WebAudio / web-audio-api-v2

The Web Audio API v2.0, developed by the W3C Audio WG
Other
121 stars 11 forks source link

OfflineAudioContext without a rendered buffer #82

Closed chrisguttandin closed 4 years ago

chrisguttandin commented 4 years ago

Describe the feature It would be nice if the OfflineAudioContext could be configured to not allocate any memory for the rendered AudioBuffer in case it is not needed.

Is there a prototype? No.

Describe the feature in more detail Sometimes an OfflineAudioContext is only used to compute a side effect and not really for rendering a buffer.

Let's imagine you have an AudioWorkletNode which just scans the signal for its maximum value. Its usage might look like this:

const offlineAudioContext = new OfflineAudioContext({ length: 44100, sampleRate: 44100 });
const audioBufferSourceNode = new AudioBufferSourceNode(
    offlineAudioContext,
    { buffer: aBufferFromSomewhere }
);
// This could be an AudioWorkletNode which scans the signal for its maximum value. 
const maximumValueNode = new MaximumValueNode(offlineAudioContext);

audioBufferSourceNode.start(0);
audioBufferSourceNode
    .connect(maximumValueNode)
    .connect(offlineAudioContext.destination);

offlineAudioContext
    .startRendering()
    .then(() => {
        // Now that the rendering is done ask the MaximumValueNode for the maximum value.
        console.log(maximumValueNode.maximumValue);
    });

In the example above the OfflineAudioContext is only used to drive the processing of the data but the rendered buffer is not really needed. I think it would be beneficial if the buffer doesn't need to be created in any case.

guest271314 commented 4 years ago

In this case an AudioBuffer does not necessarily need to be created at all https://github.com/guest271314/audioInputToWav/blob/master/index.html#L345. The equivalent of an AudioBuffer can be an Array where Array.prototype.find() and Math.max() can be utilized to get the maximum value of a float.

padenot commented 4 years ago

Virtual F2F: