Generates a tone as raw PCM WAV data, so you can do operations on it
This thing generates raw PCM data, specified by a frequency and length in seconds.
var tone = require"tonegenerator";var A440 = tone440 20; // get PCM data for a 440hz A, 20 seconds.
The data is returned as a normal array, so you can do operations on it. Before writing to a file, you need to convert it to a buffer:
var tone = require"tonegenerator";var header = require"waveheader"; //var fs = require"fs";// An A-major chordvar tone1 = tone440 2;var tone2 = tone554.37 2;var tone3 = tone659.26 2;// "playing" one tone at the time// note that at this time, our sound is just an array// of gain values. By appending the raw PCM data for one after another,// we can play them in a sequencevar res = concattone1;res = resconcattone2;res = resconcattone3;// By adding values of the tones for each sample,// we play them simultaneously, as a chordforvar i = 0; i < tone1length; i++respushtone1i + tone2i + tone3i;// write to file (note conversion to buffer!)var writer = "A-major.wav";writerwriteheader 44100 * 8 ; // 44100 Hz * 8 secondswriterwriteres;writerend;