Skip to content Skip to sidebar Skip to footer

Get Precise Notes With Riffwave.js

Does anyone know if its possible to get a precise note (C, C#, D, Eb, etc) from a javascript library like riffwave.js? The demo makes me think is possible but I'm not sure how to t

Solution 1:

Sure! You'd want to create some mapping function from key to frequency (could just be a dictionary).

To synthesize a given frequency with riffwave.js, you would do something like this

functionsimHertz(hz) {
    var audio = newAudio();
    var wave = newRIFFWAVE();
    var data = [];

    wave.header.sampleRate = 44100;

    var seconds = 1;

    for (var i = 0; i < wave.header.sampleRate * seconds; i ++) {
        data[i] = Math.round(128 + 127 * Math.sin(i * 2 * Math.PI * hz / wave.header.sampleRate));
    }

    wave.Make(data);
    audio.src = wave.dataURI;
    return audio;
}

var audio = simHertz(1000);
audio.play();

Post a Comment for "Get Precise Notes With Riffwave.js"