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
This commit is contained in:
Michael Sevakis 2010-07-01 03:57:37 +00:00
parent f09370058f
commit ceab0b04eb
5 changed files with 26 additions and 21 deletions

View file

@ -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 */ /* Clear the buffer */
memset( buf, 0, sizeof (int)*len); memset( buf, 0, sizeof (int16_t)*len);
/* Exit now if sound is disabled */ /* Exit now if sound is disabled */
if( (output_devices_ & SoundEnabled) == 0 ) if( (output_devices_ & SoundEnabled) == 0 )

View file

@ -123,7 +123,7 @@ void init_PacmanMachine(int dip);
int run(void); int run(void);
void reset_PacmanMachine(void); void reset_PacmanMachine(void);
void decodeROMs(void); void decodeROMs(void);
void playSound( int * buf, int len ); void playSound( int16_t * buf, int len );
/** /**

View file

@ -281,9 +281,9 @@ static bool pacbox_menu(void)
static uint32_t sound_buf[NBSAMPLES]; static uint32_t sound_buf[NBSAMPLES];
#if CONFIG_CPU == MCF5249 #if CONFIG_CPU == MCF5249
/* Not enough to put this in IRAM */ /* Not enough to put this in IRAM */
static int raw_buf[NBSAMPLES]; static int16_t raw_buf[NBSAMPLES];
#else #else
static int raw_buf[NBSAMPLES] IBSS_ATTR; static int16_t raw_buf[NBSAMPLES] IBSS_ATTR;
#endif #endif
/* /*
@ -291,22 +291,23 @@ static int raw_buf[NBSAMPLES] IBSS_ATTR;
*/ */
static void get_more(unsigned char **start, size_t *size) static void get_more(unsigned char **start, size_t *size)
{ {
int i; int32_t *out, *outend;
int32_t *out; int16_t *raw;
int *raw;
/* Emulate the audio for the current register settings */ /* Emulate the audio for the current register settings */
playSound(raw_buf, NBSAMPLES); playSound(raw_buf, NBSAMPLES);
out = sound_buf; out = sound_buf;
outend = out + NBSAMPLES;
raw = raw_buf; raw = raw_buf;
/* Normalize the audio and convert to stereo */ /* Convert to stereo */
for (i = 0; i < NBSAMPLES; i++) do
{ {
uint32_t sample = (uint16_t)*raw++ << 6; uint32_t sample = (uint16_t)*raw++;
*out++ = sample | (sample << 16); *out++ = sample | (sample << 16);
} }
while (out < outend);
*start = (unsigned char *)sound_buf; *start = (unsigned char *)sound_buf;
*size = NBSAMPLES*sizeof(sound_buf[0]); *size = NBSAMPLES*sizeof(sound_buf[0]);

View file

@ -65,7 +65,7 @@ static bool wsg3_get_voice(struct wsg3_voice *voice, int index)
return true; return true;
} }
void wsg3_play_sound(int * buf, int len) void wsg3_play_sound(int16_t * buf, int len)
{ {
struct wsg3_voice voice; struct wsg3_voice voice;
@ -73,7 +73,7 @@ void wsg3_play_sound(int * buf, int len)
{ {
unsigned offset = wsg3.wave_offset[0]; unsigned offset = wsg3.wave_offset[0];
unsigned step = voice.frequency * wsg3.resample_step; 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 volume = voice.volume;
int i; 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 /* Should be shifted right by 15, but we must also get rid
* of the 10 bits used for decimals */ * 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; offset += step;
} }
@ -92,7 +92,7 @@ void wsg3_play_sound(int * buf, int len)
{ {
unsigned offset = wsg3.wave_offset[1]; unsigned offset = wsg3.wave_offset[1];
unsigned step = voice.frequency * wsg3.resample_step; 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 volume = voice.volume;
int i; 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 /* Should be shifted right by 15, but we must also get rid
* of the 10 bits used for decimals */ * 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; offset += step;
} }
@ -111,7 +111,7 @@ void wsg3_play_sound(int * buf, int len)
{ {
unsigned offset = wsg3.wave_offset[2]; unsigned offset = wsg3.wave_offset[2];
unsigned step = voice.frequency * wsg3.resample_step; 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 volume = voice.volume;
int i; 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 /* Should be shifted right by 15, but we must also get rid
* of the 10 bits used for decimals */ * 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; offset += step;
} }
@ -137,8 +137,12 @@ void wsg3_set_sound_prom( const unsigned char * prom )
{ {
int i; 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++) 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) void wsg3_init(unsigned master_clock)

View file

@ -56,7 +56,7 @@ struct wsg3
unsigned char sound_prom[32*8]; unsigned char sound_prom[32*8];
unsigned resample_step; unsigned resample_step;
unsigned wave_offset[3]; 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; 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 buf pointer to sound buffer that receives the audio samples
@param len length of the sound buffer @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. Returns the sampling rate currently in use for rendering sound.