录音程序,可在DEC++或vc++6.0编译环境下成功运行
部分代码:
int main()
{
creat_file(); //新建文件,原文件数据被删除
RecordWave(); //录音函数
simplest_pcm16le_to_wave("NocturneNo2inEflat_44.1k_s16le.pcm", 1, 44100,
"output_nocture.wav"); //将二进制录音信息从内存中提取,并生成 wav 文件
测控 1602 DEV C ++ 环境下 控制台应用程序 善解人意 成员:王帅、赵永玻、侯雅茹
3
return 0;
}
void RecordWave()
{
int count = waveInGetNumDevs(); //检测录音设备
printf("\n 音频输入数量:%d\n", count);
WAVEINCAPS waveIncaps;
MMRESULT mmResult = waveInGetDevCaps(0, &waveIncaps;, sizeof(WAVEINCAPS));
printf("\n 音频输入设备:%s\n", waveIncaps.szPname);
if (MMSYSERR_NOERROR == mmResult)
{
//HWAVEIN phwi;
WAVEFORMATEX pwfx; //录音格式指针
WaveInitFormat
(&pwfx;, //波形声音的格式,单声道双声道使用 WAVE_FORMAT_PCM.当包含在
WAVEFORMATEXTENSIBLE 结构中时,使用 WAVE_FORMAT_EXTENSIBLE
1, //声道数量
44100, //采样率
16 // 采样位数
);
printf("\n 正在打开音频输入设备");
printf("\n 采样参数:声道 44.1kHz 16bit\n");
mmResult = waveInOpen(
&phwi;,
WAVE_MAPPER,
&pwfx;,
(DWORD)(MicCallback),
NULL,
CALLBACK_FUNCTION
);//3
if (MMSYSERR_NOERROR == mmResult)
{
//WAVEHDR pwh1;
char buffer1[10240];
pwh1.lpData = buffer1;
pwh1.dwBufferLength = 10240;
pwh1.dwUser = 1;
pwh1.dwFlags = 0;
测控 1602 DEV C ++ 环境下 控制台应用程序 善解人意 成员:王帅、赵永玻、侯雅茹
4
mmResult = waveInPrepareHeader(phwi, &pwh1;, sizeof(WAVEHDR));//为波形输
入设备准备缓冲区
printf("\n 准备缓冲区 1");
//WAVEHDR pwh2;
char buffer2[10240];
pwh2.lpData = buffer2;
pwh2.dwBufferLength = 10240;
pwh2.dwUser = 2;
pwh2.dwFlags = 0;
mmResult = waveInPrepareHeader(phwi, &pwh2;, sizeof(WAVEHDR));//为波形输
入设备准备缓冲区
printf("\n 准备缓冲区 2\n");
// WAVEHDR pwh3;
char buffer3[10240];
pwh3.lpData = buffer3;
pwh3.dwBufferLength = 10240;
pwh3.dwUser = 3;
pwh3.dwFlags = 0;
mmResult = waveInPrepareHeader(phwi, &pwh3;, sizeof(WAVEHDR));//为波形输
入设备准备缓冲区
printf("准备缓冲区 3\n");
if (MMSYSERR_NOERROR == mmResult)
{
mmResult = waveInAddBuffer(phwi, &pwh1;, sizeof(WAVEHDR));//给输入设
备增加一个缓存
printf("\n 将缓冲区 1 加入音频输入设备");
mmResult = waveInAddBuffer(phwi, &pwh2;, sizeof(WAVEHDR));//给输入设
备增加一个缓存
printf("\n 将缓冲区 2 加入音频输入设备\n");
mmResult = waveInAddBuffer(phwi, &pwh3;, sizeof(WAVEHDR));//给输入
1