audio - [C++]I want to get PCM data from wav file -


i know wave file's structure. don't know 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 made far. also, code can read header exactly. don't know if can read pcm data part precisely. there reference of pcm data structure? couldn't find it.

"music.wav" has 16 bits per sample, 16 byte rate, stereo channal , 2 blockalign. how should above changed?

as indicated in this description of wav specifications, pcm data stored using little-endian byte order , two's-complement resolutions greater 8 bit per sample. in other words, on intel processor, 16-bit samples typically corresponds signed short. additionally, stereo channels data interleaved (left/right samples).

with in mind, assuming "music.wav" indeed contain 16-bit pcm samples , reading data on little-endian platform using compiler sizeof(short)==2, code posted should read samples correctly.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -