Reputation: 147
This is my first time working with wav files and fft alike. Given the following code:
char* loadWAV(const char* fn, int& chan, int& samplerate, int& bps, int& size){
char buffer[4];
ifstream in(fn, ios::binary);
in.read(buffer, 4); //ChunkID "RIFF"
if(strncmp(buffer, "RIFF", 4) != 0){
cerr << "this is not a valid wave file";
return NULL;
}
in.read(buffer,4); //ChunkSize
in.read(buffer,4); //Format "WAVE"
in.read(buffer,4); // "fmt "
in.read(buffer,4); // 16
in.read(buffer,2); // 1
in.read(buffer,2); // NUMBER OF CHANNELS
chan = convertToInt(buffer,2);
in.read(buffer,4); // SAMPLE RATE
samplerate = convertToInt(buffer,4);
in.read(buffer,4); // ByteRate
in.read(buffer,2); // BlockAlign
in.read(buffer,2); // bits per sample
bps = convertToInt(buffer,2);
in.read(buffer,4); // "data"
in.read(buffer,4);
size = convertToInt(buffer,4);
char * data = new char[size];
in.read(data,size);
return data;
}
I'm assuming data pointer contains the information I need, but I don't know how to discern this information. I'm using this as a reference but I don't know what to make of the "right channel left channel" aspect and how to prepare this data to be used in an FFT. If you have any references to good documentation about this I appreciate it, My search efforts have so far resulted in NILL.
edit: also If anyone could point me to a good guide to operating with wav format files on this level i would greatly appreciate it. Thank you in advance.
Upvotes: 2
Views: 3417
Reputation: 11642
The data you have is in PCM packets.
Try these questions as a starting point:
For the FFT part of your question, you may want to consider https://dsp.stackexchange.com/.
Upvotes: 1