Reading and processing WAV file data in C/C++ -


i'm doing very important school project. need extract information of wave file in c/c++ , use information obtain lpc of voice signal. but, in order that, need pre-processing signal, doing 0 crossing , energy analysis, among other things. means need sign , real value. problem don't know how obtain useful information , correct format that. have read every single field in file, i'm not sure doing right. suggestions, please?

this way read file @ moment:

readi = fread(&bps, 1, 2, audio); printf("bits per sample = %d \n", bps);

thanks in advance.

my first recommendation use kind of library out. sound solutions seem overkill, simple library (like 1 recommended in comment of question, libsndfile) should trick.

if want know how read wav files can write own (since school might turn nose @ having use library other regular person), quick google search give info need plus people have wrote many tutorials on reading .wav format.

if still don't it, here's of own code read header , other chunks of wav/riff data file until data chunk. it's based exclusively off wav format specification. extracting actual sound data not hard: can either read raw , use raw or conversion format you'd have more comfort internally (32-bit pcm uncompressed data or something).

when looking @ below code, replace reader.read...( ... ) equivalent fread calls integer values , byte sizes of indicated type. wavchunks enum little endian values of ids inside of wav file chunk, , format variable 1 of types of wav format types can contained in wav file format:

enum class wavchunks {     riffheader = 0x46464952,     wavriff = 0x54651475,     format = 0x020746d66,     labeledtext = 0x478747c6,     instrumentation = 0x478747c6,     sample = 0x6c706d73,     fact = 0x47361666,     data = 0x61746164,     junk = 0x4b4e554a, };  enum class wavformat {     pulsecodemodulation = 0x01,     ieeefloatingpoint = 0x03,     alaw = 0x06,     mulaw = 0x07,     imaadpcm = 0x11,     yamahaitug723adpcm = 0x16,     gsm610 = 0x31,     itug721adpcm = 0x40,     mpeg = 0x50,     extensible = 0xfffe };  int32 chunkid = 0; bool datachunk = false; while ( !datachunk ) {     chunkid = reader.readint32( );     switch ( (wavchunks)chunkid ) {     case wavchunks::format:         formatsize = reader.readint32( );         format = (wavformat)reader.readint16( );         channels = (channels)reader.readint16( );         channelcount = (int)channels;         samplerate = reader.readint32( );         bitspersecond = reader.readint32( );         formatblockalign = reader.readint16( );         bitdepth = reader.readint16( );         if ( formatsize == 18 ) {             int32 extradata = reader.readint16( );             reader.seek( extradata, seekorigin::current );         }         break;     case wavchunks::riffheader:         headerid = chunkid;         memsize = reader.readint32( );         riffstyle = reader.readint32( );         break;     case wavchunks::data:         datachunk = true;         datasize = reader.readint32( );         break;     default:         int32 skipsize = reader.readint32( );         reader.seek( skipsize, seekorigin::current );         break;     } } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -