X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fsound%2Fsound.c;h=a67ebcca09288d0c54f3964e305061a35dd2b7f5;hb=e42a47e2086e6512519dd86af420363498302f49;hp=8f88dd7c5ca2972deb4b3f730d641f51ab724f55;hpb=4f2cdbf551ad1a7f487b65b4754cbf7983e80b8a;p=picodrive.git diff --git a/pico/sound/sound.c b/pico/sound/sound.c index 8f88dd7..a67ebcc 100644 --- a/pico/sound/sound.c +++ b/pico/sound/sound.c @@ -19,7 +19,7 @@ void (*PsndMix_32_to_16l)(short *dest, int *src, int count) = mix_32_to_16l_ster // master int buffer to mix to static int PsndBuffer[2*(44100+100)/50]; -// dac +// dac, psg static unsigned short dac_info[312+4]; // pos in sample buffer // cdda output buffer @@ -30,7 +30,7 @@ int PsndRate=0; int PsndLen=0; // number of mono samples, multiply by 2 for stereo int PsndLen_exc_add=0; // this is for non-integer sample counts per line, eg. 22050/60 int PsndLen_exc_cnt=0; -int PsndDacLine=0; +int PsndDacLine, PsndPsgLine; short *PsndOut=NULL; // PCM data buffer static int PsndLen_use; @@ -44,7 +44,7 @@ extern int *sn76496_regs; static void dac_recalculate(void) { - int i, dac_cnt, pos, len, lines = Pico.m.pal ? 312 : 262, mid = Pico.m.pal ? 68 : 93; + int i, dac_cnt, pos, len, lines = Pico.m.pal ? 313 : 262, mid = Pico.m.pal ? 68 : 93; if (PsndLen <= lines) { @@ -158,7 +158,7 @@ PICO_INTERNAL void PsndStartFrame(void) PsndLen_use++; } - PsndDacLine = 0; + PsndDacLine = PsndPsgLine = 0; emustatus &= ~1; dac_info[224] = PsndLen_use; } @@ -169,8 +169,8 @@ PICO_INTERNAL void PsndDoDAC(int line_to) int dout = ym2612.dacout; int line_from = PsndDacLine; - if (line_to >= 312) - line_to = 311; + if (line_to >= 313) + line_to = 312; pos = dac_info[line_from]; pos1 = dac_info[line_to + 1]; @@ -185,13 +185,42 @@ PICO_INTERNAL void PsndDoDAC(int line_to) if (PicoOpt & POPT_EN_STEREO) { short *d = PsndOut + pos*2; - for (; len > 0; len--, d+=2) *d = dout; + for (; len > 0; len--, d+=2) *d += dout; } else { short *d = PsndOut + pos; - for (; len > 0; len--, d++) *d = dout; + for (; len > 0; len--, d++) *d += dout; } } +PICO_INTERNAL void PsndDoPSG(int line_to) +{ + int line_from = PsndPsgLine; + int pos, pos1, len; + int stereo = 0; + + if (line_to >= 313) + line_to = 312; + + pos = dac_info[line_from]; + pos1 = dac_info[line_to + 1]; + len = pos1 - pos; + //elprintf(EL_STATUS, "%3d %3d %3d %3d %3d", + // pos, pos1, len, line_from, line_to); + if (len <= 0) + return; + + PsndPsgLine = line_to + 1; + + if (!PsndOut || !(PicoOpt & POPT_EN_PSG)) + return; + + if (PicoOpt & POPT_EN_STEREO) { + stereo = 1; + pos <<= 1; + } + SN76496Update(PsndOut + pos, len, stereo); +} + // cdda static void cdda_raw_update(int *buffer, int length) { @@ -264,10 +293,6 @@ static int PsndRender(int offset, int length) pprof_start(sound); - // PSG - if (PicoOpt & POPT_EN_PSG) - SN76496Update(PsndOut+offset, length, stereo); - if (PicoAHW & PAHW_PICO) { PicoPicoPCMUpdate(PsndOut+offset, length, stereo); return length; @@ -319,6 +344,7 @@ PICO_INTERNAL void PsndGetSamples(int y) if (ym2612.dacen && PsndDacLine < y) PsndDoDAC(y - 1); + PsndDoPSG(y - 1); if (y == 224) {