···640640 }
641641}
642642643643-void playSound( int * buf, int len )
643643+void playSound( int16_t * buf, int len )
644644{
645645 /* Clear the buffer */
646646- memset( buf, 0, sizeof (int)*len);
646646+ memset( buf, 0, sizeof (int16_t)*len);
647647648648 /* Exit now if sound is disabled */
649649 if( (output_devices_ & SoundEnabled) == 0 )
+1-1
apps/plugins/pacbox/arcade.h
···123123int run(void);
124124void reset_PacmanMachine(void);
125125void decodeROMs(void);
126126-void playSound( int * buf, int len );
126126+void playSound( int16_t * buf, int len );
127127128128129129/**
+9-8
apps/plugins/pacbox/pacbox.c
···281281static uint32_t sound_buf[NBSAMPLES];
282282#if CONFIG_CPU == MCF5249
283283/* Not enough to put this in IRAM */
284284-static int raw_buf[NBSAMPLES];
284284+static int16_t raw_buf[NBSAMPLES];
285285#else
286286-static int raw_buf[NBSAMPLES] IBSS_ATTR;
286286+static int16_t raw_buf[NBSAMPLES] IBSS_ATTR;
287287#endif
288288289289/*
···291291 */
292292static void get_more(unsigned char **start, size_t *size)
293293{
294294- int i;
295295- int32_t *out;
296296- int *raw;
294294+ int32_t *out, *outend;
295295+ int16_t *raw;
297296298297 /* Emulate the audio for the current register settings */
299298 playSound(raw_buf, NBSAMPLES);
300299301300 out = sound_buf;
301301+ outend = out + NBSAMPLES;
302302 raw = raw_buf;
303303304304- /* Normalize the audio and convert to stereo */
305305- for (i = 0; i < NBSAMPLES; i++)
304304+ /* Convert to stereo */
305305+ do
306306 {
307307- uint32_t sample = (uint16_t)*raw++ << 6;
307307+ uint32_t sample = (uint16_t)*raw++;
308308 *out++ = sample | (sample << 16);
309309 }
310310+ while (out < outend);
310311311312 *start = (unsigned char *)sound_buf;
312313 *size = NBSAMPLES*sizeof(sound_buf[0]);
+12-8
apps/plugins/pacbox/wsg3.c
···6565 return true;
6666}
67676868-void wsg3_play_sound(int * buf, int len)
6868+void wsg3_play_sound(int16_t * buf, int len)
6969{
7070 struct wsg3_voice voice;
7171···7373 {
7474 unsigned offset = wsg3.wave_offset[0];
7575 unsigned step = voice.frequency * wsg3.resample_step;
7676- int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
7676+ int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
7777 int volume = voice.volume;
7878 int i;
7979···8181 {
8282 /* Should be shifted right by 15, but we must also get rid
8383 * of the 10 bits used for decimals */
8484- buf[i] += wave_data[(offset >> 25) & 0x1F] * volume;
8484+ buf[i] = (int)wave_data[(offset >> 25) & 0x1F] * volume;
8585 offset += step;
8686 }
8787···9292 {
9393 unsigned offset = wsg3.wave_offset[1];
9494 unsigned step = voice.frequency * wsg3.resample_step;
9595- int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
9595+ int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
9696 int volume = voice.volume;
9797 int i;
9898···100100 {
101101 /* Should be shifted right by 15, but we must also get rid
102102 * of the 10 bits used for decimals */
103103- buf[i] += wave_data[(offset >> 25) & 0x1F] * volume;
103103+ buf[i] += (int)wave_data[(offset >> 25) & 0x1F] * volume;
104104 offset += step;
105105 }
106106···111111 {
112112 unsigned offset = wsg3.wave_offset[2];
113113 unsigned step = voice.frequency * wsg3.resample_step;
114114- int * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
114114+ int16_t * wave_data = wsg3.sound_wave_data + 32 * voice.waveform;
115115 int volume = voice.volume;
116116 int i;
117117···119119 {
120120 /* Should be shifted right by 15, but we must also get rid
121121 * of the 10 bits used for decimals */
122122- buf[i] += wave_data[(offset >> 25) & 0x1F] * volume;
122122+ buf[i] += (int)wave_data[(offset >> 25) & 0x1F] * volume;
123123 offset += step;
124124 }
125125···137137{
138138 int i;
139139140140+ memcpy(wsg3.sound_prom, prom, 32*8);
141141+142142+ /* Copy wave data and convert 4-bit unsigned -> 16-bit signed,
143143+ * prenormalized */
140144 for (i = 0; i < 32*8; i++)
141141- wsg3.sound_wave_data[i] = (int)*prom++ - 8;
145145+ wsg3.sound_wave_data[i] = ((int16_t)wsg3.sound_prom[i] - 8) * 85;
142146}
143147144148void wsg3_init(unsigned master_clock)
+2-2
apps/plugins/pacbox/wsg3.h
···5656 unsigned char sound_prom[32*8];
5757 unsigned resample_step;
5858 unsigned wave_offset[3];
5959- int sound_wave_data[32*8];
5959+ int16_t sound_wave_data[32*8]; /* sign-extended 4-bit, prenormalized */
6060};
61616262extern struct wsg3 wsg3;
···106106 @param buf pointer to sound buffer that receives the audio samples
107107 @param len length of the sound buffer
108108*/
109109-void wsg3_play_sound(int * buf, int len);
109109+void wsg3_play_sound(int16_t * buf, int len);
110110111111/**
112112 Returns the sampling rate currently in use for rendering sound.