Buffer Samplerate Javascript

AudioMatt's icon

I know this is silly but I nearly missed that I could deduce the sample rate of a buffer like this so for anyone searching in the future:

function bang(){
    var buf = new Buffer("myBuffer");
    post("samplerate: ",buf.samplerate(),"\n");
}
Buffer.prototype.samplerate = function(){
    return 1000*this.framecount()/this.length()
}

DominicThibault's icon

Thanks! This has proved useful!