summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2010-07-01 03:57:37 +0000
committerMichael Sevakis <jethead71@rockbox.org>2010-07-01 03:57:37 +0000
commitceab0b04ebb52da8fd632ed051cf833d35bbdd22 (patch)
tree810b17e7b1931ce0ac13a8105196bf958e8a94e8
parentf09370058ff170bcf99481dd8115871ba20ee816 (diff)
downloadrockbox-ceab0b04ebb52da8fd632ed051cf833d35bbdd22.tar.gz
rockbox-ceab0b04ebb52da8fd632ed051cf833d35bbdd22.zip
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
-rw-r--r--apps/plugins/pacbox/arcade.c4
-rw-r--r--apps/plugins/pacbox/arcade.h2
-rw-r--r--apps/plugins/pacbox/pacbox.c17
-rw-r--r--apps/plugins/pacbox/wsg3.c20
-rw-r--r--apps/plugins/pacbox/wsg3.h4
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 )
640 } 640 }
641} 641}
642 642
643void playSound( int * buf, int len ) 643void playSound( int16_t * buf, int len )
644{ 644{
645 /* Clear the buffer */ 645 /* Clear the buffer */
646 memset( buf, 0, sizeof (int)*len); 646 memset( buf, 0, sizeof (int16_t)*len);
647 647
648 /* Exit now if sound is disabled */ 648 /* Exit now if sound is disabled */
649 if( (output_devices_ & SoundEnabled) == 0 ) 649 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);
123int run(void); 123int run(void);
124void reset_PacmanMachine(void); 124void reset_PacmanMachine(void);
125void decodeROMs(void); 125void decodeROMs(void);
126void playSound( int * buf, int len ); 126void playSound( int16_t * buf, int len );
127 127
128 128
129/** 129/**
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)
281static uint32_t sound_buf[NBSAMPLES]; 281static uint32_t sound_buf[NBSAMPLES];
282#if CONFIG_CPU == MCF5249 282#if CONFIG_CPU == MCF5249
283/* Not enough to put this in IRAM */ 283/* Not enough to put this in IRAM */
284static int raw_buf[NBSAMPLES]; 284static int16_t raw_buf[NBSAMPLES];
285#else 285#else
286static int raw_buf[NBSAMPLES] IBSS_ATTR; 286static int16_t raw_buf[NBSAMPLES] IBSS_ATTR;
287#endif 287#endif
288 288
289/* 289/*
@@ -291,22 +291,23 @@ static int raw_buf[NBSAMPLES] IBSS_ATTR;
291 */ 291 */
292static void get_more(unsigned char **start, size_t *size) 292static void get_more(unsigned char **start, size_t *size)
293{ 293{
294 int i; 294 int32_t *out, *outend;
295 int32_t *out; 295 int16_t *raw;
296 int *raw;
297 296
298 /* Emulate the audio for the current register settings */ 297 /* Emulate the audio for the current register settings */
299 playSound(raw_buf, NBSAMPLES); 298 playSound(raw_buf, NBSAMPLES);
300 299
301 out = sound_buf; 300 out = sound_buf;
301 outend = out + NBSAMPLES;
302 raw = raw_buf; 302 raw = raw_buf;
303 303
304 /* Normalize the audio and convert to stereo */ 304 /* Convert to stereo */
305 for (i = 0; i < NBSAMPLES; i++) 305 do
306 { 306 {
307 uint32_t sample = (uint16_t)*raw++ << 6; 307 uint32_t sample = (uint16_t)*raw++;
308 *out++ = sample | (sample << 16); 308 *out++ = sample | (sample << 16);
309 } 309 }
310 while (out < outend);
310 311
311 *start = (unsigned char *)sound_buf; 312 *start = (unsigned char *)sound_buf;
312 *size = NBSAMPLES*sizeof(sound_buf[0]); 313 *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)
65 return true; 65 return true;
66} 66}
67 67
68void wsg3_play_sound(int * buf, int len) 68void wsg3_play_sound(int16_t * buf, int len)
69{ 69{
70 struct wsg3_voice voice; 70 struct wsg3_voice voice;
71 71
@@ -73,7 +73,7 @@ void wsg3_play_sound(int * buf, int len)
73 { 73 {
74 unsigned offset = wsg3.wave_offset[0]; 74 unsigned offset = wsg3.wave_offset[0];
75 unsigned step = voice.frequency * wsg3.resample_step; 75 unsigned step = voice.frequency * wsg3.resample_step;
76 int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; 76 int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
77 int volume = voice.volume; 77 int volume = voice.volume;
78 int i; 78 int i;
79 79
@@ -81,7 +81,7 @@ void wsg3_play_sound(int * buf, int len)
81 { 81 {
82 /* Should be shifted right by 15, but we must also get rid 82 /* Should be shifted right by 15, but we must also get rid
83 * of the 10 bits used for decimals */ 83 * of the 10 bits used for decimals */
84 buf[i] += wave_data[(offset >> 25) & 0x1F] * volume; 84 buf[i] = (int)wave_data[(offset >> 25) & 0x1F] * volume;
85 offset += step; 85 offset += step;
86 } 86 }
87 87
@@ -92,7 +92,7 @@ void wsg3_play_sound(int * buf, int len)
92 { 92 {
93 unsigned offset = wsg3.wave_offset[1]; 93 unsigned offset = wsg3.wave_offset[1];
94 unsigned step = voice.frequency * wsg3.resample_step; 94 unsigned step = voice.frequency * wsg3.resample_step;
95 int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; 95 int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
96 int volume = voice.volume; 96 int volume = voice.volume;
97 int i; 97 int i;
98 98
@@ -100,7 +100,7 @@ void wsg3_play_sound(int * buf, int len)
100 { 100 {
101 /* Should be shifted right by 15, but we must also get rid 101 /* Should be shifted right by 15, but we must also get rid
102 * of the 10 bits used for decimals */ 102 * of the 10 bits used for decimals */
103 buf[i] += wave_data[(offset >> 25) & 0x1F] * volume; 103 buf[i] += (int)wave_data[(offset >> 25) & 0x1F] * volume;
104 offset += step; 104 offset += step;
105 } 105 }
106 106
@@ -111,7 +111,7 @@ void wsg3_play_sound(int * buf, int len)
111 { 111 {
112 unsigned offset = wsg3.wave_offset[2]; 112 unsigned offset = wsg3.wave_offset[2];
113 unsigned step = voice.frequency * wsg3.resample_step; 113 unsigned step = voice.frequency * wsg3.resample_step;
114 int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform; 114 int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
115 int volume = voice.volume; 115 int volume = voice.volume;
116 int i; 116 int i;
117 117
@@ -119,7 +119,7 @@ void wsg3_play_sound(int * buf, int len)
119 { 119 {
120 /* Should be shifted right by 15, but we must also get rid 120 /* Should be shifted right by 15, but we must also get rid
121 * of the 10 bits used for decimals */ 121 * of the 10 bits used for decimals */
122 buf[i] += wave_data[(offset >> 25) & 0x1F] * volume; 122 buf[i] += (int)wave_data[(offset >> 25) & 0x1F] * volume;
123 offset += step; 123 offset += step;
124 } 124 }
125 125
@@ -137,8 +137,12 @@ void wsg3_set_sound_prom( const unsigned char * prom )
137{ 137{
138 int i; 138 int i;
139 139
140 memcpy(wsg3.sound_prom, prom, 32*8);
141
142 /* Copy wave data and convert 4-bit unsigned -> 16-bit signed,
143 * prenormalized */
140 for (i = 0; i < 32*8; i++) 144 for (i = 0; i < 32*8; i++)
141 wsg3.sound_wave_data[i] = (int)*prom++ - 8; 145 wsg3.sound_wave_data[i] = ((int16_t)wsg3.sound_prom[i] - 8) * 85;
142} 146}
143 147
144void wsg3_init(unsigned master_clock) 148void 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
56 unsigned char sound_prom[32*8]; 56 unsigned char sound_prom[32*8];
57 unsigned resample_step; 57 unsigned resample_step;
58 unsigned wave_offset[3]; 58 unsigned wave_offset[3];
59 int sound_wave_data[32*8]; 59 int16_t sound_wave_data[32*8]; /* sign-extended 4-bit, prenormalized */
60}; 60};
61 61
62extern struct wsg3 wsg3; 62extern struct wsg3 wsg3;
@@ -106,7 +106,7 @@ static inline unsigned char wsg3_get_register(unsigned reg)
106 @param buf pointer to sound buffer that receives the audio samples 106 @param buf pointer to sound buffer that receives the audio samples
107 @param len length of the sound buffer 107 @param len length of the sound buffer
108*/ 108*/
109void wsg3_play_sound(int * buf, int len); 109void wsg3_play_sound(int16_t * buf, int len);
110 110
111/** 111/**
112 Returns the sampling rate currently in use for rendering sound. 112 Returns the sampling rate currently in use for rendering sound.