fix: pause support + old message skip + stopCurrentPcm

- SoundManager: added stopCurrentPcm() for pause/stop of PCM playback
- messagedelegate: call stopCurrentPcm on pause, new play, and timer complete
- messagelist: skip old double-nested JSON messages (raw starts with '{')
- sound_manager.h: void* for ma_audio_buffer to avoid header dependency
This commit is contained in:
Evgeny committed 2026-07-27 00:38:15 +03:00
1 parent 2687c3ed82
commit 830f729f52
5 files changed
+38 -16

No files matched your search

+26 -13
View File
@@ -142,34 +142,47 @@ ma_context* SoundManager::context() {
void SoundManager::playRawPcm(const int16_t* pcm, int sampleCount, int sampleRate, int channels) {
if (!m_engine || !m_initialized) {
qWarning("SoundManager::playRawPcm: not initialized (engine=%p init=%d)", (void*)m_engine, m_initialized);
DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "SoundManager::playRawPcm: not initialized");
return;
}
qDebug("SoundManager::playRawPcm: %d samples %dHz %dch vol=%.2f", sampleCount, sampleRate, channels, m_volume);
stopCurrentPcm();
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "SoundManager::playRawPcm: %d samples %dHz %dch", sampleCount, sampleRate, channels);
ma_audio_buffer_config bufCfg = ma_audio_buffer_config_init(
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);
if (r != MA_SUCCESS) {
qWarning("SoundManager: audio_buffer_init_copy failed (%d)", r);
delete buf;
DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "SoundManager: audio_buffer_init_copy failed (%d)", r);
delete buf; m_currentPcmBuffer = nullptr;
return;
}
ma_sound* sound = new ma_sound;
r = ma_sound_init_from_data_source(m_engine, (ma_data_source*)buf, 0, nullptr, sound);
m_currentPcmSound = new ma_sound;
r = ma_sound_init_from_data_source(m_engine, (ma_data_source*)buf, 0, nullptr, m_currentPcmSound);
if (r != MA_SUCCESS) {
qWarning("SoundManager: PCM sound init failed (%d)", r);
DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "SoundManager: PCM sound init failed (%d)", r);
ma_audio_buffer_uninit(buf); delete buf; m_currentPcmBuffer = nullptr;
delete m_currentPcmSound; m_currentPcmSound = nullptr;
return;
}
ma_sound_set_volume(m_currentPcmSound, m_volume);
ma_sound_start(m_currentPcmSound);
}
void SoundManager::stopCurrentPcm() {
if (m_currentPcmSound) {
ma_sound_stop(m_currentPcmSound);
delete m_currentPcmSound; m_currentPcmSound = nullptr;
}
if (m_currentPcmBuffer) {
ma_audio_buffer* buf = (ma_audio_buffer*)m_currentPcmBuffer;
ma_audio_buffer_uninit(buf);
delete buf;
delete sound;
return;
m_currentPcmBuffer = nullptr;
}
ma_sound_set_volume(sound, m_volume);
ma_sound_start(sound);
qDebug("SoundManager::playRawPcm: started");
}
static QString decodeDeviceName(const char* name) {