在多线程中是不是多个线程共同占用了同一设备?如果需要同时播放多个声音的话,还是用DirectSound 吧

解决方案 »

  1.   

    参考以下我的
    BOOL CWaveOutDevice::Play(CWave *pWave)
    {
        if (!Open(pWave->GetFormat())) {
            return FALSE;
        }    CWaveBlockList* pBL = pWave->GetBlockList();
        if (!pBL) return FALSE;    POSITION pos = pBL->GetHeadPosition();
        if (!pos) return FALSE;
        
        // Inc the ref count if we're using it
        if (pWave->m_bAutoDestruct) pWave->AddRef();
        while (pos) {
            CWaveBlock* pBlock = pBL->GetNext(pos);
            ASSERT(pBlock);        // Allocate a header
            WAVEHDR* phdr = (WAVEHDR*)malloc(sizeof(WAVEHDR));
            ASSERT(phdr);
            // fill out the wave header
            memset(phdr, 0, sizeof(WAVEHDR));
            phdr->lpData = (char *)(BYTE*) pBlock->GetSamples();
            phdr->dwBufferLength = pBlock->GetSize();
            phdr->dwUser = (DWORD)(void*)pWave;    // so we can find the object         // Prepare the header
            MMRESULT mmr = waveOutPrepareHeader(m_hOutDev,
                                                phdr,
                                                sizeof(WAVEHDR));
            if (mmr) {
                MMERR(mmr);
                return FALSE;
            }
            // Mark the wave as busy playing
            pWave->IncPlayCount();        // Start it playing
            mmr = waveOutWrite(m_hOutDev,
                               phdr,
                               sizeof(WAVEHDR));
            if (mmr) {
                MMERR(mmr);
                return FALSE;
            }        // Add one to the block count
            m_iBlockCount++;
        } // next block    return TRUE;
    }
      

  2.   

    [email protected]
    我以上做过,应该不难,只是解码过程是用别人的lib罢了
      

  3.   

    多谢各位关注!freelybird(阿愚),我将代码发给你,帮我看看。
    还有哪位愿意帮忙?请留下email。
      

  4.   

    我的问题还没有解决!我查了MSDN,waveOutProc这个CALLBACK函数里面不能再调用其他wav函数,否则会引起死锁,很不幸,我的程序正是这样的,要改的话,实在是麻烦,该怎办?硬着头皮改呢?还是另找一个?谁能帮我?Applications should not call any system-defined functions from inside a callback function, except for EnterCriticalSection, LeaveCriticalSection, midiOutLongMsg, midiOutShortMsg, OutputDebugString, PostMessage, PostThreadMessage, SetEvent, timeGetSystemTime, timeGetTime, timeKillEvent, and timeSetEvent. Calling other wave functions will cause deadlock.
      

  5.   

    在回调函数中创建一个线程,调用其他的Wave函数。