I know the Wave file's structure. But I don't know the exact structure of PCM DATA.
#include<iostream>
#include<fstream>
using namespace std;
struct WAVE_HEADER{
char Chunk[4];
int ChunkSize;
char format[4];
char Sub_chunk1ID[4];
int Sub_chunk1Size;
short int AudioFormat;
short int NumChannels;
int SampleRate;
int ByteRate;
short int BlockAlign;
short int BitsPerSample;
char Sub_chunk2ID[4];
int Sub_chunk2Size;
};
struct WAVE_HEADER waveheader;
int main(){
FILE *sound;
sound = fopen("music.wav","rb");
short D;
fread(&waveheader,sizeof(waveheader),1,sound);
cout << "BitsPerSample : " << waveheader.BitsPerSample << endl;
while(!feof(sound)){
fread(&D,sizeof(waveheader.BitsPerSample),1,sound);
cout << int(D) << endl;
}
}
The above code is what I made so far. Also, this code can read header exactly. But I don't know if this can read PCM data part precisely. Is there any reference of PCM data structure? I couldn't find it.
"music.wav" has 16 bits per sample, 16 byte rate, stereo channal and two blockAlign. How should the above be changed?
float
s ordouble
s.) – The Paramagnetic Croissant