// The core integral 1D image. sclass StaticAudioSample implements IAudioSample { int channels; double sampleRate; int length; // Here they are: the partial sums of the 16 bit audio samples // in an array of 6-byte integers. Channels are stored interleaved. HalfLongs data; public double sampleRate() { ret sampleRate; } public int channels() { ret channels; } public DoubleRange bounds() { ret DoubleRange(0, length); } // Get an entry of the sum table - allow for out-of-bounds // requests (those just default to silence). public double readSumTable(int channel, int i) { if (i < 0) ret 0; i = min(i, length-1); ret data.get(i*channels+channel); } // perform the integration of the raw audio data *(L samples, int *channels, double *sampleRate) { length = lengthLevel2_shortArrays(samples); data = new HalfLongs(length*channels); long[] sums = new[channels]; int iSample = 0, iChunk = 0, iInArray = 0; short[] chunk = null; for i to length: for c to channels: { if (chunk == null || iInArray >= chunk.length) { chunk = samples.get(iChunk++); iInArray = 0; } data.set(iSample++, sums[c] += chunk[iInArray++]); } } }