From 662caa6f9197a4e0d5e64743f1078ddc82836852 Mon Sep 17 00:00:00 2001 From: balrog Date: Sat, 26 Apr 2008 12:00:18 +0000 Subject: [PATCH] Let WM8750 users write to audio buffer directly. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4254 c046a42c-6fe2-441c-8c8c-71466251a162 --- hw/i2c.h | 2 ++ hw/musicpal.c | 18 ++++++++++-------- hw/wm8750.c | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/hw/i2c.h b/hw/i2c.h index fae46b77bb..b390d1b944 100644 --- a/hw/i2c.h +++ b/hw/i2c.h @@ -67,6 +67,8 @@ void wm8750_data_req_set(i2c_slave *i2c, void (*data_req)(void *, int, int), void *opaque); void wm8750_dac_dat(void *opaque, uint32_t sample); uint32_t wm8750_adc_dat(void *opaque); +void *wm8750_dac_buffer(void *opaque, int samples); +void wm8750_dac_commit(void *opaque); /* ssd0303.c */ void ssd0303_init(DisplayState *ds, i2c_bus *bus, int address); diff --git a/hw/musicpal.c b/hw/musicpal.c index fb20b31550..e41c9e4171 100644 --- a/hw/musicpal.c +++ b/hw/musicpal.c @@ -254,7 +254,7 @@ typedef struct musicpal_audio_state { static void audio_callback(void *opaque, int free_out, int free_in) { musicpal_audio_state *s = opaque; - int16_t channel[2]; + int16_t *codec_buffer; int pos, block_size; if (!(s->playback_mode & MP_AUDIO_PLAYBACK_EN)) @@ -270,17 +270,19 @@ static void audio_callback(void *opaque, int free_out, int free_in) return; if (s->playback_mode & MP_AUDIO_16BIT_SAMPLE) - for (pos = 0; pos < block_size; pos += 4) - wm8750_dac_dat(s->wm, - *(uint32_t *)(s->target_buffer + s->play_pos + pos)); - else + memcpy(wm8750_dac_buffer(s->wm, block_size >> 2), + (uint32_t *)(s->target_buffer + s->play_pos), + block_size); + else { + codec_buffer = wm8750_dac_buffer(s->wm, block_size >> 1); for (pos = 0; pos < block_size; pos += 2) { - channel[0] = cpu_to_le16(2 * + *codec_buffer++ = cpu_to_le16(2 * *(int8_t *)(s->target_buffer + s->play_pos + pos)); - channel[1] = cpu_to_le16(2 * + *codec_buffer++ = cpu_to_le16(2 * *(int8_t *)(s->target_buffer + s->play_pos + pos + 1)); - wm8750_dac_dat(s->wm, channel[0] | (channel[1] << 16)); } + } + wm8750_dac_commit(s->wm); s->last_free = free_out - block_size; diff --git a/hw/wm8750.c b/hw/wm8750.c index c26961a2fc..4722e6c4a0 100644 --- a/hw/wm8750.c +++ b/hw/wm8750.c @@ -627,6 +627,24 @@ void wm8750_dac_dat(void *opaque, uint32_t sample) wm8750_out_flush(s); } +void *wm8750_dac_buffer(void *opaque, int samples) +{ + struct wm8750_s *s = (struct wm8750_s *) opaque; + /* XXX: Should check if there are samples free samples available */ + void *ret = s->data_out + s->idx_out; + + s->idx_out += samples << 2; + s->req_out -= samples << 2; + return ret; +} + +void wm8750_dac_commit(void *opaque) +{ + struct wm8750_s *s = (struct wm8750_s *) opaque; + + return wm8750_out_flush(s); +} + uint32_t wm8750_adc_dat(void *opaque) { struct wm8750_s *s = (struct wm8750_s *) opaque; -- 2.11.0