当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECTSOUND8::DuplicateSoundBuffer方法代码示例

本文整理汇总了C++中LPDIRECTSOUND8::DuplicateSoundBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTSOUND8::DuplicateSoundBuffer方法的具体用法?C++ LPDIRECTSOUND8::DuplicateSoundBuffer怎么用?C++ LPDIRECTSOUND8::DuplicateSoundBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPDIRECTSOUND8的用法示例。


在下文中一共展示了LPDIRECTSOUND8::DuplicateSoundBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Create

// Create
// create 'empty' sound buffer into the memory
HRESULT CSoundWave::Create(    CSoundEngine& soundEngine,
                            DWORD dwFrequency, 
                            DWORD dwBitsPerSample,
                            DWORD dwChannels,
                            DWORD dwBytes,
                            DWORD dwDuplicates,
                            DWORD dwFlags)
{
    // set original freq
    m_OriginalFrequency = dwFrequency;

    HRESULT            hres;
    WAVEFORMATEX    wfx;
    DSBUFFERDESC    desc;

    // init the wave format
    ::memset(&wfx, 0, sizeof(WAVEFORMATEX));
    wfx.wFormatTag = WAVE_FORMAT_PCM;
    wfx.nChannels = (WORD)dwChannels;
    wfx.nSamplesPerSec = dwFrequency;
    wfx.wBitsPerSample = (WORD)dwBitsPerSample;
    wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;
    wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

    // init the buffer desc
    ::memset(&desc, 0, sizeof(DSBUFFERDESC));
    desc.dwSize = sizeof(DSBUFFERDESC);
    desc.dwFlags = dwFlags;
    desc.dwBufferBytes = dwBytes;
    desc.lpwfxFormat = &wfx;

    // create sound buffer(s)...
    LPDIRECTSOUND8    pDS = soundEngine.GetDirectSound();
    m_ppDSB = new LPDIRECTSOUNDBUFFER8[dwDuplicates + 1];
    if (!m_ppDSB)
    {
        return E_OUTOFMEMORY;
    }

    // set pointers in array to NULL
    ::memset(m_ppDSB, 0, sizeof(LPDIRECTSOUNDBUFFER8) * (dwDuplicates + 1));
    m_dwBufferCount = dwDuplicates + 1;


    // create the first sound buffer
    // first sound buffer is special one,
    // it is the only one that actually contains
    // any sound data. The duplicate buffers have only
    // separate play positions, pointing into the data
    // in first buffer
    LPDIRECTSOUNDBUFFER        pDSB = NULL;
    hres = pDS->CreateSoundBuffer(&desc, &pDSB, NULL);
    if (FAILED(hres))
    {
        Release();
        return hres;
    }

    // query the latest sound buffer interface
    hres = pDSB->QueryInterface(    IID_IDirectSoundBuffer8,
                                    (void**)&m_ppDSB[0]);
    pDSB->Release();
    if (FAILED(hres))
    {
        Release();
        return hres;
    }


    // create the duplicates
    DWORD i;
    for (i=0; i<dwDuplicates; i++)
    {
        if ((dwFlags & DSBCAPS_CTRLFX))
        {
            // real time effects required, all duplicate buffers
            // must have their own wave data
            hres = pDS->CreateSoundBuffer(&desc, &pDSB, NULL);
        }
        else
        {
            // no real time effect required, use duplicate buffers
            // to save memory
            hres = pDS->DuplicateSoundBuffer(m_ppDSB[0], &pDSB);
        }

        if (SUCCEEDED(hres))
        {
            hres = pDSB->QueryInterface(    IID_IDirectSoundBuffer8,
                                            (void**)&m_ppDSB[i + 1]);
            pDSB->Release();
            if (FAILED(hres))
            {
                Release();
                return hres;
            }
        }
        else
//.........这里部分代码省略.........
开发者ID:underkround,项目名称:mazerts,代码行数:101,代码来源:SoundWave.cpp


注:本文中的LPDIRECTSOUND8::DuplicateSoundBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。