Audio: setDetune() not possible for buffer source?

Hey,

I’m trying to play some audio using an AudioListener and the AudioLoader class to load an mp3-file. As shown in the example here: THREE.Audio
I fill the sound object’s buffer with the buffer received from the loader. But when I try to detune the sound then before playing it, I get an error saying, that is can’t read ‘detune’ of ‘undefined’.

This probably is because it checks for this.source.detune === undefined inside Audio.js, since this.source is not set inside setBuffer() but it is set in all the other set-Functions. Is this intended? Is it not possible to use detune when using audioBuffers?

Thanks so much in advance!

The check if ( this.source.detune === undefined ) return; exists because detune is only partially supported in browsers. E.g. Safari does now know this audio parameter.

Thanks for your fast answer Michael!
I do understand why the comparison of detune is needed, but since this.source is never assigned a value when an Audio object’s buffer is set, my code breaks down every time at that comparison, since this.source is undefined.

But I just realized that the problem probably is, that I haven’t called play() before using setDetune(), because the source object is set to the AudioBuffer inside play() right?

Is it necessary to do it that way? Otherwise I would recommend setting the source to an AudioBuffer inside the setBuffer already to be sure, that the attribute is defined when setDetune is called. I can try it out and create a Merge Request if nothing speaks against it.

That is correct. You need the AudioBufferSourceNode first before detune can be configured.

1 Like