aboutsummaryrefslogtreecommitdiff
path: root/arch/sandbox/cpu/sdl.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-12-10 10:37:45 -0700
committerSimon Glass <sjg@chromium.org>2018-12-13 16:36:30 -0700
commit282e29eb4728c43fa42fcba816188cd5523bb6ee (patch)
treef0bb16730fd4c1e39cc0ca70ab9c6f4cd7301268 /arch/sandbox/cpu/sdl.c
parent93a98a6ff3b1ce86a1a1fef6a6e2dc9d5515c9ba (diff)
downloadu-boot-282e29eb4728c43fa42fcba816188cd5523bb6ee.zip
u-boot-282e29eb4728c43fa42fcba816188cd5523bb6ee.tar.gz
u-boot-282e29eb4728c43fa42fcba816188cd5523bb6ee.tar.bz2
dm: sandbox: sound: Convert to use driver model
Update sandbox's device tree and config to use driver model for sound. Use the double buffer for sound output so that we don't need to wait for the sound to complete before returning. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch/sandbox/cpu/sdl.c')
-rw-r--r--arch/sandbox/cpu/sdl.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index 4dacdbf..32fa1ff 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -4,6 +4,7 @@
*/
#include <errno.h>
+#include <unistd.h>
#include <linux/input.h>
#include <SDL/SDL.h>
#include <sound.h>
@@ -40,6 +41,7 @@ static struct sdl_info {
bool inited;
int cur_buf;
struct buf_info buf[2];
+ bool running;
} sdl;
static void sandbox_sdl_poll_events(void)
@@ -331,6 +333,7 @@ int sandbox_sdl_sound_init(void)
sdl.audio_active = true;
sdl.sample_rate = wanted.freq;
sdl.cur_buf = 0;
+ sdl.running = 0;
return 0;
@@ -340,27 +343,39 @@ err:
return -1;
}
-int sandbox_sdl_sound_start(uint frequency)
+int sandbox_sdl_sound_play(const void *data, uint size)
{
- struct buf_info *buf = &sdl.buf[0];
+ struct buf_info *buf;
if (!sdl.audio_active)
- return -1;
- sdl.frequency = frequency;
- sound_create_square_wave(sdl.sample_rate, (unsigned short *)buf->data,
- buf->alloced, frequency);
+ return 0;
+
+ buf = &sdl.buf[0];
+ if (buf->size)
+ buf = &sdl.buf[1];
+ while (buf->size)
+ usleep(1000);
+
+ if (size > buf->alloced)
+ return -E2BIG;
+
+ memcpy(buf->data, data, size);
+ buf->size = size;
buf->pos = 0;
- buf->size = buf->alloced;
- SDL_PauseAudio(0);
+ if (!sdl.running) {
+ SDL_PauseAudio(0);
+ sdl.running = 1;
+ }
return 0;
}
int sandbox_sdl_sound_stop(void)
{
- if (!sdl.audio_active)
- return -1;
- SDL_PauseAudio(1);
+ if (sdl.running) {
+ SDL_PauseAudio(1);
+ sdl.running = 0;
+ }
return 0;
}