From: kub Date: Mon, 30 Mar 2020 21:54:11 +0000 (+0200) Subject: fix for gp2x audio regression X-Git-Tag: v2.00~758 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84e18560bba7ada8ccb2f3201c36ae68b01ec1fc;p=picodrive.git fix for gp2x audio regression --- diff --git a/pico/memory.c b/pico/memory.c index d61491c1..0fa7b8de 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -1057,11 +1057,11 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80) break; } - PsndDoFM(get_scanline(is_from_z80)); #ifdef __GP2X__ if (PicoIn.opt & POPT_EXT_FM) return YM2612Write_940(a, d, get_scanline(is_from_z80)); #endif + PsndDoFM(get_scanline(is_from_z80)); return YM2612Write_(a, d); } diff --git a/pico/sound/sound.c b/pico/sound/sound.c index 155aa452..57d9c2e5 100644 --- a/pico/sound/sound.c +++ b/pico/sound/sound.c @@ -193,8 +193,8 @@ PICO_INTERNAL void PsndDoFM(int line_to) // Q16, number of samples since last call len = ((line_to-1) * Pico.snd.fm_mult) - Pico.snd.fm_pos; - // don't do this too often (no more than 256 per sec) - if (len >> 16 <= PicoIn.sndRate >> 9) + // don't do this too often (about every 4th scanline) + if (len >> 16 <= PicoIn.sndRate >> 12) return; // update position and calculate buffer offset and length @@ -281,22 +281,22 @@ static int PsndRender(int offset, int length) { int *buf32; int stereo = (PicoIn.opt & 8) >> 3; - int fmlen = ((Pico.snd.fm_pos+0x8000) >> 16) - offset; - int daclen = ((Pico.snd.dac_pos+0x80000) >> 20) - offset; + int fmlen = ((Pico.snd.fm_pos+0x8000) >> 16); + int daclen = ((Pico.snd.dac_pos+0x80000) >> 20); - offset <<= stereo; - buf32 = PsndBuffer+offset; + buf32 = PsndBuffer+(offset< 0) { short *dacbuf = PicoIn.sndOut + (daclen << stereo); + Pico.snd.dac_pos += (length-daclen) << 20; for (; length-daclen > 0; daclen++) { *dacbuf++ += Pico.snd.dac_val; if (stereo) dacbuf++; @@ -305,14 +305,15 @@ static int PsndRender(int offset, int length) // Add in parts of the FM buffer not yet done if (length-fmlen > 0) { - int *fmbuf = buf32 + (fmlen << stereo); + int *fmbuf = buf32 + ((fmlen-offset) << stereo); + Pico.snd.fm_pos += (length-fmlen) << 16; if (PicoIn.opt & POPT_EN_FM) YM2612UpdateOne(fmbuf, length-fmlen, stereo, 1); } // CD: PCM sound if (PicoIn.AHW & PAHW_MCD) { - pcd_pcm_update(buf32, length, stereo); + pcd_pcm_update(buf32, length-offset, stereo); } // CD: CDDA audio @@ -323,16 +324,16 @@ static int PsndRender(int offset, int length) { // note: only 44, 22 and 11 kHz supported, with forced stereo if (Pico_mcd->cdda_type == CT_MP3) - mp3_update(buf32, length, stereo); + mp3_update(buf32, length-offset, stereo); else - cdda_raw_update(buf32, length); + cdda_raw_update(buf32, length-offset); } if ((PicoIn.AHW & PAHW_32X) && (PicoIn.opt & POPT_EN_PWM)) - p32x_pwm_update(buf32, length, stereo); + p32x_pwm_update(buf32, length-offset, stereo); // convert + limit to normal 16bit output - PsndMix_32_to_16l(PicoIn.sndOut+offset, buf32, length); + PsndMix_32_to_16l(PicoIn.sndOut+(offset<writebuffsel ? shared_ctl->writebuff0 : shared_ctl->writebuff1; /* detect rapid ym updates */ - if (upd && !(writebuff_ptr & 0x80000000) && scanline < 224) + if (upd && !(writebuff_ptr & 0x80000000)) { - int mid = Pico.m.pal ? 68 : 93; - if (scanline > mid) { + int mid = (Pico.m.pal ? 313 : 262) / 2; + if (scanline >= mid) { //printf("%05i:%03i: rapid ym\n", Pico.m.frame_count, scanline); writebuff[writebuff_ptr++ & 0xffff] = 0xfffe; writebuff_ptr |= 0x80000000;