X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fsound%2Fsound.c;h=ac37c614c769b8adec3dac8639067a86d0dee8de;hb=f02439758ee681130093e689d4d8a4b377ca462f;hp=7d418604d3544497cdaaa393ae73f15ae82d930b;hpb=69996cb7c62468cd97842e35bdd2b74006a28dba;p=picodrive.git diff --git a/Pico/sound/sound.c b/Pico/sound/sound.c index 7d41860..ac37c61 100644 --- a/Pico/sound/sound.c +++ b/Pico/sound/sound.c @@ -117,7 +117,7 @@ PICO_INTERNAL void sound_reset(void) // to be called after changing sound rate or chips void sound_rerate(int preserve_state) { - unsigned int state[28]; + void *state = NULL; int target_fps = Pico.m.pal ? 50 : 60; // not all rates are supported in MCD mode due to mp3 decoder limitations @@ -127,12 +127,16 @@ void sound_rerate(int preserve_state) } if (preserve_state) { + state = malloc(0x200); + if (state == NULL) return; + memcpy(state, YM2612GetRegs(), 0x200); if ((PicoMCD & 1) && Pico_mcd->m.audio_track) Pico_mcd->m.audio_offset = mp3_get_offset(); } YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PsndRate); if (preserve_state) { // feed it back it's own registers, just like after loading state + memcpy(YM2612GetRegs(), state, 0x200); YM2612PicoStateLoad(); if ((PicoMCD & 1) && Pico_mcd->m.audio_track) mp3_start_play(Pico_mcd->TOC.Tracks[Pico_mcd->m.audio_track].F, Pico_mcd->m.audio_offset); @@ -142,6 +146,9 @@ void sound_rerate(int preserve_state) SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PsndRate); if (preserve_state) memcpy(sn76496_regs, state, 28*4); // restore old state + if (state) + free(state); + // calculate PsndLen PsndLen=PsndRate / target_fps; PsndLen_exc_add=((PsndRate - PsndLen*target_fps)<<16) / target_fps;