怎样用WaveOutOpen,WaveInOpen 等函数进行音频的播放与录音。播放时采用异步播放。谁能提供相关资料与原代码。谢谢

解决方案 »

  1.   

    http://www.csdn.net/Develop/article/17\17627.shtm
      

  2.   

    怎样用,看MSDN嘛,例子也有。
      

  3.   

    但是怎样异步播放啊,或者怎样估算播放时间,因为播放完毕我要关掉设备. HPSTR lpData = NULL;//音频数据void CVCapMFCDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    waveOutClose(hWaveOut);
    waveOutReset(hWaveOut); DWORD m_WaveLong;
    WAVEHDR pWaveOutHdr;
    WAVEOUTCAPS pwoc;
    HWAVEOUT hWaveOut;
        WAVEFORMATEX WAVE;

    CFile fp;//
    fp.Open("d:\\1.wav",CFile::modeRead);
    fp.Seek(20,0);
    fp.Read(&WAVE,20);
    m_WaveLong=fp.GetLength();
    if(lpData != NULL)
    delete []lpData;
    lpData=new char[m_WaveLong+1];
    memset(lpData,0,sizeof(lpData));
    fp.Read(lpData,m_WaveLong);
    fp.Close();

    if(m_WaveLong<0)
    {
    MessageBox("Failed to read the data chunk");
    return;
    }

    //检查音频设备,返回音频输出设备的性能
    if(waveOutGetDevCaps(WAVE_MAPPER,&pwoc,sizeof(WAVEOUTCAPS))!=0)
    {
    MessageBox("Unable to allocate or lock memory");
    return;
    }
    //检查音频输出设备是否能播放指定的音频文件
    if(waveOutOpen(&hWaveOut,0,&WAVE,NULL,NULL,WAVE_ALLOWSYNC)!=0)//
    {
    MessageBox("Failed to OPEN the wave out devices");
    return;
    }
    //准备待播放的数据
    pWaveOutHdr.lpData =(HPSTR)lpData;
    pWaveOutHdr.dwBufferLength =m_WaveLong;
    pWaveOutHdr.dwFlags =0;
    if(waveOutPrepareHeader(hWaveOut,&pWaveOutHdr,sizeof(WAVEHDR))!=0)
    {
    MessageBox("Failed to prepare the wave data buffer");
    return;
    }
    //播放音频数据文件
    if(waveOutWrite(hWaveOut,&pWaveOutHdr,sizeof(WAVEHDR))!=0)
    {
    MessageBox("Failed to write the wave data buffer");
    return;

    }
    Sleep(7000);
    waveOutClose(hWaveOut);
    waveOutReset(hWaveOut); delete []lpData;
    lpData = NULL;
    }怎样把上面的改成异步播放,即去掉Sleep(7000);