Search code examples
javascriptaudiocontext

Set DelayNode to more than 1


How do I set the DelayNode.delayTime to more than 1?

I have tried this, but it results in a warning message and only creates a max delay of one second.

var delayNode = audioContext.createDelay();
delayNode.delayTime.maxValue = 3
delayNode.delayTime.minValue = 3
delayNode.delayTime.value = 3

This is the warning

Delay.delayTime.value 3 outside nominal range [0, 1]; value will be clamped.

If it is not possible to set the delay to more than one, are there any work arounds or alternative ways?


Solution

  • The DelayNode uses an internal buffer to store the delayed samples. This buffer needs to be created when creating the node. Its size determines the maximum value of the delay. The buffer can't be changed after the node is created. By default it can only hold up to 1 second of audio. But you can set it as high as you want. Setting it to 3 seconds would look like this.

    audioContext.createDelay(3);
    // or
    new DelayNode(audioContext, { maxDelayTime: 3 });