MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / create

Method create

source/Windows/DXSoundBuffer.cpp:51–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49//-----------------------------------------------------------------------------
50
51std::shared_ptr<SoundBuffer> DXSoundBuffer::create(uint32_t dwBufferSize, uint32_t nSampleRate, int nChannels)
52{
53 if (!g_lpDS)
54 return NULL;
55
56 WAVEFORMATEX wavfmt;
57 DSBUFFERDESC dsbdesc;
58
59 wavfmt.wFormatTag = WAVE_FORMAT_PCM;
60 wavfmt.nChannels = nChannels;
61 wavfmt.nSamplesPerSec = nSampleRate;
62 wavfmt.wBitsPerSample = 16;
63 wavfmt.nBlockAlign = wavfmt.nChannels == 1 ? 2 : 4;
64 wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * wavfmt.nSamplesPerSec;
65
66 memset(&dsbdesc, 0, sizeof(dsbdesc));
67 dsbdesc.dwSize = sizeof(dsbdesc);
68 dsbdesc.dwBufferBytes = dwBufferSize;
69 dsbdesc.lpwfxFormat = &wavfmt;
70 dsbdesc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STICKYFOCUS;
71
72 LPDIRECTSOUNDBUFFER pBuffer;
73
74 // Are buffers released when g_lpDS OR m_pBuffer is released?
75 // . From DirectX doc:
76 // "Buffer objects are owned by the device object that created them. When the
77 // device object is released, all buffers created by that object are also released..."
78 HRESULT hr = g_lpDS->CreateSoundBuffer(&dsbdesc, &pBuffer, NULL);
79 if (FAILED(hr))
80 {
81 LogFileOutput("DXSoundBuffer: CreateSoundBuffer(), hr=0x%08X\n", (uint32_t)hr);
82 return NULL;
83 }
84
85 return std::make_shared<DXSoundBuffer>(pBuffer);
86}
87
88DXSoundBuffer::DXSoundBuffer(LPDIRECTSOUNDBUFFER pBuffer) : m_pBuffer(pBuffer)
89{

Callers

nothing calls this directly

Calls 2

LogFileOutputFunction · 0.85
CreateSoundBufferMethod · 0.80

Tested by

no test coverage detected