/ proof-of-concept / midiboot
Sign in
proof-of-concept / midiboot
Test recorder pitch locking and octave folding
Checks the emergent pitch lands near G5 and C6 for in-range notes and that a below-chart note folds up an octave instead of collapsing to C5.
Jeremy Magland <jmagland@flatironinstitute.org> committed commit 0b546c490f62 parent 1f214a6 Browse files
1 changed file+13−4
scripts/test-sim.tsmodified+13−4View file
@@ -128,11 +128,20 @@ const SR = 44100;
128128 // at a low sample rate to keep the jet integration quick.
129129 const b = loadBundle('recorder', 'recorder');
130130 const t0 = performance.now();
131- const [g5] = renderNoteBatch(b, [{ pitch: 79, velocity: 0.6, durationSec: 0.3 }], {
132- sampleRate: 22050, quality: 'preview', settings: {},
133- });
134- console.log(`recorder: one note in ${((performance.now() - t0) / 1000).toFixed(1)} s`);
131+ const RSR = 22050;
132+ const [g5, c6, g4] = renderNoteBatch(b, [
133+ { pitch: 79, velocity: 0.6, durationSec: 0.5 },
134+ { pitch: 84, velocity: 0.6, durationSec: 0.5 },
135+ { pitch: 67, velocity: 0.6, durationSec: 0.5 }, // below the chart: folds up an octave
136+ ], { sampleRate: RSR, quality: 'preview', settings: {} });
137+ console.log(`recorder: three notes in ${((performance.now() - t0) / 1000).toFixed(1)} s`);
135138 check(finite(g5) && peak(g5) > 0, 'recorder note sounds (prepare state reached the driver)');
139+ const f79 = peakFreq(g5, RSR, 400, 2000);
140+ const f84 = peakFreq(c6, RSR, 400, 2000);
141+ const f67 = peakFreq(g4, RSR, 400, 2000);
142+ check(Math.abs(f79 - 784) < 25, `pitch 79 locks near G5 (${f79} Hz)`);
143+ check(Math.abs(f84 - 1047) < 35, `pitch 84 locks near C6 (${f84} Hz)`);
144+ check(Math.abs(f67 - f79) < 10, `below-range pitch folds up an octave (${f67} Hz vs ${f79} Hz)`);
136145 }
137146
138147 console.log(failures === 0 ? 'exported-instrument test passed' : `${failures} failure(s)`);
↑↓ move↵openescclose