mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-10-15 15:32:51 +00:00
sdlaudio: port to the new audio backend api
Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Message-id: ac1722a03fb1b530c2081f46585ce7fa80ebef6c.1568927990.git.DirtY.iCE.hu@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
49ddd7e122
commit
ff71876766
|
@ -41,8 +41,6 @@
|
||||||
|
|
||||||
typedef struct SDLVoiceOut {
|
typedef struct SDLVoiceOut {
|
||||||
HWVoiceOut hw;
|
HWVoiceOut hw;
|
||||||
size_t live;
|
|
||||||
size_t decr;
|
|
||||||
} SDLVoiceOut;
|
} SDLVoiceOut;
|
||||||
|
|
||||||
static struct SDLAudioState {
|
static struct SDLAudioState {
|
||||||
|
@ -184,62 +182,59 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
||||||
SDLVoiceOut *sdl = opaque;
|
SDLVoiceOut *sdl = opaque;
|
||||||
SDLAudioState *s = &glob_sdl;
|
SDLAudioState *s = &glob_sdl;
|
||||||
HWVoiceOut *hw = &sdl->hw;
|
HWVoiceOut *hw = &sdl->hw;
|
||||||
size_t samples = len >> hw->info.shift;
|
|
||||||
size_t to_mix, decr;
|
|
||||||
|
|
||||||
if (s->exit || !sdl->live) {
|
if (s->exit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dolog ("in callback samples=%zu live=%zu\n", samples, sdl->live); */
|
/* dolog ("in callback samples=%zu live=%zu\n", samples, sdl->live); */
|
||||||
|
|
||||||
to_mix = MIN(samples, sdl->live);
|
while (hw->pending_emul && len) {
|
||||||
decr = to_mix;
|
size_t write_len;
|
||||||
while (to_mix) {
|
ssize_t start = ((ssize_t) hw->pos_emul) - hw->pending_emul;
|
||||||
size_t chunk = MIN(to_mix, hw->samples - hw->rpos);
|
if (start < 0) {
|
||||||
struct st_sample *src = hw->mix_buf + hw->rpos;
|
start += hw->size_emul;
|
||||||
|
}
|
||||||
|
assert(start >= 0 && start < hw->size_emul);
|
||||||
|
|
||||||
/* dolog ("in callback to_mix %zu, chunk %zu\n", to_mix, chunk); */
|
write_len = MIN(MIN(hw->pending_emul, len),
|
||||||
hw->clip(buf, src, chunk);
|
hw->size_emul - start);
|
||||||
hw->rpos = (hw->rpos + chunk) % hw->samples;
|
|
||||||
to_mix -= chunk;
|
memcpy(buf, hw->buf_emul + start, write_len);
|
||||||
buf += chunk << hw->info.shift;
|
hw->pending_emul -= write_len;
|
||||||
|
len -= write_len;
|
||||||
|
buf += write_len;
|
||||||
}
|
}
|
||||||
samples -= decr;
|
|
||||||
sdl->live -= decr;
|
|
||||||
sdl->decr += decr;
|
|
||||||
|
|
||||||
/* dolog ("done len=%zu\n", len); */
|
/* clear remaining buffer that we couldn't fill with data */
|
||||||
|
if (len) {
|
||||||
/* SDL2 does not clear the remaining buffer for us, so do it on our own */
|
memset(buf, 0, len);
|
||||||
if (samples) {
|
|
||||||
memset(buf, 0, samples << hw->info.shift);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t sdl_run_out(HWVoiceOut *hw, size_t live)
|
#define SDL_WRAPPER_FUNC(name, ret_type, args_decl, args, fail, unlock) \
|
||||||
{
|
static ret_type glue(sdl_, name)args_decl \
|
||||||
size_t decr;
|
{ \
|
||||||
SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
|
ret_type ret; \
|
||||||
|
\
|
||||||
SDL_LockAudio();
|
SDL_LockAudio(); \
|
||||||
|
\
|
||||||
if (sdl->decr > live) {
|
ret = glue(audio_generic_, name)args; \
|
||||||
ldebug ("sdl->decr %d live %d sdl->live %d\n",
|
\
|
||||||
sdl->decr,
|
SDL_UnlockAudio(); \
|
||||||
live,
|
return ret; \
|
||||||
sdl->live);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
decr = MIN (sdl->decr, live);
|
SDL_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size),
|
||||||
sdl->decr -= decr;
|
(hw, size), *size = 0, sdl_unlock)
|
||||||
|
SDL_WRAPPER_FUNC(put_buffer_out_nowrite, size_t,
|
||||||
|
(HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size),
|
||||||
|
/*nothing*/, sdl_unlock_and_post)
|
||||||
|
SDL_WRAPPER_FUNC(write, size_t,
|
||||||
|
(HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size),
|
||||||
|
/*nothing*/, sdl_unlock_and_post)
|
||||||
|
|
||||||
sdl->live = live;
|
#undef SDL_WRAPPER_FUNC
|
||||||
|
|
||||||
SDL_UnlockAudio();
|
|
||||||
|
|
||||||
return decr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sdl_fini_out (HWVoiceOut *hw)
|
static void sdl_fini_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
|
@ -336,7 +331,9 @@ static void sdl_audio_fini (void *opaque)
|
||||||
static struct audio_pcm_ops sdl_pcm_ops = {
|
static struct audio_pcm_ops sdl_pcm_ops = {
|
||||||
.init_out = sdl_init_out,
|
.init_out = sdl_init_out,
|
||||||
.fini_out = sdl_fini_out,
|
.fini_out = sdl_fini_out,
|
||||||
.run_out = sdl_run_out,
|
.write = sdl_write,
|
||||||
|
.get_buffer_out = sdl_get_buffer_out,
|
||||||
|
.put_buffer_out = sdl_put_buffer_out_nowrite,
|
||||||
.ctl_out = sdl_ctl_out,
|
.ctl_out = sdl_ctl_out,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue