Warning: session_start(): open(/var/lib/php/sessions/sess_dtduc75lrs704dk8k9j6nga0j5, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sclass PianoSampler {
double sampleRate = 48000;
double currentSample;
IQuerySound sound;
IAudioSample audio;
SlidingWindow window;
persistable class Oscillator extends HasKey {
double currentPeriodStart;
// all recorded intensities
new TreeMap> intensities;
*(Frequency f) { super(f); }
Frequency frequency() { ret key(); }
double interval() { ret frequency().interval(); }
void record_impl(DoubleRange r, Channels c) {
intensities.put(r, c);
}
void measure {
double start = phaseMinus90(), end = start + interval();
AudioHaarFeature haar = new(audio, start, end);
var re = haar!;
haar = new AudioHaarFeature(audio, currentPeriodStart, currentPeriodStart + interval());
var im = haar!;
record(this, doubleRange(start, end), complexChannels(re, im));
}
void start(double currentSample) {
relocate(currentSample + startPhase());
}
void relocate(double time) {
currentPeriodStart = time;
completionsForSample.put(interval(), this);
}
double startPhase() { ret phase90(); }
double quarterPhase() { ret interval()*.25; }
double phaseMinus90() { ret currentPeriodStart - interval()*.25; }
double phase0() { ret currentPeriodStart; }
double phase90() { ret currentPeriodStart + interval()*.25; }
double phase180() { ret currentPeriodStart + interval()*.5; }
double phase270() { ret currentPeriodStart + interval()*.75; }
double phase360() { ret currentPeriodStart + interval(); }
double phase450() { ret currentPeriodStart + interval()*1.25; }
}
TreeHasKeyMap oscillators = new TreeHasKeyMap(map(f -> new Oscillator(f), pianoFrequencies88()));
new TreeMultiMap completionsForSample;
*() {}
*(IAudioSample audio, double *currentSample) { setAudio(audio); }
*(IAudioSample audio) { setAudio(audio); } // start at time 0
void setAudio(IAudioSample audio) {
this.audio = audio;
window = optCast SlidingWindow(audio);
}
void verboseOnRecordAdded() {
onRecordAdded(lambda1 print);
}
void init {
for (o : oscillators)
o.start(currentSample);
}
void stepTo(double time) {
while ping (true) {
Double t = firstKey(completionsForSample);
if (t != null && t <= time)
for (Oscillator o : completionsForSample.getAndClear(t)) {
o.measure();
o.relocate(t);
}
}
}
void record(Oscillator o, DoubleRange r, Channels c) {
if (o == null) ret;
o.record_impl(r, c);
onRecordAdded(new RecordAdded(o, r, c));
}
record RecordAdded(Oscillator oscillator, DoubleRange period, Channels intensity) {}
transient event interface OnRecordAdded as onRecordAdded shipping RecordAdded;
Frequency lowestFrequency() { ret oscillators.firstKey(); }
Frequency highestFrequency() { ret oscillators.lastKey(); }
int minWindowSize() {
ret iceil(sampleRate*lowestFrequency().interval());
}
void makeSmallestWindow(IQuerySound sound) {
this.sound = sound;
setAudio(new SlidingWindow(channels, sampleRate, sound, 0, minWindowSize());
}
}