// For audio recognition, we need a double-precision (16 bit) // integral image. We simply turn the sample data into pixels and // have ourselves a verybig*1 image. srecord noeq AudioRecognizer { interface IAudioSample { double length(); double sampleSum(int channel, double start, double end); public default double getPixel(int channel, double start, double end) { ret doubleRatio(sampleSum, end-start); } } // the 16 bit per channel integral image class AudioSample implements IAudioSample { int channels; long[] data; public double length() { ret data.length; } public double sampleSum(int channel, double start, double end) { int a = ifloor(start), b = ifloor(end); ret getEntry(getEntry(b)-getEntry(a-1); } // get an entry of the sum table long getEntry(int i) { if (i < 0) ret 0; ret data[min(i, data.length-1)]; } *(short[] samples) { int n = l(samples); data = new long[n]; long sum = 0; for i to n: data[i] = (sum += samples[i]); } } }