From ceab0b04ebb52da8fd632ed051cf833d35bbdd22 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 1 Jul 2010 03:57:37 +0000 Subject: PacBox: Premultiply sound prom data on load rather than during emulation. Use 16-bit data for 'raw' output instead of int. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27208 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/pacbox/arcade.c | 4 ++-- apps/plugins/pacbox/arcade.h | 2 +- apps/plugins/pacbox/pacbox.c | 17 +++++++++-------- apps/plugins/pacbox/wsg3.c | 20 ++++++++++++-------- apps/plugins/pacbox/wsg3.h | 4 ++-- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/apps/plugins/pacbox/arcade.c b/apps/plugins/pacbox/arcade.c index ecf6d10af8..bd108c75aa 100644 --- a/apps/plugins/pacbox/arcade.c +++ b/apps/plugins/pacbox/arcade.c @@ -640,10 +640,10 @@ void renderSprites( unsigned char * buffer ) } } -void playSound( int * buf, int len ) +void playSound( int16_t * buf, int len ) { /* Clear the buffer */ - memset( buf, 0, sizeof (int)*len); + memset( buf, 0, sizeof (int16_t)*len); /* Exit now if sound is disabled */ if( (output_devices_ & SoundEnabled) == 0 ) diff --git a/apps/plugins/pacbox/arcade.h b/apps/plugins/pacbox/arcade.h index 33dd6d6981..33f79e1d53 100644 --- a/apps/plugins/pacbox/arcade.h +++ b/apps/plugins/pacbox/arcade.h @@ -123,7 +123,7 @@ void init_PacmanMachine(int dip); int run(void); void reset_PacmanMachine(void); void decodeROMs(void); -void playSound( int * buf, int len ); +void playSound( int16_t * buf, int len ); /** diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c index 8d44857666..7f40822e0d 100644 --- a/apps/plugins/pacbox/pacbox.c +++ b/apps/plugins/pacbox/pacbox.c @@ -281,9 +281,9 @@ static bool pacbox_menu(void) static uint32_t sound_buf[NBSAMPLES]; #if CONFIG_CPU == MCF5249 /* Not enough to put this in IRAM */ -static int raw_buf[NBSAMPLES]; +static int16_t raw_buf[NBSAMPLES]; #else -static int raw_buf[NBSAMPLES] IBSS_ATTR; +static int16_t raw_buf[NBSAMPLES] IBSS_ATTR; #endif /* @@ -291,22 +291,23 @@ static int raw_buf[NBSAMPLES] IBSS_ATTR; */ static void get_more(unsigned char **start, size_t *size) { - int i; - int32_t *out; - int *raw; + int32_t *out, *outend; + int16_t *raw; /* Emulate the audio for the current register settings */ playSound(raw_buf, NBSAMPLES); out = sound_buf; + outend = out + NBSAMPLES; raw = raw_buf; - /* Normalize the audio and convert to stereo */ - for (i = 0; i < NBSAMPLES; i++) + /* Convert to stereo */ + do { - uint32_t sample = (uint16_t)*raw++ << 6; + uint32_t sample = (uint16_t)*raw++; *out++ = sample | (sample << 16); } + while (out < outend); *start = (unsigned char *)sound_buf; *size = NBSAMPLES*sizeof(sound_buf[0]); diff --git a/apps/plugins/pacbox/wsg3.c b/apps/plugins/pacbox/wsg3.c index 3c861312b9..c848b68b6b 100644 --- a/apps/plugins/pacbox/wsg3.c +++ b/apps/plugins/pacbox/wsg3.c @@ -65,7 +65,7 @@ static bool wsg3_get_voice(struct wsg3_voice *voice, int index) return true; } -void wsg3_play_sound(int * buf, int len) +void wsg3_play_sound(int16_t * buf, int len) { struct wsg3_voice voice; @@ -73,7 +73,7 @@ void wsg3_play_sound(int * buf, int len) { unsigned offset = wsg3.wave_offset[0]; unsigned step = voice.frequency * wsg3.resample_step; - int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; + int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; int volume = voice.volume; int i; @@ -81,7 +81,7 @@ void wsg3_play_sound(int * buf, int len) { /* Should be shifted right by 15, but we must also get rid * of the 10 bits used for decimals */ - buf[i] += wave_data[(offset >> 25) & 0x1F] * volume; + buf[i] = (int)wave_data[(offset >> 25) & 0x1F] * volume; offset += step; } @@ -92,7 +92,7 @@ void wsg3_play_sound(int * buf, int len) { unsigned offset = wsg3.wave_offset[1]; unsigned step = voice.frequency * wsg3.resample_step; - int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; + int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; int volume = voice.volume; int i; @@ -100,7 +100,7 @@ void wsg3_play_sound(int * buf, int len) { /* Should be shifted right by 15, but we must also get rid * of the 10 bits used for decimals */ - buf[i] += wave_data[(offset >> 25) & 0x1F] * volume; + buf[i] += (int)wave_data[(offset >> 25) & 0x1F] * volume; offset += step; } @@ -111,7 +111,7 @@ void wsg3_play_sound(int * buf, int len) { unsigned offset = wsg3.wave_offset[2]; unsigned step = voice.frequency * wsg3.resample_step; - int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; + int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; int volume = voice.volume; int i; @@ -119,7 +119,7 @@ void wsg3_play_sound(int * buf, int len) { /* Should be shifted right by 15, but we must also get rid * of the 10 bits used for decimals */ - buf[i] += wave_data[(offset >> 25) & 0x1F] * volume; + buf[i] += (int)wave_data[(offset >> 25) & 0x1F] * volume; offset += step; } @@ -137,8 +137,12 @@ void wsg3_set_sound_prom( const unsigned char * prom ) { int i; + memcpy(wsg3.sound_prom, prom, 32*8); + + /* Copy wave data and convert 4-bit unsigned -> 16-bit signed, + * prenormalized */ for (i = 0; i < 32*8; i++) - wsg3.sound_wave_data[i] = (int)*prom++ - 8; + wsg3.sound_wave_data[i] = ((int16_t)wsg3.sound_prom[i] - 8) * 85; } void wsg3_init(unsigned master_clock) diff --git a/apps/plugins/pacbox/wsg3.h b/apps/plugins/pacbox/wsg3.h index 1ee385cdf9..fa71cd44f0 100644 --- a/apps/plugins/pacbox/wsg3.h +++ b/apps/plugins/pacbox/wsg3.h @@ -56,7 +56,7 @@ struct wsg3 unsigned char sound_prom[32*8]; unsigned resample_step; unsigned wave_offset[3]; - int sound_wave_data[32*8]; + int16_t sound_wave_data[32*8]; /* sign-extended 4-bit, prenormalized */ }; extern struct wsg3 wsg3; @@ -106,7 +106,7 @@ static inline unsigned char wsg3_get_register(unsigned reg) @param buf pointer to sound buffer that receives the audio samples @param len length of the sound buffer */ -void wsg3_play_sound(int * buf, int len); +void wsg3_play_sound(int16_t * buf, int len); /** Returns the sampling rate currently in use for rendering sound. -- cgit v1.2.3