sound, fix mcd cdda (mono, resampling), type cleanup, remove minimp3

This commit is contained in:
kub 2022-02-08 20:49:43 +00:00
parent 9f1d5acdb4
commit f7741cac91
14 changed files with 193 additions and 89 deletions

3
.gitmodules vendored
View file

@ -10,9 +10,6 @@
[submodule "pico/cd/libchdr"]
path = pico/cd/libchdr
url = https://github.com/rtissera/libchdr.git
[submodule "platform/common/minimp3"]
path = platform/common/minimp3
url = https://github.com/lieff/minimp3
[submodule "platform/common/dr_libs"]
path = platform/common/dr_libs
url = https://github.com/mackron/dr_libs

View file

@ -266,7 +266,7 @@ void p32x_pwm_write16(u32 a, unsigned int d, SH2 *sh2, unsigned int m68k_cycles)
}
}
void p32x_pwm_update(int *buf32, int length, int stereo)
void p32x_pwm_update(s32 *buf32, int length, int stereo)
{
short *pwmb;
int step;

View file

@ -23,7 +23,7 @@ extern void lprintf(const char *fmt, ...);
// external funcs for Sega/Mega CD
extern int mp3_get_bitrate(void *f, int size);
extern void mp3_start_play(void *f, int pos);
extern void mp3_update(int *buffer, int length, int stereo);
extern void mp3_update(s32 *buffer, int length, int stereo);
// this function should write-back d-cache and invalidate i-cache
// on a mem region [start_addr, end_addr)
@ -253,7 +253,7 @@ void Pico32xSetClocks(int msh2_hz, int ssh2_hz);
#define PICO_SSH2_HZ ((int)(7670442.0 * 2.4))
// sound.c
extern void (*PsndMix_32_to_16l)(short *dest, int *src, int count);
extern void (*PsndMix_32_to_16l)(s16 *dest, s32 *src, int count);
void PsndRerate(int preserve_state);
// media.c

View file

@ -452,6 +452,7 @@ struct PicoSound
int len_e_cnt;
unsigned int clkl_mult; // z80 clocks per line in Q20
unsigned int smpl_mult; // samples per line in Q16
unsigned int cdda_mult, cdda_div; // 44.1 KHz resampling factor in Q16
short dac_val, dac_val2; // last DAC sample
unsigned int dac_pos; // last DAC position in Q20
unsigned int fm_pos; // last FM position in Q20
@ -1025,7 +1026,7 @@ extern int Pico32xDrawMode;
// 32x/pwm.c
unsigned int p32x_pwm_read16(u32 a, SH2 *sh2, unsigned int m68k_cycles);
void p32x_pwm_write16(u32 a, unsigned int d, SH2 *sh2, unsigned int m68k_cycles);
void p32x_pwm_update(int *buf32, int length, int stereo);
void p32x_pwm_update(s32 *buf32, int length, int stereo);
void p32x_pwm_ctl_changed(void);
void p32x_pwm_schedule(unsigned int m68k_now);
void p32x_pwm_schedule_sh2(SH2 *sh2);

View file

@ -8,6 +8,7 @@
*/
#include <string.h>
#include "../pico_int.h"
#define MAXOUT (+32767)
#define MINOUT (-32768)
@ -15,7 +16,7 @@
/* limitter */
#define Limit16(val) \
val -= val >> 3; /* reduce level to avoid clipping */ \
if ((short)val != val) val = (val < 0 ? MINOUT : MAXOUT)
if ((s16)val != val) val = (val < 0 ? MINOUT : MAXOUT)
int mix_32_to_16l_level;
@ -81,17 +82,17 @@ static inline int filter_null(struct iir *fi2, int x)
lfi2 = lf, rfi2 = rf; \
}
void mix_32_to_16l_stereo_lvl(short *dest, int *src, int count)
void mix_32_to_16l_stereo_lvl(s16 *dest, s32 *src, int count)
{
mix_32_to_16l_stereo_core(dest, src, count, mix_32_to_16l_level, filter);
}
void mix_32_to_16l_stereo(short *dest, int *src, int count)
void mix_32_to_16l_stereo(s16 *dest, s32 *src, int count)
{
mix_32_to_16l_stereo_core(dest, src, count, 0, filter);
}
void mix_32_to_16_mono(short *dest, int *src, int count)
void mix_32_to_16_mono(s16 *dest, s32 *src, int count)
{
int l;
struct iir lf = lfi2;
@ -108,7 +109,7 @@ void mix_32_to_16_mono(short *dest, int *src, int count)
}
void mix_16h_to_32(int *dest_buf, short *mp3_buf, int count)
void mix_16h_to_32(s32 *dest_buf, s16 *mp3_buf, int count)
{
while (count--)
{
@ -116,7 +117,7 @@ void mix_16h_to_32(int *dest_buf, short *mp3_buf, int count)
}
}
void mix_16h_to_32_s1(int *dest_buf, short *mp3_buf, int count)
void mix_16h_to_32_s1(s32 *dest_buf, s16 *mp3_buf, int count)
{
count >>= 1;
while (count--)
@ -127,7 +128,7 @@ void mix_16h_to_32_s1(int *dest_buf, short *mp3_buf, int count)
}
}
void mix_16h_to_32_s2(int *dest_buf, short *mp3_buf, int count)
void mix_16h_to_32_s2(s32 *dest_buf, s16 *mp3_buf, int count)
{
count >>= 1;
while (count--)
@ -138,6 +139,30 @@ void mix_16h_to_32_s2(int *dest_buf, short *mp3_buf, int count)
}
}
// mixes cdda audio @44.1 KHz into dest_buf, resampling with nearest neighbour
void mix_16h_to_32_resample_stereo(s32 *dest_buf, s16 *cdda_buf, int count, int fac16)
{
int pos16 = 0;
while (count--) {
int pos = 2 * (pos16>>16);
*dest_buf++ += cdda_buf[pos ] >> 1;
*dest_buf++ += cdda_buf[pos+1] >> 1;
pos16 += fac16;
}
}
// mixes cdda audio @44.1 KHz into dest_buf, resampling with nearest neighbour
void mix_16h_to_32_resample_mono(s32 *dest_buf, s16 *cdda_buf, int count, int fac16)
{
int pos16 = 0;
while (count--) {
int pos = 2 * (pos16>>16);
*dest_buf += cdda_buf[pos ] >> 2;
*dest_buf++ += cdda_buf[pos+1] >> 2;
pos16 += fac16;
}
}
void mix_reset(int alpha_q16)
{
memset(&lfi2, 0, sizeof(lfi2));

View file

@ -1,11 +1,14 @@
//void mix_32_to_32(int *dest, int *src, int count);
void mix_16h_to_32(int *dest, short *src, int count);
void mix_16h_to_32_s1(int *dest, short *src, int count);
void mix_16h_to_32_s2(int *dest, short *src, int count);
void mix_32_to_16l_stereo(short *dest, int *src, int count);
void mix_32_to_16_mono(short *dest, int *src, int count);
void mix_16h_to_32(s32 *dest, s16 *src, int count);
void mix_16h_to_32_s1(s32 *dest, s16 *src, int count);
void mix_16h_to_32_s2(s32 *dest, s16 *src, int count);
void mix_16h_to_32_resample_stereo(s32 *dest, s16 *src, int count, int fac16);
void mix_16h_to_32_resample_mono(s32 *dest, s16 *src, int count, int fac16);
void mix_32_to_16l_stereo(s16 *dest, s32 *src, int count);
void mix_32_to_16_mono(s16 *dest, s32 *src, int count);
extern int mix_32_to_16l_level;
void mix_32_to_16l_stereo_lvl(short *dest, int *src, int count);
void mix_32_to_16l_stereo_lvl(s16 *dest, s32 *src, int count);
void mix_reset(int alpha_q16);

View file

@ -153,6 +153,92 @@ m16_32_s2_no_unal2:
.global mix_16h_to_32_resample_stereo @ int *dest, short *src, int count, int fac16
mix_16h_to_32_resample_stereo:
stmfd sp!, {r4-r9,lr}
subs r2, r2, #2
mov r4, #0
bmi m16_32_rss_end
m16_32_rss_loop:
ldmia r0, {r5-r8}
lsr r9, r4, #16
ldr r12,[r1, r9, lsl #2]
add r4, r4, r3
lsr r9, r4, #16
ldr lr ,[r1, r9, lsl #2]
add r4, r4, r3
subs r2, r2, #2
add r6, r6, r12,asr #17
mov r12,r12,lsl #16
add r5, r5, r12,asr #17 @ we use half volume
add r8, r8, lr, asr #17
mov lr, lr, lsl #16
add r7, r7, lr, asr #17
stmia r0!,{r5-r8}
bpl m16_32_rss_loop
m16_32_rss_end:
tst r2, #1
ldmeqfd sp!, {r4-r9,pc}
lsr r9, r4, #16
ldr lr ,[r1, r9, lsl #2]
ldmia r0, {r5,r6}
mov r12,lr, lsl #16
add r5, r5, r12,asr #17
add r6, r6, lr, asr #17
stmia r0!,{r5,r6}
ldmfd sp!, {r4-r9,lr}
bx lr
.global mix_16h_to_32_resample_mono @ int *dest, short *src, int count, int fac16
mix_16h_to_32_resample_mono:
stmfd sp!, {r4-r6,r9,lr}
subs r2, r2, #2
mov r4, #0
bmi m16_32_rsm_end
m16_32_rsm_loop:
ldmia r0, {r5-r6}
lsr r9, r4, #16
ldr r12,[r1, r9, lsl #2]
add r4, r4, r3
lsr r9, r4, #16
ldr lr ,[r1, r9, lsl #2]
add r4, r4, r3
subs r2, r2, #2
add r5, r5, r12,asr #18
mov r12,r12,lsl #16
add r5, r5, r12,asr #18 @ we use half volume (= quarter vol per channel)
add r6, r6, lr, asr #18
mov lr, lr, lsl #16
add r6, r6, lr, asr #18
stmia r0!,{r5-r6}
bpl m16_32_rsm_loop
m16_32_rsm_end:
tst r2, #1
ldmeqfd sp!, {r4-r6,r9,pc}
lsr r9, r4, #16
ldr lr ,[r1, r9, lsl #2]
ldr r5, [r0]
mov r12,lr, lsl #16
add r5, r5, r12,asr #18
add r5, r5, lr, asr #18
str r5, [r0]
ldmfd sp!, {r4-r6,r9,lr}
bx lr
@ limit
@ reg=int_sample, r12=1, r8=tmp, kills flags
.macro Limit reg

View file

@ -14,7 +14,7 @@
#include "mix.h"
#include "emu2413/emu2413.h"
void (*PsndMix_32_to_16l)(short *dest, int *src, int count) = mix_32_to_16l_stereo;
void (*PsndMix_32_to_16l)(s16 *dest, s32 *src, int count) = mix_32_to_16l_stereo;
// master int buffer to mix to
// +1 for a fill triggered by an instruction overhanging into the next scanline
@ -98,6 +98,9 @@ void PsndRerate(int preserve_state)
Pico.snd.smpl_mult = 65536LL * PicoIn.sndRate / (target_fps*target_lines);
// samples per z80 clock (Q20)
Pico.snd.clkl_mult = 16 * Pico.snd.smpl_mult * 15/7 / 488;
// samples per 44.1 KHz sample
Pico.snd.cdda_mult = 65536LL * 44100 / PicoIn.sndRate;
Pico.snd.cdda_div = 65536LL * PicoIn.sndRate / 44100;
// clear all buffers
memset32(PsndBuffer, 0, sizeof(PsndBuffer)/4);
@ -154,12 +157,12 @@ PICO_INTERNAL void PsndDoDAC(int cyc_to)
// y[n] = (x[n] + x[n-1])*(1/2) (3dB cutoff at 11025 Hz, no gain)
// 1 sample delay for correct IIR filtering over audio frame boundaries
if (PicoIn.opt & POPT_EN_STEREO) {
short *d = PicoIn.sndOut + pos*2;
s16 *d = PicoIn.sndOut + pos*2;
// left channel only, mixed ro right channel in mixing phase
*d++ += Pico.snd.dac_val2; d++;
while (--len) *d++ += Pico.snd.dac_val, d++;
} else {
short *d = PicoIn.sndOut + pos;
s16 *d = PicoIn.sndOut + pos;
*d++ += Pico.snd.dac_val2;
while (--len) *d++ += Pico.snd.dac_val;
}
@ -200,7 +203,7 @@ PICO_INTERNAL void PsndDoYM2413(int cyc_to)
{
int pos, len;
int stereo = 0;
short *buf;
s16 *buf;
// nothing to do if sound is off
if (!PicoIn.sndOut) return;
@ -268,14 +271,11 @@ PICO_INTERNAL void PsndDoFM(int cyc_to)
}
// cdda
static void cdda_raw_update(int *buffer, int length)
static void cdda_raw_update(s32 *buffer, int length, int stereo)
{
int ret, cdda_bytes, mult = 1;
int ret, cdda_bytes;
cdda_bytes = length*4;
if (PicoIn.sndRate <= 22050 + 100) mult = 2;
if (PicoIn.sndRate < 22050 - 100) mult = 4;
cdda_bytes *= mult;
cdda_bytes = (length * Pico.snd.cdda_mult >> 16) * 4;
ret = pm_read_audio(cdda_out_buffer, cdda_bytes, Pico_mcd->cdda_stream);
if (ret < cdda_bytes) {
@ -285,11 +285,13 @@ static void cdda_raw_update(int *buffer, int length)
}
// now mix
switch (mult) {
case 1: mix_16h_to_32(buffer, cdda_out_buffer, length*2); break;
case 2: mix_16h_to_32_s1(buffer, cdda_out_buffer, length*2); break;
case 4: mix_16h_to_32_s2(buffer, cdda_out_buffer, length*2); break;
}
if (stereo) switch (Pico.snd.cdda_mult) {
case 0x10000: mix_16h_to_32(buffer, cdda_out_buffer, length*2); break;
case 0x20000: mix_16h_to_32_s1(buffer, cdda_out_buffer, length*2); break;
case 0x40000: mix_16h_to_32_s2(buffer, cdda_out_buffer, length*2); break;
default: mix_16h_to_32_resample_stereo(buffer, cdda_out_buffer, length, Pico.snd.cdda_mult);
} else
mix_16h_to_32_resample_mono(buffer, cdda_out_buffer, length, Pico.snd.cdda_mult);
}
void cdda_start_play(int lba_base, int lba_offset, int lb_len)
@ -326,7 +328,7 @@ PICO_INTERNAL void PsndClear(void)
if (PicoIn.opt & POPT_EN_STEREO)
memset32((int *) PicoIn.sndOut, 0, len); // assume PicoIn.sndOut to be aligned
else {
short *out = PicoIn.sndOut;
s16 *out = PicoIn.sndOut;
if ((uintptr_t)out & 2) { *out++ = 0; len--; }
memset32((int *) out, 0, len/2);
if (len & 1) out[len-1] = 0;
@ -350,14 +352,14 @@ static int PsndRender(int offset, int length)
if (PicoIn.AHW & PAHW_PICO) {
// XXX ugly hack, need to render sound for interrupts
s16 *buf16 = PicoIn.sndOut ? PicoIn.sndOut : (short *)PsndBuffer;
s16 *buf16 = PicoIn.sndOut ? PicoIn.sndOut : (s16 *)PsndBuffer;
PicoPicoPCMUpdate(buf16+(offset<<stereo), length-offset, stereo);
return length;
}
// Fill up DAC output in case of missing samples (Q rounding errors)
if (length-daclen > 0 && PicoIn.sndOut) {
short *dacbuf = PicoIn.sndOut + (daclen << stereo);
s16 *dacbuf = PicoIn.sndOut + (daclen << stereo);
Pico.snd.dac_pos += (length-daclen) << 20;
*dacbuf++ += Pico.snd.dac_val2;
if (stereo) dacbuf++;
@ -370,7 +372,7 @@ static int PsndRender(int offset, int length)
// Add in parts of the PSG output not yet done
if (length-psglen > 0 && PicoIn.sndOut) {
short *psgbuf = PicoIn.sndOut + (psglen << stereo);
s16 *psgbuf = PicoIn.sndOut + (psglen << stereo);
Pico.snd.psg_pos += (length-psglen) << 20;
if (PicoIn.opt & POPT_EN_PSG)
SN76496Update(psgbuf, length-psglen, stereo);
@ -378,7 +380,7 @@ static int PsndRender(int offset, int length)
// Add in parts of the FM buffer not yet done
if (length-fmlen > 0 && PicoIn.sndOut) {
int *fmbuf = buf32 + ((fmlen-offset) << stereo);
s32 *fmbuf = buf32 + ((fmlen-offset) << stereo);
Pico.snd.fm_pos += (length-fmlen) << 20;
if (PicoIn.opt & POPT_EN_FM)
YM2612UpdateOne(fmbuf, length-fmlen, stereo, 1);
@ -395,11 +397,10 @@ static int PsndRender(int offset, int length)
&& Pico_mcd->cdda_stream != NULL
&& !(Pico_mcd->s68k_regs[0x36] & 1))
{
// note: only 44, 22 and 11 kHz supported, with forced stereo
if (Pico_mcd->cdda_type == CT_MP3)
mp3_update(buf32, length-offset, stereo);
else
cdda_raw_update(buf32, length-offset);
cdda_raw_update(buf32, length-offset, stereo);
}
if ((PicoIn.AHW & PAHW_32X) && (PicoIn.opt & POPT_EN_PWM))
@ -439,14 +440,14 @@ static int PsndRenderMS(int offset, int length)
// Add in parts of the PSG output not yet done
if (length-psglen > 0) {
short *psgbuf = PicoIn.sndOut + (psglen << stereo);
s16 *psgbuf = PicoIn.sndOut + (psglen << stereo);
Pico.snd.psg_pos += (length-psglen) << 20;
if (PicoIn.opt & POPT_EN_PSG)
SN76496Update(psgbuf, length-psglen, stereo);
}
if (length-ym2413len > 0) {
short *ym2413buf = PicoIn.sndOut + (ym2413len << stereo);
s16 *ym2413buf = PicoIn.sndOut + (ym2413len << stereo);
Pico.snd.ym2413_pos += (length-ym2413len) << 20;
int len = (length-ym2413len);
if (PicoIn.opt & POPT_EN_YM2413){
@ -461,8 +462,8 @@ static int PsndRenderMS(int offset, int length)
// upmix to "stereo" if needed
if (PicoIn.opt & POPT_EN_STEREO) {
int i;
short *p;
for (i = length, p = (short *)PicoIn.sndOut; i > 0; i--, p+=2)
s16 *p;
for (i = length, p = (s16 *)PicoIn.sndOut; i > 0; i--, p+=2)
*(p + 1) = *p;
}

View file

@ -1127,7 +1127,7 @@ static int update_algo_channel(chan_rend_context *ct, unsigned int eg_out, unsig
return smp;
}
static void chan_render_loop(chan_rend_context *ct, int *buffer, int length)
static void chan_render_loop(chan_rend_context *ct, s32 *buffer, int length)
{
int scounter; /* sample counter */
@ -1244,7 +1244,7 @@ disabled:
}
}
#else
void chan_render_loop(chan_rend_context *ct, int *buffer, unsigned short length);
void chan_render_loop(chan_rend_context *ct, s32 *buffer, unsigned short length);
#endif
static chan_rend_context crct;
@ -1255,7 +1255,7 @@ static void chan_render_prep(void)
crct.lfo_inc = ym2612.OPN.lfo_inc;
}
static void chan_render_finish(int *buffer, unsigned short length, int active_chans)
static void chan_render_finish(s32 *buffer, unsigned short length, int active_chans)
{
ym2612.OPN.eg_cnt = crct.eg_cnt;
ym2612.OPN.eg_timer = crct.eg_timer;
@ -1290,7 +1290,7 @@ static UINT32 update_lfo_phase(FM_SLOT *SLOT, UINT32 block_fnum)
return SLOT->Incr;
}
static int chan_render(int *buffer, int length, int c, UINT32 flags) // flags: stereo, ?, disabled, ?, pan_r, pan_l
static int chan_render(s32 *buffer, int length, int c, UINT32 flags) // flags: stereo, ?, disabled, ?, pan_r, pan_l
{
crct.CH = &ym2612.CH[c];
crct.mem = crct.CH->mem_value; /* one sample delay memory */
@ -1781,7 +1781,7 @@ static int OPNWriteReg(int r, int v)
/*******************************************************************************/
/* Generate samples for YM2612 */
int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty)
int YM2612UpdateOne_(s32 *buffer, int length, int stereo, int is_buf_empty)
{
int pan;
int active_chs = 0;

View file

@ -167,7 +167,7 @@ extern YM2612 ym2612;
void YM2612Init_(int baseclock, int rate, int flags);
void YM2612ResetChip_(void);
int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty);
int YM2612UpdateOne_(s32 *buffer, int length, int stereo, int is_buf_empty);
int YM2612Write_(unsigned int a, unsigned int v);
//unsigned char YM2612Read_(void);

View file

@ -24,7 +24,7 @@ static char *mystrip(char *str);
#include "menu_pico.h"
#include "emu.h"
#include <pico/pico.h>
#include <pico/pico_int.h>
// always output DOS endlines
#ifdef _WIN32

@ -1 +0,0 @@
Subproject commit 95864e8e0d3b34402a49ae9af6c66f7e98c13c35

View file

@ -128,10 +128,10 @@ void mp3_start_play(void *f_, int pos1024)
mp3dec_decode(mp3_current_file, &mp3_file_pos, mp3_file_len);
}
void mp3_update(int *buffer, int length, int stereo)
void mp3_update(s32 *buffer, int length, int stereo)
{
int length_mp3, shr = 0;
void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;
int length_mp3;
void (*mix_samples)(int *dest_buf, short *mp3_buf, int count, int fac16) = mix_16h_to_32_resample_stereo;
if (mp3_current_file == NULL || mp3_file_pos >= mp3_file_len)
return; /* no file / EOF */
@ -139,35 +139,29 @@ void mp3_update(int *buffer, int length, int stereo)
if (!decoder_active)
return;
length_mp3 = length;
if (PicoIn.sndRate <= 11025 + 100) {
mix_samples = mix_16h_to_32_s2;
length_mp3 <<= 2; shr = 2;
}
else if (PicoIn.sndRate <= 22050 + 100) {
mix_samples = mix_16h_to_32_s1;
length_mp3 <<= 1; shr = 1;
}
length_mp3 = length * Pico.snd.cdda_mult >> 16;
if (!stereo)
mix_samples = mix_16h_to_32_resample_mono;
if (1152 - cdda_out_pos >= length_mp3) {
mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
length * 2);
length, Pico.snd.cdda_mult);
cdda_out_pos += length_mp3;
} else {
int ret, left = 1152 - cdda_out_pos;
int left = (1152 - cdda_out_pos) * Pico.snd.cdda_div >> 16;
int ret, sm = stereo ? 2 : 1;
if (left > 0)
mix_samples(buffer, cdda_out_buffer + cdda_out_pos * 2,
(left >> shr) * 2);
left, Pico.snd.cdda_mult);
ret = mp3dec_decode(mp3_current_file, &mp3_file_pos,
mp3_file_len);
if (ret == 0) {
cdda_out_pos = length_mp3 - left;
mix_samples(buffer + (left >> shr) * 2,
cdda_out_buffer,
(cdda_out_pos >> shr) * 2);
mix_samples(buffer + left * sm, cdda_out_buffer,
length-left, Pico.snd.cdda_mult);
cdda_out_pos = (length-left) * Pico.snd.cdda_mult >> 16;
} else
cdda_out_pos = 0;
}

View file

@ -386,16 +386,14 @@ void mp3_start_play(void *f, int pos)
}
void mp3_update(int *buffer, int length, int stereo)
void mp3_update(s32 *buffer, int length, int stereo)
{
int length_mp3;
// playback was started, track not ended
if (mp3_handle < 0 || mp3_src_pos >= mp3_src_size) return;
length_mp3 = length;
if (PicoIn.sndRate == 22050) length_mp3 <<= 1; // mp3s are locked to 44100Hz stereo
else if (PicoIn.sndRate == 11025) length_mp3 <<= 2; // so make length 44100ish
length_mp3 = length * Pico.snd.cdda_mult >> 16;
/* do we have to wait? */
if (mp3_job_started && mp3_samples_ready < length_mp3)
@ -409,30 +407,30 @@ void mp3_update(int *buffer, int length, int stereo)
/* mix mp3 data, only stereo */
if (mp3_samples_ready >= length_mp3)
{
int shr = 0;
void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;
if (PicoIn.sndRate == 22050) { mix_samples = mix_16h_to_32_s1; shr = 1; }
else if (PicoIn.sndRate == 11025) { mix_samples = mix_16h_to_32_s2; shr = 2; }
void (*mix_samples)(s32 *dest_buf, s16 *mp3_buf, int count, int fac16) = mix_16h_to_32_resample_stereo;
if (!stereo)
mix_samples = mix_16h_to_32_resample_mono;
if (1152 - mp3_buffer_offs >= length_mp3) {
mix_samples(buffer, mp3_mix_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, length<<1);
mix_samples(buffer, mp3_mix_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, length, Pico.snd.cdda_mult);
mp3_buffer_offs += length_mp3;
} else {
// collect samples from both buffers..
int left = 1152 - mp3_buffer_offs;
int left = (1152 - mp3_buffer_offs) * Pico.snd.cdda_div >> 16;
int sm = stereo ? 2 : 1;
if (mp3_play_bufsel == 0)
{
mix_samples(buffer, mp3_mix_buffer[0] + mp3_buffer_offs*2, length<<1);
mp3_buffer_offs = length_mp3 - left;
mix_samples(buffer, mp3_mix_buffer[0] + mp3_buffer_offs*2, length, Pico.snd.cdda_mult);
mp3_play_bufsel = 1;
} else {
mix_samples(buffer, mp3_mix_buffer[1] + mp3_buffer_offs*2, (left>>shr)<<1);
mp3_buffer_offs = length_mp3 - left;
mix_samples(buffer + ((left>>shr)<<1),
mp3_mix_buffer[0], (mp3_buffer_offs>>shr)<<1);
mix_samples(buffer, mp3_mix_buffer[1] + mp3_buffer_offs*2, left, Pico.snd.cdda_mult);
mix_samples(buffer + left * sm,
mp3_mix_buffer[0], (length-left), Pico.snd.cdda_mult);
mp3_play_bufsel = 0;
}
mp3_buffer_offs = (length-left) * Pico.snd.cdda_mult >> 16;
}
mp3_samples_ready -= length_mp3;
}