summaryrefslogtreecommitdiff
path: root/arch/sandbox
diff options
context:
space:
mode:
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-12-04 20:48:57 +0100
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-12-05 17:43:23 +0100
commit304bc9f437df51b4d982fe25fd0988350c8f5fc9 (patch)
tree4cba5069695bdbb6d3cebc4646ca94b27e9ad649 /arch/sandbox
parent3f01307ced9af0c20b48217c2c58b63f824451c5 (diff)
sandbox: fix sound driver
In the callback function we have to use memcpy(). Otherwise we add the new samples on top of what is stored in the stream buffer. If we don't have enough data, zero out the rest of the stream buffer. Our sampling frequency is 48000. Let the batch size for the callback function be 960. If we play a multiple of 20 ms, this will always be a full batch. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/cpu/sdl.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index f4ca36b35c8..2c570ed8d16 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -441,7 +441,6 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
{
struct buf_info *buf;
int avail;
- bool have_data = false;
int i;
for (i = 0; i < 2; i++) {
@@ -453,10 +452,9 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
}
if (avail > len)
avail = len;
- have_data = true;
- SDL_MixAudio(stream, buf->data + buf->pos, avail,
- SDL_MIX_MAXVOLUME);
+ memcpy(stream, buf->data + buf->pos, avail);
+ stream += avail;
buf->pos += avail;
len -= avail;
@@ -466,7 +464,8 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
else
break;
}
- sdl.stopping = !have_data;
+ memset(stream, 0, len);
+ sdl.stopping = !!len;
}
int sandbox_sdl_sound_init(int rate, int channels)
@@ -484,7 +483,7 @@ int sandbox_sdl_sound_init(int rate, int channels)
wanted.freq = rate;
wanted.format = AUDIO_S16;
wanted.channels = channels;
- wanted.samples = 1024; /* Good low-latency value for callback */
+ wanted.samples = 960; /* Good low-latency value for callback */
wanted.callback = sandbox_sdl_fill_audio;
wanted.userdata = NULL;