rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
MIT License
1.89k stars 160 forks source link

playing a sound with a different panning type removes the loaded panning type #102

Closed frastlin closed 4 years ago

frastlin commented 5 years ago

Hello, Extending #40 when you switch panning for one play method, the original object changes to match the panning in play.

const sound = new Wad({source:'./myfile.ogg', panning:[1,1,1]})
sound.play({panning:0})
sound.setPanning([1,5,1])

throws the following error:

TypeError: this.panning.node.setPosition is not a function
srcWadJs/</Wad</Wad.prototype.setPanning
node_modules/web-audio-daw/build/wad.js:3534
  3531 | this.panning.location = panning;
  3532 | 
  3533 | if (isArray(panning) && this.panning.type === '3d' && this.panning.node) {
> 3534 |   this.panning.node.setPosition(panning[0], panning[1], panning[2]);
       | ^
  3535 | } else if (typeof panning === 'number' && this.panning.type === 'stereo' && this.panning.node) {
  3536 |   this.panning.node.pan.setTargetAtTime(panning, context.currentTime, timeConstant);
  3537 | }
rserota commented 5 years ago

Your code totally should work, but to be honest, I'm not sure when I'll get around to fixing it. I don't think this use case is super common, and there are other low-hanging fruit that I plan to work on first.
Thanks for raising this issue, though.

frastlin commented 5 years ago

It's an easy workaround, I just instigate a new Wad object with the loaded sound file. import sound_file from './sound_file.ogg' const sound1 = new Wad({source:sound_file, panning:[1,1,1]}) const sound2 = new Wad({source:sound_file, panning:0})

I would give this a 1/5 on the priority scale.