mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
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:
parent
f09370058f
commit
ceab0b04eb
5 changed files with 26 additions and 21 deletions
|
@ -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 )
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue