Skip to content

Instantly share code, notes, and snippets.

@corbanbrook
Created January 11, 2010 21:24
Show Gist options
  • Save corbanbrook/274617 to your computer and use it in GitHub Desktop.
Save corbanbrook/274617 to your computer and use it in GitHub Desktop.
function p.FFT (bufferSize) {
this.bufferSize = bufferSize;
this.SinTable = new Array(bufferSize);
this.CosTable = new Array(bufferSize);
this.ReverseTable = new Array(bufferSize);
this.prototype.FFT(bufferSize) {
this.buildTrigTables();
this.buildReverseTable();
}
this.prototype.buildTrigTables = function() {
for ( var i = 0; i < this.bufferSize; i++ ) {
this.SinTable[i] = Math.sin(-Math.PI/i);
this.CosTable[i] = Math.cos(-Math.PI/i);
}
}
this.prototype.buildReverseTable = function() {
ReverseTable[0] = 0;
var limit = 1;
var bit = this.bufferSize >> 1;
while ( limit < this.bufferSize ) {
for ( var i = 0; i < limit; i++ ) {
ReverseTable[i + limit] = ReverseTable[i] + bit;
}
limit = limit << 1;
bit = bit >> 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment