我是用waveInOpen-->waveInPrepareHeader-->waveInAddBuffer-->waveInStart
系列函数把声音录到内存缓冲区中的,录入的格式即wFormatTag为WAVE_FORMAT_PCM我想问的是:
把缓冲区中的数据存成wav文件时,要不要进行格式的转换,
或者是否VC中有函数可以把缓冲区中的内容直接往文件中写。请大侠赐教!

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc/?id=904
      

  2.   

    多谢taianmonkey
    你提供的文档我看过,我也正是按照这个过程来写的程序
    但是,我现在想把录到的声音(在内存中)保存到文件(WAV)中,
    不知道是否要进行文件格式的转换?我试过用WriteFile直接往文件中写,但得到的文件却不能
    用播放器播放,不知道为什么?
      

  3.   

    下面是wave文件头的格式,以及读的方法,写的过程是类似的。Wav files are formed by a header part and a data part. As the header part includes binary data with different characteristics, it can be appropriate to read data of different types. The header of a wav file is composed of the following fields Field bytes format contains 
    1 0...3 str4 "RIFF" in ASCII 
    2 4...7 int4 Total bytes minus 8 
    3 8...15 str4 "WAVEfmt" Eigth character is a space 
    4 16...19 int4 16 for PCM format 
    5 20...21 int2 1 for PCM format 
    6 22...23 int2 channels 
    7 24...27 int4 sampling frequency 
    8 28...31 int4 bytes per second 
    9 32...33 int2 bytes by capture 
    10 34...35 int2 bits per sample 
    11 36:39 str4 "data" 
    12 40:43 int4 bytes in data 
    With this information we can recover the data. We are going to recover the sin wave that we have just created. 
    fid = mopen('beep.wav', 'rb');        // opens file to read in binary
    ID = mget (4, 'c', fid);              // RIFF
    ID = ascii (ID);                      // conversion to ASCII format
    Size = mget (1, 'ui', fid);           // total bytes minus 8
    typ = mget (8, 'c', fid);             // WAVEfmt_
    typ = ascii (typ);                    // conversion to ASCII format
    PCM = mget (1, 'ui', fid);            // 16 
    PCM2 = mget (1, 'us', fid);           // 1
    nchannels = mget (1, 'us', fid);      // number of channels
    fsampling2 = mget (1, 'ui', fid);     // sampling frequency
    nbbytes = mget ( 1, 'ui', fid);       // bytes per second
    nbytescap  = mget ( 1, 'us', fid);    // bytes by capture
    nbytessamp = mget ( 1, 'us', fid);    // bytes per sample
    worddata = mget (4, 'c', fid );       // data in ASCII format
    worddata = ascii (worddata);          // conversion to ASCII format
    bytesindata = mget (1, 'ul', fid);    // bytes in data
      

  4.   

    非常感谢superinsect,我马上尝试您提供的方法。
      

  5.   

    搞定,再次感谢superinsect,还有其他的兄弟们!