A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

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

+26 -21
+2 -2
apps/plugins/pacbox/arcade.c
··· 640 640 } 641 641 } 642 642 643 - void playSound( int * buf, int len ) 643 + void playSound( int16_t * buf, int len ) 644 644 { 645 645 /* Clear the buffer */ 646 - memset( buf, 0, sizeof (int)*len); 646 + memset( buf, 0, sizeof (int16_t)*len); 647 647 648 648 /* Exit now if sound is disabled */ 649 649 if( (output_devices_ & SoundEnabled) == 0 )
+1 -1
apps/plugins/pacbox/arcade.h
··· 123 123 int run(void); 124 124 void reset_PacmanMachine(void); 125 125 void decodeROMs(void); 126 - void playSound( int * buf, int len ); 126 + void playSound( int16_t * buf, int len ); 127 127 128 128 129 129 /**
+9 -8
apps/plugins/pacbox/pacbox.c
··· 281 281 static uint32_t sound_buf[NBSAMPLES]; 282 282 #if CONFIG_CPU == MCF5249 283 283 /* Not enough to put this in IRAM */ 284 - static int raw_buf[NBSAMPLES]; 284 + static int16_t raw_buf[NBSAMPLES]; 285 285 #else 286 - static int raw_buf[NBSAMPLES] IBSS_ATTR; 286 + static int16_t raw_buf[NBSAMPLES] IBSS_ATTR; 287 287 #endif 288 288 289 289 /* ··· 291 291 */ 292 292 static void get_more(unsigned char **start, size_t *size) 293 293 { 294 - int i; 295 - int32_t *out; 296 - int *raw; 294 + int32_t *out, *outend; 295 + int16_t *raw; 297 296 298 297 /* Emulate the audio for the current register settings */ 299 298 playSound(raw_buf, NBSAMPLES); 300 299 301 300 out = sound_buf; 301 + outend = out + NBSAMPLES; 302 302 raw = raw_buf; 303 303 304 - /* Normalize the audio and convert to stereo */ 305 - for (i = 0; i < NBSAMPLES; i++) 304 + /* Convert to stereo */ 305 + do 306 306 { 307 - uint32_t sample = (uint16_t)*raw++ << 6; 307 + uint32_t sample = (uint16_t)*raw++; 308 308 *out++ = sample | (sample << 16); 309 309 } 310 + while (out < outend); 310 311 311 312 *start = (unsigned char *)sound_buf; 312 313 *size = NBSAMPLES*sizeof(sound_buf[0]);
+12 -8
apps/plugins/pacbox/wsg3.c
··· 65 65 return true; 66 66 } 67 67 68 - void wsg3_play_sound(int * buf, int len) 68 + void wsg3_play_sound(int16_t * buf, int len) 69 69 { 70 70 struct wsg3_voice voice; 71 71 ··· 73 73 { 74 74 unsigned offset = wsg3.wave_offset[0]; 75 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 77 int volume = voice.volume; 78 78 int i; 79 79 ··· 81 81 { 82 82 /* Should be shifted right by 15, but we must also get rid 83 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 85 offset += step; 86 86 } 87 87 ··· 92 92 { 93 93 unsigned offset = wsg3.wave_offset[1]; 94 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 96 int volume = voice.volume; 97 97 int i; 98 98 ··· 100 100 { 101 101 /* Should be shifted right by 15, but we must also get rid 102 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 104 offset += step; 105 105 } 106 106 ··· 111 111 { 112 112 unsigned offset = wsg3.wave_offset[2]; 113 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 115 int volume = voice.volume; 116 116 int i; 117 117 ··· 119 119 { 120 120 /* Should be shifted right by 15, but we must also get rid 121 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 123 offset += step; 124 124 } 125 125 ··· 137 137 { 138 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 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 144 148 void wsg3_init(unsigned master_clock)
+2 -2
apps/plugins/pacbox/wsg3.h
··· 56 56 unsigned char sound_prom[32*8]; 57 57 unsigned resample_step; 58 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 62 62 extern struct wsg3 wsg3; ··· 106 106 @param buf pointer to sound buffer that receives the audio samples 107 107 @param len length of the sound buffer 108 108 */ 109 - void wsg3_play_sound(int * buf, int len); 109 + void wsg3_play_sound(int16_t * buf, int len); 110 110 111 111 /** 112 112 Returns the sampling rate currently in use for rendering sound.