# Problem using PositionalAudio context

**URL:** <https://discourse.threejs.org/t/problem-using-positionalaudio-context/66772>\
**Category:** Questions\
**Tags:** web-audio, audio\
**Created:** [June 12, 2024, 2:51pm UTC](https://discourse.threejs.org/t/problem-using-positionalaudio-context/66772 "2024-06-12T14:51:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![diemildefreude](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@diemildefreude](https://discourse.threejs.org/u/diemildefreude)\
**Post date:** [June 12, 2024, 2:51pm UTC](https://discourse.threejs.org/t/problem-using-positionalaudio-context/66772/1 "2024-06-12T14:51:52Z")

</div>

Hvcc is a compiler that converts [pure data](https://puredata.info) patches into C with wrappers for various platforms, including a js webassembly wrapper:

[Wasted-Audio/hvcc: The heavy hvcc compiler for Pure Data patches. Updated to python3 and additional generators (github.com)](https://github.com/Wasted-Audio/hvcc)

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](https://stackoverflow.com/questions/58705054/using-tone-js-with-three-js-how-to-get-positional-audio) 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.

```javascript
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](https://github.com/Wasted-Audio/hvcc/blob/551586c020240a123a175dd5d7db202d014665ab/hvcc/generators/c2js/template/hv_wrapper.js).
