本文整理汇总了C++中IDirectSoundBuffer::GetCaps方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirectSoundBuffer::GetCaps方法的具体用法?C++ IDirectSoundBuffer::GetCaps怎么用?C++ IDirectSoundBuffer::GetCaps使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectSoundBuffer
的用法示例。
在下文中一共展示了IDirectSoundBuffer::GetCaps方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetSampleSize
OutputStream*
DSAudioDevice::openBuffer(
void* samples, int frame_count,
int channel_count, int sample_rate, SampleFormat sample_format)
{
ADR_GUARD("DSAudioDevice::openBuffer");
const int frame_size = channel_count * GetSampleSize(sample_format);
WAVEFORMATEX wfx;
memset(&wfx, 0, sizeof(wfx));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = channel_count;
wfx.nSamplesPerSec = sample_rate;
wfx.nAvgBytesPerSec = sample_rate * frame_size;
wfx.nBlockAlign = frame_size;
wfx.wBitsPerSample = GetSampleSize(sample_format) * 8;
wfx.cbSize = sizeof(wfx);
DSBUFFERDESC dsbd;
memset(&dsbd, 0, sizeof(dsbd));
dsbd.dwSize = sizeof(dsbd);
dsbd.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPAN |
DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY |
DSBCAPS_STATIC | DSBCAPS_CTRLPOSITIONNOTIFY;
if (m_global_focus) {
dsbd.dwFlags |= DSBCAPS_GLOBALFOCUS;
}
const int buffer_frame_count = std::max(m_min_buffer_length, frame_count);
const int buffer_size = buffer_frame_count * frame_size;
dsbd.dwBufferBytes = buffer_size;
dsbd.lpwfxFormat = &wfx;
// create the DS buffer
IDirectSoundBuffer* buffer;
HRESULT result = m_direct_sound->CreateSoundBuffer(
&dsbd, &buffer, NULL);
if (FAILED(result) || !buffer) {
return 0;
}
ADR_IF_DEBUG {
DSBCAPS caps;
caps.dwSize = sizeof(caps);
result = buffer->GetCaps(&caps);
if (FAILED(result)) {
buffer->Release();
return 0;
} else {
std::ostringstream ss;
ss << "actual buffer size: " << caps.dwBufferBytes << std::endl
<< "buffer_size: " << buffer_size;
ADR_LOG(ss.str().c_str());
}
}
void* data;
DWORD data_size;
result = buffer->Lock(0, buffer_size, &data, &data_size, 0, 0, 0);
if (FAILED(result)) {
buffer->Release();
return 0;
}
ADR_IF_DEBUG {
std::ostringstream ss;
ss << "buffer size: " << buffer_size << std::endl
<< "data size: " << data_size << std::endl
<< "frame count: " << frame_count;
ADR_LOG(ss.str().c_str());
}
const int actual_size = frame_count * frame_size;
memcpy(data, samples, actual_size);
memset((u8*)data + actual_size, 0, buffer_size - actual_size);
buffer->Unlock(data, data_size, 0, 0);
DSOutputBuffer* b = new DSOutputBuffer(
this, buffer, buffer_frame_count, frame_size);
SYNCHRONIZED(this);
m_open_buffers.push_back(b);
return b;
}