X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fsound%2Fsound.c;h=48ad40953c008124878664ef54a9497e91314ae4;hb=e743be2070a13d14cae39a55b815b62b0edb6776;hp=e1e0408c79a17d1b4d2b7229be2d4b50a3fa80eb;hpb=c8d1e9b66255c00a3bef7ca27ae019e3523d7a4b;p=picodrive.git diff --git a/pico/sound/sound.c b/pico/sound/sound.c index e1e0408..48ad409 100644 --- a/pico/sound/sound.c +++ b/pico/sound/sound.c @@ -107,14 +107,9 @@ static void dac_recalculate(void) PICO_INTERNAL void PsndReset(void) { - void *ym2612_regs; - - // also clear the internal registers+addr line - ym2612_regs = YM2612GetRegs(); - memset(ym2612_regs, 0, 0x200+4); - timers_reset(); - + // PsndRerate calls YM2612Init, which also resets PsndRerate(0); + timers_reset(); } @@ -252,7 +247,7 @@ PICO_INTERNAL void cdda_start_play(void) lba_offset += Pico_mcd->TOC.Tracks[index].Offset; // find the actual file for this track - for (i = index; i >= 0; i--) + for (i = index; i > 0; i--) if (Pico_mcd->TOC.Tracks[i].F != NULL) break; if (Pico_mcd->TOC.Tracks[i].F == NULL) { @@ -296,7 +291,7 @@ PICO_INTERNAL void PsndClear(void) memset32((int *) PsndOut, 0, len); // assume PsndOut to be aligned else { short *out = PsndOut; - if ((int)out & 2) { *out++ = 0; len--; } + if ((long)out & 2) { *out++ = 0; len--; } memset32((int *) out, 0, len/2); if (len & 1) out[len-1] = 0; } @@ -313,6 +308,8 @@ static int PsndRender(int offset, int length) (Pico_mcd->pcm.control & 0x80) && Pico_mcd->pcm.enabled; offset <<= stereo; + pprof_start(sound); + #if !SIMPLE_WRITE_SOUND if (offset == 0) { // should happen once per frame // compensate for float part of PsndLen @@ -340,6 +337,7 @@ static int PsndRender(int offset, int length) memset32(buf32, 0, length<> 3; + int length = PsndLen; + +#if !SIMPLE_WRITE_SOUND + // compensate for float part of PsndLen + PsndLen_exc_cnt += PsndLen_exc_add; + if (PsndLen_exc_cnt >= 0x10000) { + PsndLen_exc_cnt -= 0x10000; + length++; + } +#endif + + // PSG + if (PicoOpt & POPT_EN_PSG) + SN76496Update(PsndOut, length, stereo); + + // upmix to "stereo" if needed + if (stereo) { + int i, *p; + for (i = length, p = (void *)PsndOut; i > 0; i--, p++) + *p |= *p << 16; + } + + if (PicoWriteSound != NULL) + PicoWriteSound(length * ((PicoOpt & POPT_EN_STEREO) ? 4 : 2)); + PsndClear(); +} +