Hvcc is a compiler that converts pure data patches into C with wrappers for various platforms, including a js webassembly wrapper:
I’m not sure anyone has ever combined hvcc objects with three.js before. I’m trying to use three.js’ PositionalAudio to spatialize hvcc audio. Based on this StackOverflow post about using Tone.js with three.js, I’ve tried something that kind of works.
In the below code, the context taken from the PositionalAudio object is used to initialize the hvcc object. Then, I use hvcc’s webAudioWorklet (if available, otherwise audiolib) as a node source for the PositionalAudio. This is similar to what was done in that StackOverflow solution (but that was for Tone.js).
The result is that I that I hear the timbre of spatialization (HRTF filtering), but not the actual panning.
audioListener = new Three.AudioListener();
camera.add(audioListener);
const sound = new Three.PositionalAudio(audioListener);
initHeavy(sound.context).then(() =>
{
if(hvLoader.webAudioWorklet)
{
sound.setNodeSource(hvLoader.webAudioWorklet);
}
else
{
sound.setNodeSource(hvLoader.audiolib);
}
mesh.add(sound);
});
function initHeavy(context)
{
return new Promise (function(resolve, reject)
{
wavTest_Module().then((loadedModule) =>
{
hvModule = loadedModule;
hvLoader = new hvModule.AudioLibLoader();
if(!hvLoader.webAudioContext)
{
hvLoader.init(
{
blockSize: 2048,
printHook: onPrint,
sendHook: null,
webAudioContext: context //context from PositionalAudio set here
}).then(() =>
{
setHvParam("lopFreq", 10000);
setHvParam("vol", 1.0);
loadHvAudio("./test.mp3");
sendHvEvent("playTab");
resolve();
}).catch((error) => reject(error));
}
});
});
}
I realize this is probably a difficult problem due to hvcc’s nicheness, but I appreciate any clues at all. The js wrapper source code is here.