Search code examples
javascriptsafariweb-audio-apimicrosoft-edge

alternative to audioContext.copyToChannel() in Safari and Edge


Both Safari and Edge do not support the audioContext.copyToChannel() function to populate an audioBuffer with custom content. Is there any other way to do it?

In my case, I want to create an impulse response, populate a buffer with that response and convolve some sound with that buffer. For Chrome and Firefox this works:

buffer = audioCtx.createBuffer(numOfChannels, 1, sampleRate);
buffer.copyToChannel(impulseResponse, 0);
buffer.copyToChannel(impulseResponse, 1);
convolverNode.buffer = buffer;

Solution

  • You can just use getChannelData(channel) on the AudioBuffer, you then get a regular Float32Array than you can modify at will. Maybe you want to look at the set method ?

    copyToChannel is there to optimize buffer copies , as noted in the spec (see the little green box below.