From 9b38c38c63060b4eea2f43b7f8f41d6abf4c9340 Mon Sep 17 00:00:00 2001 From: djdiskmachine Date: Thu, 14 May 2026 16:15:18 +0200 Subject: [PATCH 1/5] Finally possibly fix audio dropouts yay questionmark --- .../Adapters/SDL2/Audio/SDLAudioDriver.cpp | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp b/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp index 5035fce8..96a9c522 100644 --- a/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp +++ b/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp @@ -10,7 +10,8 @@ void sdl_callback(void *userdata, Uint8 *stream, int len) { }; SDLAudioDriverThread::SDLAudioDriverThread(SDLAudioDriver *driver) { - semaphore_ = SysSemaphore::Create(0, 4); + // Uncap the semaphore to prevent dropped requests during long OS stalls. + semaphore_=SysSemaphore::Create(0,1024); driver_ = driver; }; @@ -62,6 +63,9 @@ bool SDLAudioDriver::InitDriver() { input.samples = settings_.bufferSize_; input.userdata = this; + SDL_SetHint(SDL_HINT_APP_NAME, "LittleGPTracker"); + SDL_SetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME, "LittleGPTracker"); + // On my machine this wasn't working. // SDL_AudioDeviceID deviceId = // SDL_OpenAudioDevice(NULL,0,&input,&returned,0); The above may return 0 @@ -83,8 +87,8 @@ bool SDLAudioDriver::InitDriver() { mainBuffer_ = (char *)((((int)unalignedMain_) + 1) & (0xFFFFFFFC)); #endif - Trace::Log("AUDIO", "%s successfully opened with %d samples", driverName, - fragSize_ / 4); + Trace::Log("AUDIO", "%s successfully opened with %d samples %d", driverName, + fragSize_ / 4, returned.freq); // Create mini blank buffer in case of underruns @@ -153,22 +157,27 @@ void SDLAudioDriver::OnChunkDone(Uint8 *stream, int len) { while (bufferSize_ - bufferPos_ < len) { // First move remaining bytes at the front - memcpy(mainBuffer_, mainBuffer_ + bufferPos_, bufferSize_ - bufferPos_); + memmove(mainBuffer_, mainBuffer_ + bufferPos_, + bufferSize_ - bufferPos_); // then get next queued buffer and copy data from it if (pool_[poolPlayPosition_].buffer_ == 0) { - SYS_MEMCPY(mainBuffer_ + bufferSize_ - bufferPos_, miniBlank_, len); - bufferSize_ = bufferSize_ - bufferPos_ + len; - + // Use fragSize_ instead of len! miniBlank_ is only allocated to + // fragSize_. Using len causes a buffer over-read if SDL requests a + // larger chunk. + SYS_MEMCPY(mainBuffer_+bufferSize_-bufferPos_, miniBlank_, fragSize_); + bufferSize_=bufferSize_-bufferPos_+fragSize_ ; bufferPos_ = 0; + // Wake the thread on underrun to prevent the pool from permanently + // drying up + if (thread_) thread_->Notify() ; } else { memcpy(mainBuffer_ + bufferSize_ - bufferPos_, pool_[poolPlayPosition_].buffer_, pool_[poolPlayPosition_].size_); - MidiService::GetInstance()->Flush(); // Adapt buffer variables bufferSize_ = @@ -181,6 +190,12 @@ void SDLAudioDriver::OnChunkDone(Uint8 *stream, int len) { poolPlayPosition_ = (poolPlayPosition_ + 1) % SOUND_BUFFER_COUNT; if (thread_) thread_->Notify(); + // Tick the engine and flush MIDI ONLY when a real logical block is + // processed! This keeps the sequencer perfectly in sync with the + // audio pool consumption, and prevents runaway MIDI generation on + // underruns which fills the ALSA buffer and freezes the thread. + onAudioBufferTick(); + MidiService::GetInstance()->Flush() ; } } // Now dump audio to the device From a631bec92bb668edf4b7ec6f41b6ad7e37ca21fe Mon Sep 17 00:00:00 2001 From: djdiskmachine <110535302+djdiskmachine@users.noreply.github.com> Date: Thu, 14 May 2026 17:19:28 +0200 Subject: [PATCH 2/5] Update SDL hints for application name --- sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp b/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp index 96a9c522..5bb07669 100644 --- a/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp +++ b/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp @@ -63,8 +63,8 @@ bool SDLAudioDriver::InitDriver() { input.samples = settings_.bufferSize_; input.userdata = this; - SDL_SetHint(SDL_HINT_APP_NAME, "LittleGPTracker"); - SDL_SetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME, "LittleGPTracker"); + SDL_SetHint("APP_NAME", "LittleGPTracker"); + SDL_SetHint("AUDIO_DEVICE_APP_NAME", "LittleGPTracker"); // On my machine this wasn't working. // SDL_AudioDeviceID deviceId = From 0444e5d0572a6b4266ce4e37f6590b8f1a537249 Mon Sep 17 00:00:00 2001 From: djdiskmachine <110535302+djdiskmachine@users.noreply.github.com> Date: Thu, 14 May 2026 17:20:42 +0200 Subject: [PATCH 3/5] Update Project.h --- sources/Application/Model/Project.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/Application/Model/Project.h b/sources/Application/Model/Project.h index a3c14a3c..00bfe0f4 100644 --- a/sources/Application/Model/Project.h +++ b/sources/Application/Model/Project.h @@ -21,7 +21,7 @@ #define PROJECT_NUMBER "1" #define PROJECT_RELEASE "6" -#define BUILD_COUNT "0-bacon14" +#define BUILD_COUNT "0-bacon15" #define MAX_TAP 3 From 14e95a9bbd6cb8efe546cab8269c16e459d06ad7 Mon Sep 17 00:00:00 2001 From: djdiskmachine <110535302+djdiskmachine@users.noreply.github.com> Date: Fri, 15 May 2026 21:48:09 +0200 Subject: [PATCH 4/5] Skip wake the thread on underrun --- sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp b/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp index 5bb07669..5ec3002e 100644 --- a/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp +++ b/sources/Adapters/SDL2/Audio/SDLAudioDriver.cpp @@ -169,9 +169,6 @@ void SDLAudioDriver::OnChunkDone(Uint8 *stream, int len) { SYS_MEMCPY(mainBuffer_+bufferSize_-bufferPos_, miniBlank_, fragSize_); bufferSize_=bufferSize_-bufferPos_+fragSize_ ; bufferPos_ = 0; - // Wake the thread on underrun to prevent the pool from permanently - // drying up - if (thread_) thread_->Notify() ; } else { memcpy(mainBuffer_ + bufferSize_ - bufferPos_, From 6499790c11f1fc00a78922e4b1de437881121313 Mon Sep 17 00:00:00 2001 From: djdiskmachine <110535302+djdiskmachine@users.noreply.github.com> Date: Fri, 15 May 2026 22:25:25 +0200 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 8c1f13d5..6e5979ef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +1.6.0-bacon15 + Finally solve "Audio randomly dies" issue + Various additions FX Command Box selector (#238) * In phrase and table views a selection box appears when editing FX commands