Skip to content

Instantly share code, notes, and snippets.

@gadtfly
Last active May 10, 2019 15:10
Show Gist options
  • Select an option

  • Save gadtfly/03226453a414f48c2a7adb70fd4e154d to your computer and use it in GitHub Desktop.

Select an option

Save gadtfly/03226453a414f48c2a7adb70fd4e154d to your computer and use it in GitHub Desktop.
Play the FF Prelude on your PC speaker, because why not. Requires `beep`.
const child_process = require('child_process');
const beep = (f, l) => { child_process.spawnSync('beep', ['-f', f, '-l', l]); };
const freq_for_note = (root_freq, step, steps_per_octave = 12) => root_freq * 2**(step/steps_per_octave);
const invert_chord = (steps, steps_per_octave = 12) => steps.slice(1).concat(steps[0] + steps_per_octave);
const rangeTo = n => [... Array(n).keys()];
const note_length = 60*1000/320;
const root_freq = freq_for_note(440, 3 - 3*12); // C2 derived from A440
const octaves_per_run = 4;
const maj_run = [0,2,4,7];
const min_run = [0,2,3,7];
const maj7_run = [0,4,7,11];
const runs = [[0, maj_run], [-3, min_run], [0, maj_run] , [-3, min_run], [-7, maj_run], [-5, maj_run], [-4, maj7_run], [-2, maj7_run]];
runs.forEach(([root_step, run_steps]) => {
const beep_note = (octave, step) => { beep(freq_for_note(root_freq, root_step + step + octave*12), note_length); };
rangeTo(octaves_per_run).forEach((octave) => {
run_steps.forEach((step) => {
beep_note(octave, step);
});
});
rangeTo(octaves_per_run).reverse().forEach((octave) => {
invert_chord(run_steps).reverse().forEach((step) => {
beep_note(octave, step);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment