aboutsummaryrefslogtreecommitdiff
path: root/shell/audio
diff options
context:
space:
mode:
authorneonloop2021-03-10 16:53:39 +0000
committerneonloop2021-03-10 16:53:39 +0000
commitadaecd14d484d309e4d9ba2353ae843ab5213aec (patch)
tree92ba55bfc2e06aac66a6f5e1080cc2018815c7dc /shell/audio
parentba054eee2a5f9d7abfaf1fad62c0f77eef1c1da7 (diff)
downloadsnesemu-adaecd14d484d309e4d9ba2353ae843ab5213aec.tar.gz
snesemu-adaecd14d484d309e4d9ba2353ae843ab5213aec.tar.bz2
snesemu-adaecd14d484d309e4d9ba2353ae843ab5213aec.zip
Initial trimui model s support
Diffstat (limited to 'shell/audio')
-rw-r--r--shell/audio/alsa/sound_output.c4
-rw-r--r--shell/audio/oss/sound_output.c4
-rw-r--r--shell/audio/portaudio/sound_output.c4
-rw-r--r--shell/audio/sdl/sound_output.c19
-rw-r--r--shell/audio/sound_output.h2
5 files changed, 31 insertions, 2 deletions
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 <sys/ioctl.h>
#include <stdint.h>
+#include <stdbool.h>
#include <fcntl.h>
#include <unistd.h>
#include <SDL/SDL.h>
#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 <stdbool.h>
#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