I am trying to read the .wav file and give the raw data as input to the FFT algorithm.I have used the following code to read the .wav file.
char ChunkID[4], Format[4], Subchunk1ID[4],Subchunk2ID[4];
int ChunkSize,Subchunk1Size, SampleRate, ByteRate,Subchunk2Size;
short AudioFormat, NumChannels, BlockAlign, BitsPerSample;
short *Data;
// Read the wave file
FILE *fhandle=fopen([var UTF8String],"rb");
fread(ChunkID,1,4,fhandle);
fread(&ChunkSize,4,1,fhandle);
fread(Format,1,4,fhandle);
fread(Subchunk1ID,1,4,fhandle);
fread(&Subchunk1Size,4,1,fhandle);
fread(&AudioFormat,2,1,fhandle);
fread(&NumChannels,2,1,fhandle);
fread(&SampleRate,4,1,fhandle);
fread(&ByteRate,4,1,fhandle);
fread(&BlockAlign,2,1,fhandle);
fread(&BitsPerSample,2,1,fhandle);
fread(&Subchunk2ID,1,4,fhandle);
fread(&Subchunk2Size,4,1,fhandle);
Data=(short*) malloc (sizeof(short)*Subchunk2Size/(BitsPerSample/8)); // Create an element for every sample
fread(Data,BitsPerSample/8,Subchunk2Size/(BitsPerSample/8),fhandle); // Reading raw audio data
fclose(fhandle);
The ChunkID gives the value 'caff' and the format gives 'desc' i cant see any value in data.Do i miss anything.i want to give the raw sound data as input to FFt.Please help me out.Give me right approach for this.