ソースを参照

fix for gp2x audio regression

kub 4 年 前
コミット
84e18560bb
3 ファイル変更18 行追加17 行削除
  1. 1 1
      pico/memory.c
  2. 14 13
      pico/sound/sound.c
  3. 3 3
      platform/gp2x/940ctl.c

+ 1 - 1
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);
 }
 

+ 14 - 13
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<<stereo);
 
   pprof_start(sound);
 
   if (PicoIn.AHW & PAHW_PICO) {
-    PicoPicoPCMUpdate(PicoIn.sndOut+offset, length, stereo);
+    PicoPicoPCMUpdate(PicoIn.sndOut+(offset<<stereo), length-offset, stereo);
     return length;
   }
 
   // Fill up DAC output in case of missing samples (Q16 rounding errors)
   if (length-daclen > 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<<stereo), buf32, length-offset);
 
   pprof_end(sound);
 

+ 3 - 3
platform/gp2x/940ctl.c

@@ -100,10 +100,10 @@ int YM2612Write_940(unsigned int a, unsigned int v, int scanline)
 		UINT16 *writebuff = shared_ctl->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;