diff --git a/src/game/lv.c b/src/game/lv.c index 4a416902c..792e4d84a 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -2438,9 +2438,9 @@ void lv_set_paused(bool paused) { if (paused) { pak_disable_rumble_for_all_players(); - snd0000fe20(); + snd_pause_mp3(); } else { - snd0000fe50(); + snd_unpause_mp3(); pak_enable_rumble_for_all_players(); } diff --git a/src/include/constants.h b/src/include/constants.h index 3f375b007..a5d77af0c 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -2621,6 +2621,13 @@ #define MP3RESPONSETYPE_WHISPER 2 #define MP3RESPONSETYPE_GREETING 3 +#define MP3STATE_IDLE 0 +#define MP3STATE_PLAYING 1 +#define MP3STATE_PAUSED 2 +#define MP3STATE_STOPPED 3 +#define MP3STATE_LOADING 4 +#define MP3STATE_UNPAUSING 5 + #define MPBODY_DARK_COMBAT 0x00 #define MPBODY_DARK_TRENCH 0x01 #define MPBODY_DARK_FROCK 0x02 diff --git a/src/include/lib/mp3.h b/src/include/lib/mp3.h index b2f1fdbde..67e6af90e 100644 --- a/src/include/lib/mp3.h +++ b/src/include/lib/mp3.h @@ -6,12 +6,12 @@ void mp3_init(ALHeap *heap); void mp3_play_file(s32 romaddr, s32 filesize); -void func00037e1c(void); -void func00037e38(void); -void func00037e68(void); -s32 func00037ea4(void); -void func00037f08(s32 arg0, bool arg1); -void func00037f5c(s32 arg0, bool arg1); -s32 func00037fc0(s32 arg0, Acmd **cmd); +void mp3_stop(void); +void mp3_pause(void); +void mp3_unpause(void); +s32 mp3_is_busy(void); +void mp3_set_vol(s32 vol, bool arg1); +void mp3_set_pan(s32 pan, bool immediate); +bool mp3_make_samples(s32 arg0, Acmd **cmd); #endif diff --git a/src/include/lib/snd.h b/src/include/lib/snd.h index 8cbe2e5c1..6626b876c 100644 --- a/src/include/lib/snd.h +++ b/src/include/lib/snd.h @@ -12,17 +12,17 @@ void snd_set_sound_mode(s32 mode); ALSound *snd_load_sound(s16 soundnum); void snd_init(void); bool snd_is_mp3(s16 soundnum); -bool snd_stop_mp3(s16 arg0); +bool snd_stop_mp3(s16 soundnum); bool seq_play(struct seqinstance *seq, s32 tracknum); void seq_set_volume(struct seqinstance *seq, u16 volume); void snd_handle_retrace(void); -void snd0000fe20(void); -void snd0000fe50(void); +void snd_pause_mp3(void); +void snd_unpause_mp3(void); void snd_tick(void); bool snd_is_disabled(void); void snd_start_mp3_by_filenum(u32 filenum); void snd_adjust(struct sndstate **handle, bool ismp3, s32 vol, s32 pan, s32 soundnum, f32 pitch, s32 fxbus, s32 fxmix, bool forcefxmix); -struct sndstate *snd00010718(struct sndstate **handle, s32 flags, s32 volume, s32 pan, s32 soundnum, f32 pitch, s32 fxbus, s32 fxmix, bool forcefxmix); +struct sndstate *snd00010718(struct sndstate **handle, bool ismp3, s32 volume, s32 pan, s32 soundnum, f32 pitch, s32 fxbus, s32 fxmix, bool forcefxmix); struct sndstate *snd_start(s32 arg0, s16 sound, struct sndstate **handle, s32 volume, s32 pan, f32 pitch, s32 fxbus, s32 fxmix); void snd_start_mp3(s16 soundnum, s32 volume, s32 pan, s32 responseflags); void snd_play_nosedive(s32 seconds); diff --git a/src/include/types.h b/src/include/types.h index 83283492b..6ce5c93d5 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -5584,38 +5584,38 @@ struct mp3thing { struct mp3vars { /*0x00*/ s32 romaddr; - /*0x04*/ struct asistream *var8009c394; - /*0x08*/ u8 *var8009c398; - /*0x0c*/ s16 var8009c39c; - /*0x0e*/ s16 var8009c39e; - /*0x10*/ s16 ivol1; - /*0x12*/ s16 ivol2; - /*0x14*/ s16 var8009c3a4; - /*0x16*/ s16 var8009c3a6; - /*0x18*/ u16 ratel1; - /*0x1a*/ s16 ratem1; - /*0x1c*/ s16 var8009c3ac; - /*0x1e*/ u16 ratel2; - /*0x20*/ s16 ratem2; - /*0x22*/ s16 var8009c3b2; - /*0x24*/ s16 var8009c3b4; - /*0x28*/ s32 samples; - /*0x2c*/ s32 var8009c3bc; + /*0x04*/ struct asistream *stream; + /*0x08*/ ENVMIX_STATE *em_state; + /*0x0c*/ s16 em_pan; + /*0x0e*/ s16 em_volume; + /*0x10*/ s16 em_cvolL; + /*0x12*/ s16 em_cvolR; + /*0x14*/ s16 em_dryamt; + /*0x16*/ s16 em_wetamt; + /*0x18*/ u16 em_lratl; + /*0x1a*/ s16 em_lratm; + /*0x1c*/ s16 em_ltgt; + /*0x1e*/ u16 em_rratl; + /*0x20*/ s16 em_rratm; + /*0x22*/ s16 em_rtgt; + /*0x24*/ s16 em_first; + /*0x28*/ s32 em_delta; + /*0x2c*/ s32 em_segEnd; /*0x30*/ s32 filesize; - /*0x34*/ s32 var8009c3c4; + /*0x34*/ s32 dmaoffset; /*0x38*/ struct mp3thing *var8009c3c8; /*0x3c*/ s32 var8009c3cc; /*0x40*/ s32 var8009c3d0; /*0x44*/ u32 *var8009c3d4[1]; /*0x48*/ u32 var8009c3d8; - /*0x4c*/ void *var8009c3dc; - /*0x50*/ u32 var8009c3e0; - /*0x54*/ u32 var8009c3e4; + /*0x4c*/ void *dmafunc; + /*0x50*/ u32 state; + /*0x54*/ u32 currentvol; /*0x58*/ u32 var8009c3e8; - /*0x5c*/ s16 var8009c3ec; - /*0x5e*/ s16 var8009c3ee; - /*0x60*/ u8 var8009c3f0; - /*0x61*/ u8 var8009c3f1; + /*0x5c*/ s16 currentpan; + /*0x5e*/ s16 targetpan; + /*0x60*/ u8 statetimer; + /*0x61*/ u8 dualchannel; }; struct rdptask { diff --git a/src/lib/mp3.c b/src/lib/mp3.c index 52735c339..cfd248c74 100644 --- a/src/lib/mp3.c +++ b/src/lib/mp3.c @@ -11,25 +11,27 @@ * These two ABI commands are used in this file, but the format of the data * doesn't match the format used by n_audio's ABI. */ -#define acmd07(pkt, a, b) \ +#define aMp3ExecDma(pkt, a, b) \ { \ Acmd *_a = (Acmd *)pkt; \ _a->words.w0 = _SHIFTL(0x07, 24, 8) | _SHIFTL(a, 0, 16); \ _a->words.w1 = b; \ } -#define acmd08(pkt, a) \ +#define aMp3SetAddr(pkt, a) \ { \ Acmd *_a = (Acmd *)pkt; \ _a->words.w0 = _SHIFTL(0x08, 24, 8); \ _a->words.w1 = a; \ } +#define N_EQPOWER_LENGTH 128 + struct mp3vars g_Mp3Vars; struct asistream *g_AsiStream; -void func00038b90(void *fn); -s32 func00038ba8(s32 arg0, u8 *arg1, s32 arg2, s32 arg3); +void mp3_set_dma_func(void *fn); +s32 mp3_handle_dma(s32 arg0, u8 *arg1, s32 arg2, s32 arg3); void mp3_dma(void); extern f32 *var8009c6d8; @@ -37,7 +39,7 @@ extern f32 *var8009c6dc; extern struct mp3decfourbytes *var8009c640; extern f32 *var8009c644; -void func00038924(struct mp3vars *vars); +void mp3_update_vars(struct mp3vars *vars); void mp3_init(ALHeap *heap) { @@ -50,7 +52,6 @@ void mp3_init(ALHeap *heap) g_AsiStream = alHeapAlloc(heap, sizeof(struct asistream), 1); var8005f6f8 = alHeapAlloc(heap, 1, 34 * 256 * sizeof(var8005f6f8[0])); var8005f6fc = alHeapAlloc(heap, 1, 34 * 256 * sizeof(var8005f6fc[0])); - var8009c6d8 = alHeapAlloc(heap, 256 * sizeof(var8009c6d8[0]), 1); var8009c6dc = alHeapAlloc(heap, 256 * sizeof(var8009c6dc[0]), 1); var8009c640 = alHeapAlloc(heap, 10500 * sizeof(struct mp3decfourbytes), 1); @@ -58,150 +59,149 @@ void mp3_init(ALHeap *heap) mp3main_init(); - g_Mp3Vars.var8009c398 = alHeapAlloc(heap, 1, ALIGN16(sizeof(ALEnvMixer))); + g_Mp3Vars.em_state = alHeapAlloc(heap, 1, ALIGN16(sizeof(ENVMIX_STATE))); g_Mp3Vars.var8009c3d4[0] = alHeapAlloc(heap, 1, 0x440); - g_Mp3Vars.var8009c3e0 = 0; - g_Mp3Vars.var8009c3e4 = 0x7fff; - g_Mp3Vars.var8009c3ec = g_Mp3Vars.var8009c3ee = 0x40; - g_Mp3Vars.var8009c39e = 0x7fff; - g_Mp3Vars.var8009c39c = 0x40; + g_Mp3Vars.state = MP3STATE_IDLE; + g_Mp3Vars.currentvol = AL_VOL_FULL; + g_Mp3Vars.currentpan = g_Mp3Vars.targetpan = AL_PAN_CENTER; + g_Mp3Vars.em_volume = AL_VOL_FULL; + g_Mp3Vars.em_pan = AL_PAN_CENTER; + g_Mp3Vars.em_cvolL = (n_eqpower[g_Mp3Vars.em_pan & 0x7f] * g_Mp3Vars.em_volume) >> 15; + g_Mp3Vars.em_cvolR = (n_eqpower[N_EQPOWER_LENGTH - (g_Mp3Vars.em_pan & 0x7f) - 1] * g_Mp3Vars.em_volume) >> 15; + g_Mp3Vars.em_first = 1; + g_Mp3Vars.em_dryamt = 0x7ffc; + g_Mp3Vars.em_wetamt = (g_Mp3Vars.em_pan & 0x80) ? 1 : 0; - g_Mp3Vars.ivol1 = (n_eqpower[g_Mp3Vars.var8009c39c & 0x7f] * g_Mp3Vars.var8009c39e) >> 15; - g_Mp3Vars.ivol2 = (n_eqpower[127 - (g_Mp3Vars.var8009c39c & 0x7f)] * g_Mp3Vars.var8009c39e) >> 15; - - g_Mp3Vars.var8009c3b4 = 1; - g_Mp3Vars.var8009c3a4 = 0x7ffc; - - if (g_Mp3Vars.var8009c39c & 0x80) { - g_Mp3Vars.var8009c3a6 = 1; - } else { - g_Mp3Vars.var8009c3a6 = 0; - } - - func00038b90(func00038ba8); + mp3_set_dma_func(mp3_handle_dma); } void mp3_play_file(s32 romaddr, s32 filesize) { - if (g_Mp3Vars.var8009c3dc == NULL) { + if (g_Mp3Vars.dmafunc == NULL) { return; } g_Mp3Vars.romaddr = romaddr; g_Mp3Vars.filesize = filesize; - g_Mp3Vars.var8009c3c4 = 0; + g_Mp3Vars.dmaoffset = 0; g_Mp3Vars.var8009c3e8 = 0; - g_Mp3Vars.var8009c3e4 = 0x7fff; - g_Mp3Vars.var8009c3f0 = 5; + g_Mp3Vars.currentvol = AL_VOL_FULL; + g_Mp3Vars.statetimer = 5; mp3_dma(); - g_Mp3Vars.var8009c3e0 = 4; + g_Mp3Vars.state = MP3STATE_LOADING; } -void func00037e1c(void) +void mp3_stop(void) { - g_Mp3Vars.var8009c3e0 = 3; + g_Mp3Vars.state = MP3STATE_STOPPED; } -void func00037e38(void) +void mp3_pause(void) { - if (g_Mp3Vars.var8009c3e0 == 1) { - g_Mp3Vars.var8009c3e0 = 2; + /** + * @bug: Pausing while the MP3 system is still in MP3STATE_LOADING causes + * the pause to be ignored. This is what makes speech skipping possible. + * Additionally, after unpausing the MP3 system is in MP3STATE_UNPAUSING for + * a few frames, so pauses during this time is also ignored. + */ + if (g_Mp3Vars.state == MP3STATE_PLAYING) { + g_Mp3Vars.state = MP3STATE_PAUSED; } } -void func00037e68(void) +void mp3_unpause(void) { - if (g_Mp3Vars.var8009c3e0 == 2) { - g_Mp3Vars.var8009c3f0 = 5; - g_Mp3Vars.var8009c3e0 = 5; + if (g_Mp3Vars.state == MP3STATE_PAUSED) { + g_Mp3Vars.statetimer = 5; + g_Mp3Vars.state = MP3STATE_UNPAUSING; } } -s32 func00037ea4(void) +s32 mp3_is_busy(void) { - if (g_Mp3Vars.var8009c3e0 == 1 - || g_Mp3Vars.var8009c3e0 == 4 - || g_Mp3Vars.var8009c3e0 == 5 - || g_Mp3Vars.var8009c3e0 == 2) { - return g_Mp3Vars.var8009c3e0; + if (g_Mp3Vars.state == MP3STATE_PLAYING + || g_Mp3Vars.state == MP3STATE_LOADING + || g_Mp3Vars.state == MP3STATE_UNPAUSING + || g_Mp3Vars.state == MP3STATE_PAUSED) { + return g_Mp3Vars.state; } else { return 0; } } -void func00037f08(s32 arg0, bool arg1) +void mp3_set_vol(s32 vol, bool arg1) { - if (arg0 < 0) { - g_Mp3Vars.var8009c3e4 = 0; - } else if (arg0 > 0x7fff) { - g_Mp3Vars.var8009c3e4 = 0x7fff; + if (vol < 0) { + g_Mp3Vars.currentvol = 0; + } else if (vol > AL_VOL_FULL) { + g_Mp3Vars.currentvol = AL_VOL_FULL; } else { - g_Mp3Vars.var8009c3e4 = arg0; + g_Mp3Vars.currentvol = vol; } g_Mp3Vars.var8009c3e8 = arg1; } -void func00037f5c(s32 arg0, bool arg1) +void mp3_set_pan(s32 pan, bool immediate) { - if (arg0 > 255) { - arg0 = 255; + if (pan > 255) { + pan = 255; } - if (arg0 < 0) { - arg0 = 0; + if (pan < 0) { + pan = 0; } - g_Mp3Vars.var8009c3ee = arg0; + g_Mp3Vars.targetpan = pan; - if (arg1) { - g_Mp3Vars.var8009c3ec = g_Mp3Vars.var8009c3ee; + if (immediate) { + g_Mp3Vars.currentpan = g_Mp3Vars.targetpan; } } -void func00037fa8(s32 arg0, s32 arg1) +void mp3_00037fa8(s32 arg0, s32 arg1) { // empty } -s32 func00037fc0(s32 arg0, Acmd **cmd) +bool mp3_make_samples(s32 arg0, Acmd **cmd) { s32 i; - s32 sp60; - s32 sp5c = 0; + s32 diff; + s32 numchannels = 0; struct mp3thing *sp58; struct mp3thing *sp54 = NULL; s32 sp50; s32 sp4c = N_AL_MAIN_L_OUT; s32 sp48 = N_AL_MAIN_R_OUT; - if (g_Mp3Vars.var8009c3ec != g_Mp3Vars.var8009c3ee) { - sp60 = g_Mp3Vars.var8009c3ee - g_Mp3Vars.var8009c3ec; + if (g_Mp3Vars.currentpan != g_Mp3Vars.targetpan) { + diff = g_Mp3Vars.targetpan - g_Mp3Vars.currentpan; - if (sp60 >= -2 && sp60 <= 2) { - g_Mp3Vars.var8009c3ec += sp60; - } else if (sp60 >= 3) { - g_Mp3Vars.var8009c3ec += 2; + if (diff >= -2 && diff <= 2) { + g_Mp3Vars.currentpan += diff; + } else if (diff >= 3) { + g_Mp3Vars.currentpan += 2; } else { - g_Mp3Vars.var8009c3ec -= 2; + g_Mp3Vars.currentpan -= 2; } } - if (g_Mp3Vars.var8009c3e0 == 4) { + if (g_Mp3Vars.state == MP3STATE_LOADING) { mp3_dma(); - if (g_Mp3Vars.var8009c3f0 == 0) { - g_Mp3Vars.var8009c394 = mp3main00044460(0, g_Mp3Vars.var8009c3dc, g_Mp3Vars.filesize); + if (g_Mp3Vars.statetimer == 0) { + g_Mp3Vars.stream = mp3main_start_file(0, g_Mp3Vars.dmafunc, g_Mp3Vars.filesize); - if (g_Mp3Vars.var8009c394 == NULL) { - g_Mp3Vars.var8009c3e0 = 0; - return 0; + if (g_Mp3Vars.stream == NULL) { + g_Mp3Vars.state = MP3STATE_IDLE; + return false; } else { - g_Mp3Vars.var8009c3e0 = 1; - g_Mp3Vars.var8009c3b4 = 1; - g_Mp3Vars.var8009c3c8 = 0; + g_Mp3Vars.state = MP3STATE_PLAYING; + g_Mp3Vars.em_first = 1; + g_Mp3Vars.var8009c3c8 = NULL; g_Mp3Vars.var8009c3cc = 0; g_Mp3Vars.var8009c3d0 = 0; g_Mp3Vars.var8009c3d8 = 0; @@ -209,25 +209,25 @@ s32 func00037fc0(s32 arg0, Acmd **cmd) bzero(g_Mp3Vars.var8009c3d4[0], 0x440); } } else { - g_Mp3Vars.var8009c3f0--; + g_Mp3Vars.statetimer--; } } - if (g_Mp3Vars.var8009c3e0 == 5) { + if (g_Mp3Vars.state == MP3STATE_UNPAUSING) { mp3_dma(); - if (g_Mp3Vars.var8009c3f0 == 0) { - g_Mp3Vars.var8009c3e0 = 1; + if (g_Mp3Vars.statetimer == 0) { + g_Mp3Vars.state = MP3STATE_PLAYING; } else { - g_Mp3Vars.var8009c3f0--; + g_Mp3Vars.statetimer--; } } - if (g_Mp3Vars.var8009c3e0 == 1) { + if (g_Mp3Vars.state == MP3STATE_PLAYING) { if (arg0 + g_Mp3Vars.var8009c3d0 > g_Mp3Vars.var8009c3cc) { g_Mp3Vars.var8009c3cc -= g_Mp3Vars.var8009c3d0; - if (g_Mp3Vars.var8009c3cc != 0 && g_Mp3Vars.var8009c3c8 != 0) { + if (g_Mp3Vars.var8009c3cc != 0 && g_Mp3Vars.var8009c3c8 != NULL) { sp54 = (struct mp3thing *)(g_Mp3Vars.var8009c3d0 + g_Mp3Vars.var8009c3c8->unk00); sp50 = g_Mp3Vars.var8009c3cc; } @@ -235,19 +235,19 @@ s32 func00037fc0(s32 arg0, Acmd **cmd) g_Mp3Vars.var8009c3d0 = 0; g_Mp3Vars.var8009c3cc = 0; - if (mp3main0004453c(g_Mp3Vars.var8009c394, &sp58, &sp5c)) { + if (mp3main_continue_file(g_Mp3Vars.stream, &sp58, &numchannels)) { g_Mp3Vars.var8009c3c8 = sp58; - for (i = 0; i < sp5c; i++) { - acmd08((*cmd)++, osVirtualToPhysical(g_Mp3Vars.var8009c3d4[i])); - acmd07((*cmd)++, g_Mp3Vars.var8009c3d8, osVirtualToPhysical(sp58)); + for (i = 0; i < numchannels; i++) { + aMp3SetAddr((*cmd)++, osVirtualToPhysical(g_Mp3Vars.var8009c3d4[i])); + aMp3ExecDma((*cmd)++, g_Mp3Vars.var8009c3d8, osVirtualToPhysical(sp58)); sp58++; } g_Mp3Vars.var8009c3d8 = (g_Mp3Vars.var8009c3d8 - 0x24) & 0x1e; g_Mp3Vars.var8009c3cc = 0x240; - g_Mp3Vars.var8009c3f1 = sp5c == 2; + g_Mp3Vars.dualchannel = numchannels == 2; } else { // empty } @@ -255,14 +255,14 @@ s32 func00037fc0(s32 arg0, Acmd **cmd) mp3_dma(); - if (g_Mp3Vars.var8009c3f1 == 0) { + if (!g_Mp3Vars.dualchannel) { sp4c = 0; } if (sp54 != NULL) { n_aLoadBuffer((*cmd)++, sp50 + sp50, sp4c, osVirtualToPhysical(sp54)); - if (g_Mp3Vars.var8009c3f1) { + if (g_Mp3Vars.dualchannel) { sp54++; n_aLoadBuffer((*cmd)++, sp50 + sp50, sp48, osVirtualToPhysical(sp54)); } @@ -272,12 +272,12 @@ s32 func00037fc0(s32 arg0, Acmd **cmd) arg0 -= sp50; } - if (arg0 > 0 && g_Mp3Vars.var8009c3c8) { + if (arg0 > 0 && g_Mp3Vars.var8009c3c8 != NULL) { sp54 = (struct mp3thing *)(g_Mp3Vars.var8009c3d0 * 2 + (uintptr_t)g_Mp3Vars.var8009c3c8); n_aLoadBuffer((*cmd)++, arg0 + arg0, sp4c, osVirtualToPhysical(sp54)); - if (g_Mp3Vars.var8009c3f1) { + if (g_Mp3Vars.dualchannel) { sp54++; n_aLoadBuffer((*cmd)++, arg0 + arg0, sp48, osVirtualToPhysical(sp54)); } @@ -285,121 +285,121 @@ s32 func00037fc0(s32 arg0, Acmd **cmd) g_Mp3Vars.var8009c3d0 += arg0; } - func00038924(&g_Mp3Vars); + mp3_update_vars(&g_Mp3Vars); - if (!g_Mp3Vars.var8009c3f1) { + if (!g_Mp3Vars.dualchannel) { aClearBuffer((*cmd)++, N_AL_MAIN_L_OUT, N_AL_TEMP_2); - if (g_Mp3Vars.var8009c3b4) { - g_Mp3Vars.var8009c3b4 = 0; + if (g_Mp3Vars.em_first) { + g_Mp3Vars.em_first = 0; - g_Mp3Vars.var8009c3ac = n_eqpower[g_Mp3Vars.var8009c39c & 0x7f] * g_Mp3Vars.var8009c39e >> 0xf; - g_Mp3Vars.ratem1 = _getRate(g_Mp3Vars.ivol1, g_Mp3Vars.var8009c3ac, g_Mp3Vars.var8009c3bc, &g_Mp3Vars.ratel1); + g_Mp3Vars.em_ltgt = (g_Mp3Vars.em_volume * n_eqpower[g_Mp3Vars.em_pan & 0x7f]) >> 15; + g_Mp3Vars.em_lratm = _getRate(g_Mp3Vars.em_cvolL, g_Mp3Vars.em_ltgt, g_Mp3Vars.em_segEnd, &g_Mp3Vars.em_lratl); - g_Mp3Vars.var8009c3b2 = n_eqpower[0x7f - (g_Mp3Vars.var8009c39c & 0x7f)] * g_Mp3Vars.var8009c39e >> 0xf; - g_Mp3Vars.ratem2 = _getRate(g_Mp3Vars.ivol2, g_Mp3Vars.var8009c3b2, g_Mp3Vars.var8009c3bc, &g_Mp3Vars.ratel2); + g_Mp3Vars.em_rtgt = (g_Mp3Vars.em_volume * n_eqpower[N_EQPOWER_LENGTH - (g_Mp3Vars.em_pan & 0x7f) - 1]) >> 15; + g_Mp3Vars.em_rratm = _getRate(g_Mp3Vars.em_cvolR, g_Mp3Vars.em_rtgt, g_Mp3Vars.em_segEnd, &g_Mp3Vars.em_rratl); - n_aSetVolume((*cmd)++, A_VOL | A_LEFT, g_Mp3Vars.ivol1, g_Mp3Vars.var8009c3a4, g_Mp3Vars.var8009c3a6); - n_aSetVolume((*cmd)++, A_VOL | A_RIGHT, g_Mp3Vars.var8009c3b2, g_Mp3Vars.ratem2, g_Mp3Vars.ratel2); - n_aSetVolume((*cmd)++, A_RATE, g_Mp3Vars.var8009c3ac, g_Mp3Vars.ratem1, g_Mp3Vars.ratel1); - n_aEnvMixer((*cmd)++, 1, g_Mp3Vars.ivol2, osVirtualToPhysical(g_Mp3Vars.var8009c398)); + n_aSetVolume((*cmd)++, A_VOL | A_LEFT, g_Mp3Vars.em_cvolL, g_Mp3Vars.em_dryamt, g_Mp3Vars.em_wetamt); + n_aSetVolume((*cmd)++, A_VOL | A_RIGHT, g_Mp3Vars.em_rtgt, g_Mp3Vars.em_rratm, g_Mp3Vars.em_rratl); + n_aSetVolume((*cmd)++, A_RATE, g_Mp3Vars.em_ltgt, g_Mp3Vars.em_lratm, g_Mp3Vars.em_lratl); + n_aEnvMixer((*cmd)++, A_INIT, g_Mp3Vars.em_cvolR, osVirtualToPhysical(g_Mp3Vars.em_state)); } else { - n_aEnvMixer((*cmd)++, 0, 0, osVirtualToPhysical(g_Mp3Vars.var8009c398)); + n_aEnvMixer((*cmd)++, A_CONTINUE, 0, osVirtualToPhysical(g_Mp3Vars.em_state)); } - g_Mp3Vars.samples += SAMPLES; + g_Mp3Vars.em_delta += SAMPLES; - if (g_Mp3Vars.samples > g_Mp3Vars.var8009c3bc) { - g_Mp3Vars.samples = g_Mp3Vars.var8009c3bc; + if (g_Mp3Vars.em_delta > g_Mp3Vars.em_segEnd) { + g_Mp3Vars.em_delta = g_Mp3Vars.em_segEnd; } } } else { - return 0; + return false; } - return 1; + return true; } -void func00038924(struct mp3vars *vars) +void mp3_update_vars(struct mp3vars *vars) { - if (vars->var8009c39e != vars->var8009c3e4 || vars->var8009c39c != vars->var8009c3ec) { - if (vars->samples >= vars->var8009c3bc) { - vars->var8009c3ac = (n_eqpower[vars->var8009c39c & 0x7f] * vars->var8009c39e >> 15); - vars->var8009c3b2 = (n_eqpower[127 - (vars->var8009c39c & 0x7f)] * vars->var8009c39e >> 15); - vars->samples = vars->var8009c3bc; - vars->ivol1 = vars->var8009c3ac; - vars->ivol2 = vars->var8009c3b2; + if (vars->em_volume != vars->currentvol || vars->em_pan != vars->currentpan) { + if (vars->em_delta >= vars->em_segEnd) { + vars->em_ltgt = (n_eqpower[vars->em_pan & 0x7f] * vars->em_volume >> 15); + vars->em_rtgt = (n_eqpower[N_EQPOWER_LENGTH - (vars->em_pan & 0x7f) - 1] * vars->em_volume >> 15); + vars->em_delta = vars->em_segEnd; + vars->em_cvolL = vars->em_ltgt; + vars->em_cvolR = vars->em_rtgt; } else { - vars->ivol1 = _getVol(vars->ivol1, vars->samples, vars->ratem1, vars->ratel1); - vars->ivol2 = _getVol(vars->ivol2, vars->samples, vars->ratem2, vars->ratel2); + vars->em_cvolL = _getVol(vars->em_cvolL, vars->em_delta, vars->em_lratm, vars->em_lratl); + vars->em_cvolR = _getVol(vars->em_cvolR, vars->em_delta, vars->em_rratm, vars->em_rratl); } - if (vars->ivol1 == 0) { - vars->ivol1 = 1; + if (vars->em_cvolL == 0) { + vars->em_cvolL = 1; } - if (vars->ivol2 == 0) { - vars->ivol2 = 1; + if (vars->em_cvolR == 0) { + vars->em_cvolR = 1; } - vars->var8009c39e = vars->var8009c3e4; + vars->em_volume = vars->currentvol; - if (vars->var8009c39c != vars->var8009c3ec) { + if (vars->em_pan != vars->currentpan) { if (var8009c340.headphone) { - vars->var8009c39c = ((s16)(vars->var8009c3ec & 0x7f) >> 1) + 32; + vars->em_pan = ((s16)(vars->currentpan & 0x7f) >> 1) + 32; } else { if (var8009c340.mono) { - vars->var8009c39c = 64; + vars->em_pan = AL_PAN_CENTER; } else { - vars->var8009c39c = vars->var8009c3ec; + vars->em_pan = vars->currentpan; } } - vars->var8009c39c &= (vars->var8009c3ec & 0x80) + 0x7f; + vars->em_pan &= (vars->currentpan & 0x80) + 127; - vars->var8009c3a6 = (vars->var8009c39c & 0x80) ? 1 : 0; + vars->em_wetamt = (vars->em_pan & 0x80) ? 1 : 0; } - vars->samples = 0; - vars->var8009c3bc = SAMPLE184(vars->var8009c3e8); - vars->var8009c3b4 = 1; + vars->em_delta = 0; + vars->em_segEnd = SAMPLE184(vars->var8009c3e8); + vars->em_first = 1; } } -void func00038b90(void *fn) +void mp3_set_dma_func(void *fn) { - g_Mp3Vars.var8009c3dc = fn; + g_Mp3Vars.dmafunc = fn; } -s32 func00038ba8(s32 arg0, u8 *arg1, s32 arg2, s32 arg3) +s32 mp3_handle_dma(s32 arg0, u8 *dst, s32 len, s32 dmaoffset) { - u32 sp1c; + u8 *bufptr; ALDMAproc proc; - if (arg3 != -1) { - g_Mp3Vars.var8009c3c4 = arg3; + if (dmaoffset != -1) { + g_Mp3Vars.dmaoffset = dmaoffset; } - if (g_Mp3Vars.var8009c3c4 + arg2 > g_Mp3Vars.filesize) { - arg2 = g_Mp3Vars.filesize - g_Mp3Vars.var8009c3c4; + if (g_Mp3Vars.dmaoffset + len > g_Mp3Vars.filesize) { + len = g_Mp3Vars.filesize - g_Mp3Vars.dmaoffset; } - proc = n_syn->dma(&sp1c); - sp1c = OS_K0_TO_PHYSICAL(proc(g_Mp3Vars.romaddr + g_Mp3Vars.var8009c3c4, arg2, 0)); + proc = n_syn->dma(&bufptr); + bufptr = (u8 *) OS_K0_TO_PHYSICAL(proc(g_Mp3Vars.romaddr + g_Mp3Vars.dmaoffset, len, NULL)); - bcopy((u8 *)sp1c, arg1, arg2); + bcopy(bufptr, dst, len); - g_Mp3Vars.var8009c3c4 += arg2; + g_Mp3Vars.dmaoffset += len; - return arg2; + return len; } void mp3_dma(void) { - u32 state; + u8 *bufptr; ALDMAproc proc; - proc = n_syn->dma(&state); + proc = n_syn->dma(&bufptr); - proc(g_Mp3Vars.romaddr + g_Mp3Vars.var8009c3c4, 0x400, 0); + proc(g_Mp3Vars.romaddr + g_Mp3Vars.dmaoffset, 0x400, NULL); } diff --git a/src/lib/mp3/decoder.c b/src/lib/mp3/decoder.c index fd8ce4748..17491e4dc 100644 --- a/src/lib/mp3/decoder.c +++ b/src/lib/mp3/decoder.c @@ -1847,14 +1847,14 @@ const f32 var700596bc[] = { 0.99999314546585, }; -const u32 var700596dc[2][15] = { - { 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000 }, - { 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000 }, +const u32 g_BitRateTable[2][15] = { + /* MPEG 2 */ { 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000 }, + /* MPEG 1 */ { 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000 }, }; -const u32 var70059754[2][4] = { - { 22050, 24000, 16000, 22050 }, - { 44100, 48000, 32000, 44100 }, +const u32 g_SampleRateTable[2][4] = { + /* MPEG 2 */ { 22050, 24000, 16000, 22050 }, + /* MPEG 1 */ { 44100, 48000, 32000, 44100 }, }; const u32 var70059774[] = {0xbd03ba34}; @@ -2488,7 +2488,7 @@ bool mp3dec00041600(struct asistream *stream, u32 gr, u32 ch) block_type = stream->block_type[0][ch]; window_switching = stream->window_switching[0][ch]; - if ((stream->unk3bc4 != 1 && stream->unk3bc4 != 3) || ch != 1) { + if ((stream->channelmodeext != 1 && stream->channelmodeext != 3) || ch != 1) { sp48 = 0; if (compress < 400) { @@ -2515,7 +2515,7 @@ bool mp3dec00041600(struct asistream *stream, u32 gr, u32 ch) } } - if (stream->unk3bc4 == 1 || stream->unk3bc4 == 3) { + if (stream->channelmodeext == 1 || stream->channelmodeext == 3) { if (ch == 1) { stream->unk3ef8 = compress % 2; sp38 = compress >> 1; @@ -2822,7 +2822,7 @@ bool mp3dec_set_side_info(struct asistream *stream) stream->unk206c = stream->channelmode == CHANNELMODE_SINGLEMONO ? 9 : 17; } - sp34 = stream->unk04(stream->unk00, &stream->buffer[stream->unk2068], stream->unk206c, -1); + sp34 = stream->dmafunc(stream->unk00, &stream->buffer[stream->unk2068], stream->unk206c, -1); if (stream->unk206c != sp34) { return false; @@ -2834,24 +2834,24 @@ bool mp3dec_set_side_info(struct asistream *stream) stream->numgranules = stream->version != VERSION_2 ? 2 : 1; if (stream->version != VERSION_2) { - stream->main_data_begin = mp3util_get_bits(stream->buffer, &stream->count, 9); + stream->main_data_begin = mp3util_get_bits(stream->buffer, &stream->offset, 9); // skip private bits stream->numchannels == 1 - ? mp3util_get_bits(stream->buffer, &stream->count, 5) - : mp3util_get_bits(stream->buffer, &stream->count, 3); + ? mp3util_get_bits(stream->buffer, &stream->offset, 5) + : mp3util_get_bits(stream->buffer, &stream->offset, 3); } else { - stream->main_data_begin = mp3util_get_bits(stream->buffer, &stream->count, 8); + stream->main_data_begin = mp3util_get_bits(stream->buffer, &stream->offset, 8); stream->numchannels == 1 - ? mp3util_get_bits(stream->buffer, &stream->count, 1) - : mp3util_get_bits(stream->buffer, &stream->count, 2); + ? mp3util_get_bits(stream->buffer, &stream->offset, 1) + : mp3util_get_bits(stream->buffer, &stream->offset, 2); } if (stream->version != VERSION_2) { for (ch = 0; ch < stream->numchannels; ch++) { for (scfsi_band = 0; scfsi_band < 4; scfsi_band++) { - stream->scfsi[ch][scfsi_band] = mp3util_get_bits(stream->buffer, &stream->count, 1); + stream->scfsi[ch][scfsi_band] = mp3util_get_bits(stream->buffer, &stream->offset, 1); } } } @@ -2864,53 +2864,53 @@ bool mp3dec_set_side_info(struct asistream *stream) for (gr = 0; gr < stream->numgranules; gr++) { for (ch = 0; ch < stream->numchannels; ch++) { - stream->part2_3_length[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 12); - stream->big_value[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 9); - stream->global_gain[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 8); - stream->scalefac_compress[gr][ch] = sp28 ? mp3util_get_bits(stream->buffer, &stream->count, sp28) : 0; - stream->window_switching[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 1); + stream->part2_3_length[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 12); + stream->big_value[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 9); + stream->global_gain[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 8); + stream->scalefac_compress[gr][ch] = sp28 ? mp3util_get_bits(stream->buffer, &stream->offset, sp28) : 0; + stream->window_switching[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 1); if (stream->window_switching[gr][ch]) { - stream->block_type[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 2); - stream->mixed_block_flag[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 1); + stream->block_type[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 2); + stream->mixed_block_flag[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 1); for (region = 0; region < 2; region++) { - stream->table_select[gr][ch][region] = mp3util_get_bits(stream->buffer, &stream->count, 5); + stream->table_select[gr][ch][region] = mp3util_get_bits(stream->buffer, &stream->offset, 5); } stream->table_select[gr][ch][2] = 0; for (window = 0; window < 3; window++) { - stream->subblock_gain[gr][ch][window] = mp3util_get_bits(stream->buffer, &stream->count, 3); + stream->subblock_gain[gr][ch][window] = mp3util_get_bits(stream->buffer, &stream->offset, 3); } } else { stream->block_type[gr][ch] = 0; stream->mixed_block_flag[gr][ch] = false; for (region = 0; region < 3; region++) { - stream->table_select[gr][ch][region] = mp3util_get_bits(stream->buffer, &stream->count, 5); + stream->table_select[gr][ch][region] = mp3util_get_bits(stream->buffer, &stream->offset, 5); } - stream->region0_count[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 4); - stream->region1_count[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 3); + stream->region0_count[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 4); + stream->region1_count[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 3); } if (stream->version != VERSION_2) { - stream->preflag[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 1); + stream->preflag[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 1); } - stream->scalefac_scale[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 1); - stream->count1table_select[gr][ch] = mp3util_get_bits(stream->buffer, &stream->count, 1); + stream->scalefac_scale[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 1); + stream->count1table_select[gr][ch] = mp3util_get_bits(stream->buffer, &stream->offset, 1); } } - stream->unk3f7c = var700596dc[stream->version][stream->bitrateindex]; - stream->unk3f80 = var70059754[stream->version][stream->samplerateindex]; + stream->bitrate = g_BitRateTable[stream->version][stream->bitrateindex]; + stream->samplerate = g_SampleRateTable[stream->version][stream->samplerateindex]; if (stream->version != VERSION_2) { - stream->unk3f84 = stream->unk3f7c * 144 / stream->unk3f80; + stream->unk3f84 = stream->bitrate * 144 / stream->samplerate; } else { - stream->unk3f84 = stream->unk3f7c * 72 / stream->unk3f80; + stream->unk3f84 = stream->bitrate * 72 / stream->samplerate; } stream->unk3f88 = (stream->unk3f84 + stream->haspadding) - (stream->unk2068 + stream->unk206c); diff --git a/src/lib/mp3/internal.h b/src/lib/mp3/internal.h index e39769487..94c67957c 100644 --- a/src/lib/mp3/internal.h +++ b/src/lib/mp3/internal.h @@ -11,7 +11,7 @@ s32 mp3main00043dd0(struct asistream *stream); f32 func00045ed0(f32 arg0, f32 arg1); -s32 mp3util_get_bits(u8 *buffer, s32 *count, s32 numbits); +s32 mp3util_get_bits(u8 *buffer, s32 *offset, s32 numbits); s32 mp3util000462f8(u8 *arg0, s32 *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s16 **arg6, u8 **arg7); s32 mp3util000464a8(u8 *arg0, s32 *arg1, s32 arg2, s32 arg3, s32 arg4, s16 **arg5, u8 **arg6); diff --git a/src/lib/mp3/main.c b/src/lib/mp3/main.c index 1552192f2..53e8a7db4 100644 --- a/src/lib/mp3/main.c +++ b/src/lib/mp3/main.c @@ -30,7 +30,7 @@ s32 mp3main00043dd0(struct asistream *stream) stream->unk2020 -= sp1c * 8; } - sp18 = stream->unk04(stream->unk00, &stream->unk1c[stream->unk201c], stream->unk3f88, -1); + sp18 = stream->dmafunc(stream->unk00, &stream->unk1c[stream->unk201c], stream->unk3f88, -1); if (sp18 < stream->unk3f88) { bzero(&stream->unk1c[sp18], stream->unk3f88 - sp18); @@ -42,7 +42,7 @@ s32 mp3main00043dd0(struct asistream *stream) return stream->unk201c - stream->unk3f88; } -bool mp3main00043ef8(struct asistream *stream, s32 arg1) +bool mp3main_read_frame(struct asistream *stream, s32 arg1) { s32 sp24; s32 sp20; @@ -58,7 +58,7 @@ bool mp3main00043ef8(struct asistream *stream, s32 arg1) mask = 0xff; while (true) { - sp1c = stream->unk04(stream->unk00, &stream->buffer[sp20], 1, sp24); + sp1c = stream->dmafunc(stream->unk00, &stream->buffer[sp20], 1, sp24); if (sp1c <= 0) { return false; @@ -82,31 +82,31 @@ bool mp3main00043ef8(struct asistream *stream, s32 arg1) mask = 0xf0; } - sp1c = stream->unk04(stream->unk00, &stream->buffer[2], 2, -1); + sp1c = stream->dmafunc(stream->unk00, &stream->buffer[2], 2, -1); if (sp1c <= 0) { return false; } stream->unk18 += 2; - stream->count = 12; - stream->version = mp3util_get_bits(stream->buffer, &stream->count, 1); - stream->layer = mp3util_get_bits(stream->buffer, &stream->count, 2); - stream->crctype = mp3util_get_bits(stream->buffer, &stream->count, 1); - stream->bitrateindex = mp3util_get_bits(stream->buffer, &stream->count, 4); - stream->samplerateindex = mp3util_get_bits(stream->buffer, &stream->count, 2); - stream->haspadding = mp3util_get_bits(stream->buffer, &stream->count, 1); - stream->privatebit = mp3util_get_bits(stream->buffer, &stream->count, 1); - stream->channelmode = mp3util_get_bits(stream->buffer, &stream->count, 2); + stream->offset = 12; - stream->unk3bc4 = mp3util_get_bits(stream->buffer, &stream->count, 2); - stream->unk3bc8 = mp3util_get_bits(stream->buffer, &stream->count, 1); - stream->unk3bcc = mp3util_get_bits(stream->buffer, &stream->count, 1); - stream->unk3bd0 = mp3util_get_bits(stream->buffer, &stream->count, 2); + stream->version = mp3util_get_bits(stream->buffer, &stream->offset, 1); + stream->layer = mp3util_get_bits(stream->buffer, &stream->offset, 2); + stream->crctype = mp3util_get_bits(stream->buffer, &stream->offset, 1); + stream->bitrateindex = mp3util_get_bits(stream->buffer, &stream->offset, 4); + stream->samplerateindex = mp3util_get_bits(stream->buffer, &stream->offset, 2); + stream->haspadding = mp3util_get_bits(stream->buffer, &stream->offset, 1); + stream->privatebit = mp3util_get_bits(stream->buffer, &stream->offset, 1); + stream->channelmode = mp3util_get_bits(stream->buffer, &stream->offset, 2); + stream->channelmodeext = mp3util_get_bits(stream->buffer, &stream->offset, 2); + stream->copyright = mp3util_get_bits(stream->buffer, &stream->offset, 1); + stream->isoriginal = mp3util_get_bits(stream->buffer, &stream->offset, 1); + stream->emphasis = mp3util_get_bits(stream->buffer, &stream->offset, 2); - if (stream->bitrateindex == 15 || stream->samplerateindex == 3) { - return mp3main00043ef8(stream, -1); + if (stream->bitrateindex == 15 || stream->samplerateindex == 3) { /* bad/reserved values */ + return mp3main_read_frame(stream, -1); } if (!stream->doneinitial) { @@ -117,47 +117,50 @@ bool mp3main00043ef8(struct asistream *stream, s32 arg1) stream->initialcrctype = stream->crctype; stream->initialsamplerateindex = stream->samplerateindex; stream->initialchannelmode = stream->channelmode; - stream->unk3bec = stream->unk3bc8; - stream->unk3bf0 = stream->unk3bcc; + stream->initialcopyright = stream->copyright; + stream->initialisoriginal = stream->isoriginal; } else if (stream->version != stream->initialversion || stream->layer != stream->initiallayer || stream->crctype != stream->initialcrctype || stream->samplerateindex != stream->initialsamplerateindex || stream->channelmode != stream->initialchannelmode - || stream->unk3bcc != stream->unk3bf0) { - return mp3main00043ef8(stream, -1); + || stream->isoriginal != stream->initialisoriginal) { + return mp3main_read_frame(stream, -1); } stream->unk2068 = 4; if (stream->crctype == CRC_PROTECTED) { - sp1c = stream->unk04(stream->unk00, &stream->buffer[4], 2, -1); + sp1c = stream->dmafunc(stream->unk00, &stream->buffer[4], 2, -1); if (sp1c <= 0) { return false; } stream->unk18 += 2; - stream->count += 16; + stream->offset += 16; stream->unk2068 = 6; } if (stream->layer == LAYER_3) { - stream->unk8478 = mp3dec_decode_frame; - stream->unk847c = mp3dec_set_side_info; + stream->decodeframefunc = mp3dec_decode_frame; + stream->setsideinfofunc = mp3dec_set_side_info; } else if (stream->layer == LAYER_2) { return false; } else if (stream->layer == LAYER_1) { return false; } - if (stream->unk847c(stream) == 0) { + if (!stream->setsideinfofunc(stream)) { return false; } return true; } +/** + * System initialisation (ie. called once at boot). + */ u32 mp3main_init(void) { if (var8005f704++) { @@ -168,7 +171,7 @@ u32 mp3main_init(void) return 0; } -struct asistream *mp3main00044460(s32 arg0, void *arg1, s32 arg2) +struct asistream *mp3main_start_file(s32 arg0, void *dmafunc, s32 filesize) { struct asistream *stream = g_AsiStream; @@ -181,14 +184,14 @@ struct asistream *mp3main00044460(s32 arg0, void *arg1, s32 arg2) stream->unk14 = -1; stream->unk00 = arg0; - stream->unk04 = arg1; - stream->unk08 = arg2; + stream->dmafunc = dmafunc; + stream->filesize = filesize; stream->unk201c = 0; stream->unk2020 = 0; stream->unk3ba0 = 0; - mp3main00043ef8(stream, 0); + mp3main_read_frame(stream, 0); stream->unk8474 = 0; @@ -197,31 +200,31 @@ struct asistream *mp3main00044460(s32 arg0, void *arg1, s32 arg2) return stream; } -s32 mp3main0004453c(struct asistream *streamptr, struct mp3thing **arg1, s32 *arg2) +s32 mp3main_continue_file(struct asistream *streamptr, struct mp3thing **arg1, s32 *numchannels) { struct asistream *stream = streamptr; s32 result; stream->unk3ba0++; - if (stream->unk3ba0 > 5) { + if (stream->unk3ba0 >= ARRAYCOUNT(stream->unk2070)) { stream->unk3ba0 = 0; } - if (!mp3main00043ef8(stream, stream->unk8474)) { - g_Mp3Vars.var8009c3e0 = 3; + if (!mp3main_read_frame(stream, stream->unk8474)) { + g_Mp3Vars.state = MP3STATE_STOPPED; return 0; } stream->unk8474 = -1; - result = stream->unk8478(stream); + result = stream->decodeframefunc(stream); if (!result) { // empty } else { *arg1 = &stream->unk2070[stream->unk3ba0]; - *arg2 = stream->numchannels; + *numchannels = stream->numchannels; } return result; diff --git a/src/lib/mp3/mp3.h b/src/lib/mp3/mp3.h index d527429d2..44a73bccc 100644 --- a/src/lib/mp3/mp3.h +++ b/src/lib/mp3/mp3.h @@ -21,8 +21,8 @@ struct asistream_4f64 { struct asistream { /*0x0000*/ s32 unk00; - /*0x0004*/ s32 (*unk04)(s32 arg0, void *arg1, s32 arg2, s32 arg3); - /*0x0008*/ s32 unk08; + /*0x0004*/ s32 (*dmafunc)(s32 arg0, void *arg1, s32 arg2, s32 arg3); + /*0x0008*/ s32 filesize; /*0x000c*/ s32 unk0c; /*0x0010*/ s32 unk10; /*0x0014*/ s32 unk14; @@ -31,7 +31,7 @@ struct asistream { /*0x201c*/ s32 unk201c; /*0x2020*/ s32 unk2020; /*0x2024*/ u8 buffer[0x40]; - /*0x2064*/ s32 count; + /*0x2064*/ s32 offset; /*0x2068*/ u32 unk2068; /*0x206c*/ u32 unk206c; /*0x2070*/ struct mp3thing unk2070[6]; @@ -44,18 +44,18 @@ struct asistream { /*0x3bb8*/ u32 haspadding; /*0x3bbc*/ u32 privatebit; /*0x3bc0*/ u32 channelmode; - /*0x3bc4*/ u32 unk3bc4; - /*0x3bc8*/ u32 unk3bc8; - /*0x3bcc*/ u32 unk3bcc; - /*0x3bd0*/ u32 unk3bd0; + /*0x3bc4*/ u32 channelmodeext; + /*0x3bc8*/ u32 copyright; + /*0x3bcc*/ u32 isoriginal; + /*0x3bd0*/ u32 emphasis; /*0x3bd4*/ bool doneinitial; /*0x3bd8*/ u32 initialversion; /*0x3bdc*/ u32 initiallayer; /*0x3be0*/ u32 initialcrctype; /*0x3be4*/ u32 initialsamplerateindex; /*0x3be8*/ u32 initialchannelmode; - /*0x3bec*/ u32 unk3bec; - /*0x3bf0*/ u32 unk3bf0; + /*0x3bec*/ u32 initialcopyright; + /*0x3bf0*/ u32 initialisoriginal; /*0x3bf4*/ u32 main_data_begin; /*0x3bf8*/ u32 scfsi[1][32]; /*0x3c78*/ u32 part2_3_length[2][1]; @@ -76,8 +76,8 @@ struct asistream { /*0x3ef8*/ u32 unk3ef8; /*0x3efc*/ u32 unk3efc[6]; /*0x3f14*/ u32 unk3f14[26]; - /*0x3f7c*/ s32 unk3f7c; - /*0x3f80*/ s32 unk3f80; + /*0x3f7c*/ s32 bitrate; + /*0x3f80*/ s32 samplerate; /*0x3f84*/ s32 unk3f84; /*0x3f88*/ s32 unk3f88; /*0x3f8c*/ s32 numchannels; @@ -92,12 +92,12 @@ struct asistream { /*0x6a64*/ struct asistream_4f64 unk6a64[2][32]; /*0x7c64*/ u8 unk7c64[0x810]; /*0x8474*/ s32 unk8474; - /*0x8478*/ bool (*unk8478)(struct asistream *stream); - /*0x847c*/ bool (*unk847c)(struct asistream *stream); + /*0x8478*/ bool (*decodeframefunc)(struct asistream *stream); + /*0x847c*/ bool (*setsideinfofunc)(struct asistream *stream); }; u32 mp3main_init(void); -struct asistream *mp3main00044460(s32 arg0, void *arg1, s32 arg2); -s32 mp3main0004453c(struct asistream *stream, struct mp3thing **arg1, s32 *arg2); +struct asistream *mp3main_start_file(s32 arg0, void *arg1, s32 arg2); +s32 mp3main_continue_file(struct asistream *stream, struct mp3thing **arg1, s32 *arg2); #endif diff --git a/src/lib/naudio/n_auxbus.c b/src/lib/naudio/n_auxbus.c index 0b190985f..49d3afe78 100644 --- a/src/lib/naudio/n_auxbus.c +++ b/src/lib/naudio/n_auxbus.c @@ -11,7 +11,7 @@ Acmd *n_alAuxBusPull(s32 sampleOffset, Acmd *cmdptr, s32 fxBus, s32 *numpulls) u32 sp30 = 1; u32 sp2c; - aClearBuffer(cmd++, 1984, 736); + aClearBuffer(cmd++, N_AL_AUX_L_OUT, N_AL_TEMP_2); *numpulls = 0; @@ -36,8 +36,8 @@ Acmd *n_alAuxBusPull(s32 sampleOffset, Acmd *cmdptr, s32 fxBus, s32 *numpulls) sp2c = 65536.0f / sp30; } - n_aNoop(cmd++, 1248, sp2c, sp30); - n_aNoop(cmd++, 1616, sp2c, sp30); + n_aNoop(cmd++, N_AL_MAIN_L_OUT, sp2c, sp30); + n_aNoop(cmd++, N_AL_MAIN_R_OUT, sp2c, sp30); } for (i = 0; i < bus->sourceCount; i++) { diff --git a/src/lib/naudio/n_mainbus.c b/src/lib/naudio/n_mainbus.c index 102c86f7f..9cfff5caf 100644 --- a/src/lib/naudio/n_mainbus.c +++ b/src/lib/naudio/n_mainbus.c @@ -1,7 +1,7 @@ #include #include "n_synthInternals.h" -s32 func00037fc0(s32 arg0, Acmd **cmd); +s32 mp3_make_samples(s32 arg0, Acmd **cmd); void func0003ba64(struct fx *fx, f32 outputrate); Acmd *n_alMainBusPull(s32 sampleOffset, Acmd *p) @@ -9,7 +9,7 @@ Acmd *n_alMainBusPull(s32 sampleOffset, Acmd *p) Acmd *ptr = p; s32 i; - if (!func00037fc0(FIXED_SAMPLE, &ptr)) { + if (!mp3_make_samples(FIXED_SAMPLE, &ptr)) { aClearBuffer(ptr++, N_AL_MAIN_L_OUT, N_AL_DIVIDED << 1); } diff --git a/src/lib/snd.c b/src/lib/snd.c index 3488713c1..4b70521cd 100644 --- a/src/lib/snd.c +++ b/src/lib/snd.c @@ -1556,8 +1556,8 @@ void snd_init(void) osSyncPrintf("RWI : Initialising the new and improved MP3 player\n"); mp3_init(&g_SndHeap); - func00037f08(0x7fff, 1); - func00037f5c(0, true); + mp3_set_vol(AL_VOL_FULL, true); + mp3_set_pan(0, true); osSyncPrintf("RWI : MP3 player Initialising Done\n"); } @@ -1589,14 +1589,14 @@ bool snd_is_mp3(s16 soundnum) return tmp.mp3priority != 0; } -bool snd_stop_mp3(s16 arg0) +bool snd_stop_mp3(s16 soundnum) { if (!g_SndDisabled && g_SndMp3Enabled) { - if (func00037ea4() && g_SndCurMp3.unk08 != 0) { + if (mp3_is_busy() && g_SndCurMp3.unk08 != 0) { return false; } - func00037e1c(); + mp3_stop(); g_SndCurMp3.playing = false; g_SndCurMp3.responsetimer240 = -1; @@ -1710,17 +1710,17 @@ void snd_handle_retrace(void) // empty } -void snd0000fe20(void) +void snd_pause_mp3(void) { if (g_SndMp3Enabled) { - func00037e38(); + mp3_pause(); } } -void snd0000fe50(void) +void snd_unpause_mp3(void) { if (g_SndMp3Enabled) { - func00037e68(); + mp3_unpause(); } } @@ -1818,7 +1818,7 @@ void snd_tick(void) } } - if (func00037ea4() == 0 && g_SndCurMp3.playing) { + if (!mp3_is_busy() && g_SndCurMp3.playing) { if (g_SndCurMp3.unk08) { mp3_play_file(g_SndCurMp3.romaddr, g_SndCurMp3.romsize); return; @@ -2010,11 +2010,11 @@ void snd_adjust(struct sndstate **handle, bool ismp3, s32 vol, s32 pan, s32 soun if (ismp3) { if (vol != -1) { vol = vol * snd_get_sfx_volume() / AL_VOL_FULL; - func00037f08(vol, true); + mp3_set_vol(vol, true); } if (pan != -1) { - func00037f5c(pan, true); + mp3_set_pan(pan, true); } } @@ -2037,7 +2037,7 @@ void snd_adjust(struct sndstate **handle, bool ismp3, s32 vol, s32 pan, s32 soun } } -struct sndstate *snd00010718(struct sndstate **handle, s32 flags, s32 volume, s32 pan, s32 soundnum, f32 pitch, s32 fxbus, s32 fxmixarg, bool forcefxmix) +struct sndstate *snd00010718(struct sndstate **handle, bool ismp3, s32 volume, s32 pan, s32 soundnum, f32 pitch, s32 fxbus, s32 fxmixarg, bool forcefxmix) { OSPri prevpri = osGetThreadPri(NULL); s32 fxmix = -1; @@ -2201,13 +2201,13 @@ void snd_start_mp3(s16 soundnum, s32 volume, s32 pan, s32 responseflags) g_SndCurMp3.romaddr = file_get_rom_address(sp20.id); g_SndCurMp3.romsize = file_get_rom_size(sp20.id); - func00037f08(volume, true); - func00037f5c(pan, true); + mp3_set_vol(volume, true); + mp3_set_pan(pan, true); mp3_play_file(g_SndCurMp3.romaddr, g_SndCurMp3.romsize); - func00037f08(volume, true); - func00037f5c(pan, true); + mp3_set_vol(volume, true); + mp3_set_pan(pan, true); g_SndCurMp3.sfxref.packed = sp20.packed; g_SndCurMp3.playing = true;