◀︎ ▲︎ ▶︎︎

Pitch Changer

	var pshift = function(val, indata) {
    this.fft.forward(indata);
    for (var i = 0; i < stream_length; i++) {
        a_real[i] = 0;
        a_imag[i] = 0;
    }
    for (var i = 0; i < stream_length; i++) {
        var index = parseInt(i * val);
        var eq = 1.0;
        if (i > stream_length / 2) {
            eq = 0;
        }
        if ((index >= 0) && (index < stream_length)) {
            a_real[index] += fft.real[i] * eq;
            a_imag[index] += fft.imag[i] * eq;
        } 
    }
    return this.fft.inverse(this.a_real, this.a_imag);
}
	pitchShifter.onaudioprocess = function(event) {
    var sin
    	= event.inputBuffer.getChannelData(0);
    var sout
    	= event.outputBuffer.getChannelData(0);
    var data = pshift(rate, sin);
    for (var i = 0; i < sin.length; i++) {
        sout[i] = data[i];
    }
};