Search code examples
javascriptsafariweb-audio-api

The index is not in the allowed range


I'm currently having an issue with the Tone.Analyzer in Safari 10.1. When initializing the Tone.Analyzer with a size > Math.pow(2, 10) (1024) I get the following error: IndexSizeError (DOM Exception 1): The index is not in the allowed range.

I've also submitted this to the ToneJS repository, but I feel like this is more like an bug in Safari, right?

Code

import Tone from 'tone';

const sampleSize = Math.pow(2, 13); // Math.pow(2, 10); works...

this.fft = new Tone.Analyser('fft', sampleSize);
this.panVol = new Tone.PanVol().fan(this.fft).toMaster();

Link to WebpackBin example

However, I can't find any information on the interwebz, which browser accepts which size, while the Tone.js documentation mentions, that the Value must be a power of two in the range 32 to 32768. (Same as in the Web Audio API documentation)

Does Safaris Audio APIs getByteFrequencyData haven't implemented higher sizes? Would love to implement a highly accurate equalizer, but the sample size needs to be > 4000 for the lower frequencies.


Solution

  • An early version of the WebAudio spec said that 2048 was the largest FFT size for the AnalyserNode. Later versions made the limit at least 32k, Safari still implements the old limit.