X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fsound%2Fsound.c;h=e799e93686cb01aea53206f83a06f6e079e50160;hb=075672bf9f028490174bd3fbebe957a47a10b09d;hp=8f88dd7c5ca2972deb4b3f730d641f51ab724f55;hpb=4f2cdbf551ad1a7f487b65b4754cbf7983e80b8a;p=picodrive.git diff --git a/pico/sound/sound.c b/pico/sound/sound.c index 8f88dd7..e799e93 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) { @@ -141,9 +141,9 @@ void PsndRerate(int preserve_state) PsndClear(); // set mixer - PsndMix_32_to_16l = (PicoOpt & POPT_EN_STEREO) ? mix_32_to_16l_stereo : mix_32_to_16_mono; + PsndMix_32_to_16l = (PicoIn.opt & POPT_EN_STEREO) ? mix_32_to_16l_stereo : mix_32_to_16_mono; - if (PicoAHW & PAHW_PICO) + if (PicoIn.AHW & PAHW_PICO) PicoReratePico(); } @@ -158,8 +158,8 @@ PICO_INTERNAL void PsndStartFrame(void) PsndLen_use++; } - PsndDacLine = 0; - emustatus &= ~1; + PsndDacLine = PsndPsgLine = 0; + Pico.m.status &= ~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]; @@ -183,15 +183,44 @@ PICO_INTERNAL void PsndDoDAC(int line_to) if (!PsndOut) return; - if (PicoOpt & POPT_EN_STEREO) { + if (PicoIn.opt & 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 || !(PicoIn.opt & POPT_EN_PSG)) + return; + + if (PicoIn.opt & POPT_EN_STEREO) { + stereo = 1; + pos <<= 1; + } + SN76496Update(PsndOut + pos, len, stereo); +} + // cdda static void cdda_raw_update(int *buffer, int length) { @@ -243,7 +272,7 @@ PICO_INTERNAL void PsndClear(void) { int len = PsndLen; if (PsndLen_exc_add) len++; - if (PicoOpt & POPT_EN_STEREO) + if (PicoIn.opt & POPT_EN_STEREO) memset32((int *) PsndOut, 0, len); // assume PsndOut to be aligned else { short *out = PsndOut; @@ -258,23 +287,19 @@ static int PsndRender(int offset, int length) { int buf32_updated = 0; int *buf32 = PsndBuffer+offset; - int stereo = (PicoOpt & 8) >> 3; + int stereo = (PicoIn.opt & 8) >> 3; offset <<= stereo; pprof_start(sound); - // PSG - if (PicoOpt & POPT_EN_PSG) - SN76496Update(PsndOut+offset, length, stereo); - - if (PicoAHW & PAHW_PICO) { + if (PicoIn.AHW & PAHW_PICO) { PicoPicoPCMUpdate(PsndOut+offset, length, stereo); return length; } // Add in the stereo FM buffer - if (PicoOpt & POPT_EN_FM) { + if (PicoIn.opt & POPT_EN_FM) { buf32_updated = YM2612UpdateOne(buf32, length, stereo, 1); } else memset32(buf32, 0, length<cdda_stream != NULL && !(Pico_mcd->s68k_regs[0x36] & 1)) { @@ -301,7 +326,7 @@ static int PsndRender(int offset, int length) cdda_raw_update(buf32, length); } - if ((PicoAHW & PAHW_32X) && (PicoOpt & POPT_EN_PWM)) + if ((PicoIn.AHW & PAHW_32X) && (PicoIn.opt & POPT_EN_PWM)) p32x_pwm_update(buf32, length, stereo); // convert + limit to normal 16bit output @@ -319,48 +344,48 @@ PICO_INTERNAL void PsndGetSamples(int y) if (ym2612.dacen && PsndDacLine < y) PsndDoDAC(y - 1); + PsndDoPSG(y - 1); if (y == 224) { - if (emustatus & 2) + if (Pico.m.status & 2) curr_pos += PsndRender(curr_pos, PsndLen-PsndLen/2); else curr_pos = PsndRender(0, PsndLen_use); - if (emustatus & 1) - emustatus |= 2; - else emustatus &= ~2; + if (Pico.m.status & 1) + Pico.m.status |= 2; + else Pico.m.status &= ~2; if (PicoWriteSound) - PicoWriteSound(curr_pos * ((PicoOpt & POPT_EN_STEREO) ? 4 : 2)); + PicoWriteSound(curr_pos * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2)); // clear sound buffer PsndClear(); PsndDacLine = 224; dac_info[224] = 0; } - else if (emustatus & 3) { - emustatus|= 2; - emustatus&=~1; + else if (Pico.m.status & 3) { + Pico.m.status |= 2; + Pico.m.status &= ~1; curr_pos = PsndRender(0, PsndLen/2); } } PICO_INTERNAL void PsndGetSamplesMS(void) { - int stereo = (PicoOpt & 8) >> 3; int length = PsndLen_use; - // PSG - if (PicoOpt & POPT_EN_PSG) - SN76496Update(PsndOut, length, stereo); + PsndDoPSG(223); // upmix to "stereo" if needed - if (stereo) { + if (PicoIn.opt & POPT_EN_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)); + PicoWriteSound(length * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2)); PsndClear(); + + dac_info[224] = 0; } // vim:shiftwidth=2:ts=2:expandtab