sclass AudioAdder implements IAudioSample { new Cl sources; gettable double sampleRate; settable int channels; settable DoubleRange bounds; // for now same value in all channels new TreeMap additions; *() {} *(IAudioSample source) { addUnlessNull(sources, source); } void addSource(IAudioSample source) { addUnlessNull(sources, source); this.source = source; } void addPlateau(double start, double end, double intensity) { if (start >= end) ret; _changeSumAt(start, intensity); _changeSumAt(end, -intensity); } // We will probably add plateaus rather randomly throughout an area, // so could optimize this doing something akin to LogNArray. void _changeSumAt(double time, double intensity) { double value = unnull(floorValue(additions, time)) + intensity; // create, overwrite or delete mapPutOrRemove(additions, time, nullIfZero(value)); Double next = additions.higherKey(time); while (next != null) { subtractions.put(next, additions.get(next) + intensity); next = subtractions.higherKey(next); } } public double readSumTable(int channel, double t) { double diff = unnull(floorValue(additions, t)); ret diff; for (source : sources) diff += source.readSumTable(channel, t); ret diff; } }