Adopt decoded voice buffers without large copies on the Qt thread
This commit is contained in:
1 parent
add016894b
commit
c77cb9bb0a
2 files changed
+10
-3
No files matched your search
@@ -46,6 +46,7 @@ void SoundManager::clearCurrentPcm() {
|
||||
ma_audio_buffer_uninit(buf); delete buf; m_currentPcmBuffer = nullptr;
|
||||
}
|
||||
m_currentPcmSampleRate = 0;
|
||||
m_currentPcmOwner.reset();
|
||||
}
|
||||
|
||||
void SoundManager::shutdown() {
|
||||
@@ -200,13 +201,15 @@ ma_context* SoundManager::context() {
|
||||
return m_context;
|
||||
}
|
||||
|
||||
void SoundManager::playRawPcm(const int16_t* pcm, int sampleCount, int sampleRate, int channels) {
|
||||
void SoundManager::playRawPcm(const int16_t* pcm, int sampleCount, int sampleRate, int channels,
|
||||
std::shared_ptr<std::vector<int16_t>> owner) {
|
||||
if (!m_engine || !m_initialized) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_GENERAL, "SoundManager::playRawPcm: not initialized (engine=%p init=%d)",
|
||||
(void*)m_engine, (int)m_initialized);
|
||||
return;
|
||||
}
|
||||
clearCurrentPcm();
|
||||
m_currentPcmOwner = std::move(owner);
|
||||
m_currentPcmSampleRate = sampleRate;
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "SoundManager::playRawPcm: %d samples %dHz %dch volume=%.2f",
|
||||
sampleCount, sampleRate, channels, m_volume);
|
||||
@@ -215,7 +218,7 @@ void SoundManager::playRawPcm(const int16_t* pcm, int sampleCount, int sampleRat
|
||||
ma_format_s16, (ma_uint32)channels, (ma_uint64)sampleCount, pcm, NULL);
|
||||
ma_audio_buffer* buf = new ma_audio_buffer;
|
||||
m_currentPcmBuffer = buf;
|
||||
ma_result r = ma_audio_buffer_init_copy(&bufCfg, buf);
|
||||
ma_result r = m_currentPcmOwner ? ma_audio_buffer_init(&bufCfg, buf) : ma_audio_buffer_init_copy(&bufCfg, buf);
|
||||
if (r != MA_SUCCESS) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_GENERAL, "SoundManager: audio_buffer_init_copy failed (%d)", r);
|
||||
delete buf; m_currentPcmBuffer = nullptr;
|
||||
|
||||
Reference in new issue
Block a user