如何把缓冲区中的声音文件存成wav文件?
我是用waveInOpen-->waveInPrepareHeader-->waveInAddBuffer-->waveInStart
系列函数把声音录到内存缓冲区中的,录入的格式即wFormatTag为WAVE_FORMAT_PCM
我想问的是:
把缓冲区中的数据存成wav文件时,要不要进行格式的转换,
或者是否VC中有函数可以把缓冲区中的内容直接往文件中写。
请大侠赐教!
问题点数:20、回复次数:7Top
1 楼lvjiayan111()回复于 2004-09-06 09:42:39 得分 0
帮帮忙啊,我是真的很想知道啊,兄弟们!Top
2 楼taianmonkey()回复于 2004-09-06 11:18:11 得分 5
http://www.vckbase.com/document/viewdoc/?id=904Top
3 楼lvjiayan111()回复于 2004-09-06 21:17:17 得分 0
多谢taianmonkey
你提供的文档我看过,我也正是按照这个过程来写的程序
但是,我现在想把录到的声音(在内存中)保存到文件(WAV)中,
不知道是否要进行文件格式的转换?
我试过用WriteFile直接往文件中写,但得到的文件却不能
用播放器播放,不知道为什么?Top
4 楼wuyapu()回复于 2004-09-07 08:23:20 得分 3
没有写文件头,看看文件规范,先写文件头,然后再将缓冲区中内容写入Top
5 楼superinsect(superinsect)回复于 2004-09-07 08:40:40 得分 12
下面是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
Top
6 楼lvjiayan111()回复于 2004-09-07 14:44:26 得分 0
非常感谢superinsect,我马上尝试您提供的方法。Top
7 楼lvjiayan111()回复于 2004-09-07 21:40:34 得分 0
搞定,再次感谢superinsect,还有其他的兄弟们!Top




