if(m_WaveLong<0) { MessageBox("Failed to read the data chunk"); return; }
m_PlayPro.SetRangeMax(m_WaveLong,TRUE);
//检查音频设备,返回音频输出设备的性能 if(waveOutGetDevCaps(WAVE_MAPPER,&pwoc2,sizeof(WAVEOUTCAPS))!=0) { MessageBox("Unable to allocate or lock memory"); return; } //检查音频输出设备是否能播放指定的音频文件 if(waveOutOpen(&hWaveOut2,0,&lpFormat,NULL,NULL,CALLBACK_NULL)!=0) { MessageBox("Failed to OPEN the wave out devices"); return; } //准备待播放的数据 pWaveOutHdr2.lpData =(HPSTR)lpData; pWaveOutHdr2.dwBufferLength =m_WaveLong; pWaveOutHdr2.dwFlags =0; if(waveOutPrepareHeader(hWaveOut2,&pWaveOutHdr2,sizeof(WAVEHDR))!=0) { MessageBox("Failed to prepare the wave data buffer"); return; } //播放音频数据文件 if(waveOutWrite(hWaveOut2,&pWaveOutHdr2,sizeof(WAVEHDR))!=0) { MessageBox("Failed to write the wave data buffer"); return; }
如果说你在dos下写程序的话,当然是要带上你自己的驱动才可以让你的声卡发声的
如果是在windows下,你用windows本身的函数问题是很简单的
一定要自己编吗?
如果自己编写驱动该怎么编呢?
HWAVEIN m_hWaveIn; //输入音频的句柄
WAVEHDR* m_pWaveHdr[8];
char m_buffer[8][buflength];
WAVEINCAPS ipwoc;
WAVEOUTCAPS opwoc;
WAVEHDR pWaveOutHdr;
HWAVEOUT hWaveOut; WAVEHDR pWaveOutHdr2;
WAVEOUTCAPS pwoc2;
HWAVEOUT hWaveOut2;
void CIPPhoneDlg::PlayRecord(CString m_path, DWORD pos)
{
m_path="c:\\test.wav";
pos=0; waveOutUnprepareHeader(hWaveOut,&pWaveOutHdr, sizeof(WAVEHDR) );
waveOutReset(hWaveOut);
waveOutClose(hWaveOut);
waveOutUnprepareHeader(hWaveOut2,&pWaveOutHdr2, sizeof(WAVEHDR) );
waveOutReset(hWaveOut2);
waveOutClose(hWaveOut2);
HPSTR lpData;//音频数据
WAVEFORMATEX lpFormat;
CFile fpp;
fpp.Open(m_path,CFile::modeRead);
fpp.Seek(20,0);
fpp.Read(&lpFormat,20);
fpp.Close();
m_BytesPerSecond=lpFormat.nSamplesPerSec;
fpp.Open(m_path,CFile::modeRead);
m_WaveLong=fpp.GetLength();
fpp.Seek(pos,0);
lpData=new char[m_WaveLong*3/2];
fpp.Read(lpData,m_WaveLong-pos);
fpp.Close();
if(m_WaveLong<0)
{
MessageBox("Failed to read the data chunk");
return;
}
m_PlayPro.SetRangeMax(m_WaveLong,TRUE);
//检查音频设备,返回音频输出设备的性能
if(waveOutGetDevCaps(WAVE_MAPPER,&pwoc2,sizeof(WAVEOUTCAPS))!=0)
{
MessageBox("Unable to allocate or lock memory");
return;
}
//检查音频输出设备是否能播放指定的音频文件
if(waveOutOpen(&hWaveOut2,0,&lpFormat,NULL,NULL,CALLBACK_NULL)!=0)
{
MessageBox("Failed to OPEN the wave out devices");
return;
}
//准备待播放的数据
pWaveOutHdr2.lpData =(HPSTR)lpData;
pWaveOutHdr2.dwBufferLength =m_WaveLong;
pWaveOutHdr2.dwFlags =0;
if(waveOutPrepareHeader(hWaveOut2,&pWaveOutHdr2,sizeof(WAVEHDR))!=0)
{
MessageBox("Failed to prepare the wave data buffer");
return;
}
//播放音频数据文件
if(waveOutWrite(hWaveOut2,&pWaveOutHdr2,sizeof(WAVEHDR))!=0)
{
MessageBox("Failed to write the wave data buffer");
return;
}
m_PlayPro.EnableWindow(TRUE);
m_dwPlayed=pos;
m_PlayPro.SetPos(pos);
SetTimer(3,1000,0);
}