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 = ;var A440 = ; // 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 = ;var header = ; //var fs = ;// An A-major chordvar tone1 = ;var tone2 = ;var tone3 = ;// "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 = ;res = res;res = res;// By adding values of the tones for each sample,// we play them simultaneously, as a chordforvar i = 0; i < tone1length; i++res;// write to file (note conversion to buffer!)var writer = "A-major.wav";writer; // 44100 Hz * 8 secondswriter;writer;