From adaecd14d484d309e4d9ba2353ae843ab5213aec Mon Sep 17 00:00:00 2001 From: neonloop Date: Wed, 10 Mar 2021 16:53:39 +0000 Subject: Initial trimui model s support --- shell/audio/alsa/sound_output.c | 4 ++++ shell/audio/oss/sound_output.c | 4 ++++ shell/audio/portaudio/sound_output.c | 4 ++++ shell/audio/sdl/sound_output.c | 19 +++++++++++++++++-- shell/audio/sound_output.h | 2 ++ 5 files changed, 31 insertions(+), 2 deletions(-) (limited to 'shell/audio') diff --git a/shell/audio/alsa/sound_output.c b/shell/audio/alsa/sound_output.c index 5173bb6..4da70a7 100644 --- a/shell/audio/alsa/sound_output.c +++ b/shell/audio/alsa/sound_output.c @@ -132,6 +132,10 @@ void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size) } } +bool Audio_Underrun_Likely() { + return false; +} + void Audio_Close() { if (handle) diff --git a/shell/audio/oss/sound_output.c b/shell/audio/oss/sound_output.c index 2d32b1f..39a7ba3 100644 --- a/shell/audio/oss/sound_output.c +++ b/shell/audio/oss/sound_output.c @@ -49,6 +49,10 @@ void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size) write(oss_audio_fd, buffer, buffer_size * 4 ); } +bool Audio_Underrun_Likely() { + return false; +} + void Audio_Close() { if (oss_audio_fd >= 0) diff --git a/shell/audio/portaudio/sound_output.c b/shell/audio/portaudio/sound_output.c index 226db5c..0c03c93 100644 --- a/shell/audio/portaudio/sound_output.c +++ b/shell/audio/portaudio/sound_output.c @@ -35,6 +35,10 @@ void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size) Pa_WriteStream( apu_stream, buffer, buffer_size); } +bool Audio_Underrun_Likely() { + return false; +} + void Audio_Close() { //Pa_Close(); diff --git a/shell/audio/sdl/sound_output.c b/shell/audio/sdl/sound_output.c index f14bb1d..ae1ab83 100644 --- a/shell/audio/sdl/sound_output.c +++ b/shell/audio/sdl/sound_output.c @@ -1,11 +1,14 @@ #include #include +#include #include #include #include #include "sound_output.h" +#define UNDERRUN_THRESHOLD 0.5 + static int32_t BUFFSIZE; static uint8_t *buffer; static uint32_t buf_read_pos = 0; @@ -36,14 +39,20 @@ static int32_t sdl_read_buffer(uint8_t* data, int32_t len) static void sdl_write_buffer(uint8_t* data, int32_t len) { + SDL_LockAudio(); for(uint32_t i = 0; i < len; i += 4) { - if(buffered_bytes == BUFFSIZE) return; // just drop samples + while (buffered_bytes == BUFFSIZE) { + SDL_UnlockAudio(); + usleep(1000); + SDL_LockAudio(); + } *(int32_t*)((char*)(buffer + buf_write_pos)) = *(int32_t*)((char*)(data + i)); //memcpy(buffer + buf_write_pos, data + i, 4); buf_write_pos = (buf_write_pos + 4) % BUFFSIZE; buffered_bytes += 4; } + SDL_UnlockAudio(); } void sdl_callback(void *unused, uint8_t *stream, int32_t len) @@ -90,9 +99,15 @@ uint32_t Audio_Init() void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size) { - SDL_LockAudio(); sdl_write_buffer(buffer, buffer_size * 4); +} + +bool Audio_Underrun_Likely() { + bool underrun_likely = false; + SDL_LockAudio(); + underrun_likely = buffered_bytes < BUFFSIZE * UNDERRUN_THRESHOLD; SDL_UnlockAudio(); + return underrun_likely; } void Audio_Close() diff --git a/shell/audio/sound_output.h b/shell/audio/sound_output.h index ba8a318..b770fbe 100644 --- a/shell/audio/sound_output.h +++ b/shell/audio/sound_output.h @@ -1,10 +1,12 @@ #ifndef SOUND_OUTPUT_H #define SOUND_OUTPUT_H +#include #include "shared.h" extern uint32_t Audio_Init(); extern void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size); +extern bool Audio_Underrun_Likely(); extern void Audio_Close(); #endif -- cgit v1.2.3