标题:[求助]如何给录音后的数据加上WAV文件头以保存为音频文件
取消只看楼主
colormoon
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-7-17
 问题点数:0 回复次数:1 
[求助]如何给录音后的数据加上WAV文件头以保存为音频文件

我在做一个录音程序设计,但是在录音后的数据保存上有点搞不清楚,下面是我在数据上加的WAV文件头,但是保存后,文件大小总是1KB,问题出在哪里呢?
//定义WAVE文件结构
DWORD WaveHeaderSize=38;
DWORD WaveFormatSize=sizeof(WAVEFORMATEX);
DWORD AudioDataSize=sizeof(m_dwDataLength);

WAVEFORMATEX WaveFormatEx;
WaveFormatEx.wFormatTag =WAVE_FORMAT_PCM;
WaveFormatEx.nSamplesPerSec =44100;
WaveFormatEx.wBitsPerSample =16;
WaveFormatEx.nChannels =2;
WaveFormatEx.cbSize =0;
WaveFormatEx.nBlockAlign =WaveFormatEx.nChannels *WaveFormatEx.wBitsPerSample /8;
WaveFormatEx.nAvgBytesPerSec =WaveFormatEx.nSamplesPerSec *WaveFormatEx.nBlockAlign ;

//创建新文件
CFile m_file;
CFileException fileException;
CString m_csFileName=SaveDlg.GetPathName ();
m_file.Open (m_csFileName,CFile::modeCreate | CFile::modeReadWrite,&fileException);

//写入WAV文件头,按顺序写入
m_file.SeekToBegin ();
m_file.Write ("RIFF",4);
unsigned int Sec=(AudioDataSize+WaveHeaderSize);
m_file.Write (&Sec,sizeof(Sec));
m_file.Write ("WAVE",4);

m_file.Write ("fmt ",4);
m_file.Write (&WaveFormatSize,sizeof(WaveFormatSize));
m_file.Write (&WaveFormatEx.wFormatTag ,sizeof(WaveFormatEx.wFormatTag ));
m_file.Write (&WaveFormatEx.nChannels ,sizeof(WaveFormatEx.nChannels ));
m_file.Write (&WaveFormatEx.nSamplesPerSec ,sizeof(WaveFormatEx.nSamplesPerSec ));
m_file.Write (&WaveFormatEx.nAvgBytesPerSec ,sizeof(WaveFormatEx.nAvgBytesPerSec ));
m_file.Write (&WaveFormatEx.nBlockAlign ,sizeof(WaveFormatEx.nBlockAlign ));
m_file.Write (&WaveFormatEx.wBitsPerSample ,sizeof(WaveFormatEx.wBitsPerSample ));
m_file.Write (&WaveFormatEx.cbSize ,sizeof(WaveFormatEx.cbSize ));

m_file.Write ("data",4);
m_file.Write (&AudioDataSize,sizeof(AudioDataSize));

//写入音频数据,把音频数据放到WAV文件头后写入

m_file.Write (m_pSaveBuffer,sizeof(AudioDataSize));

搜索更多相关主题的帖子: WAV 音频 文件 数据 录音 
2006-07-17 16:54
colormoon
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-7-17
得分:0 
谢谢版主哦,正是这些问题,我都没注意到,万分感谢!
2006-07-18 16:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-78817-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.192251 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved