X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fsound%2Fsound.c;h=69c1be0397b7ea2527f44d0f92487cbb30469016;hb=274fcc35aa20e9777a8e09630a94088757384329;hp=7f3fd8dfb58e35c2d886ec838735a301a94f2eb9;hpb=2ec9bec58b89831cdead4cdec8f593c5b99d2715;p=picodrive.git diff --git a/pico/sound/sound.c b/pico/sound/sound.c index 7f3fd8d..69c1be0 100644 --- a/pico/sound/sound.c +++ b/pico/sound/sound.c @@ -1,19 +1,21 @@ -// This is part of Pico Library - -// (c) Copyright 2004 Dave, All rights reserved. -// (c) Copyright 2006,2007 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. - +/* + * PicoDrive + * (c) Copyright Dave, 2004 + * (C) notaz, 2006-2009 + * + * This work is licensed under the terms of MAME license. + * See COPYING file in the top-level directory. + */ #include #include "ym2612.h" #include "sn76496.h" #include "../pico_int.h" -#include "../cd/pcm.h" +#include "../cd/cue.h" #include "mix.h" +#define SIMPLE_WRITE_SOUND 0 + void (*PsndMix_32_to_16l)(short *dest, int *src, int count) = mix_32_to_16l_stereo; // master int buffer to mix to @@ -107,14 +109,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(); } @@ -124,15 +121,6 @@ void PsndRerate(int preserve_state) void *state = NULL; int target_fps = Pico.m.pal ? 50 : 60; - // not all rates are supported in MCD mode due to mp3 decoder limitations - if (PicoAHW & PAHW_MCD) { - if (!(11025-100 <= PsndRate && PsndRate <= 11025+100) && - !(22050-100 <= PsndRate && PsndRate <= 22050+100) && - !(44100-100 <= PsndRate && PsndRate <= 44100+100)) - PsndRate = 22050; - PicoOpt |= POPT_EN_STEREO; // force stereo - } - if (preserve_state) { state = malloc(0x204); if (state == NULL) return; @@ -144,8 +132,6 @@ void PsndRerate(int preserve_state) // feed it back it's own registers, just like after loading state memcpy(YM2612GetRegs(), state, 0x204); ym2612_unpack_state(); - if ((PicoAHW & PAHW_MCD) && !(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1)) - cdda_start_play(); } if (preserve_state) memcpy(state, sn76496_regs, 28*4); // remember old state @@ -163,9 +149,6 @@ void PsndRerate(int preserve_state) // recalculate dac info dac_recalculate(); - if (PicoAHW & PAHW_MCD) - pcm_set_rate(PsndRate); - // clear all buffers memset32(PsndBuffer, 0, sizeof(PsndBuffer)/4); memset(cdda_out_buffer, 0, sizeof(cdda_out_buffer)); @@ -186,6 +169,9 @@ PICO_INTERNAL void PsndDoDAC(int line_to) int dout = ym2612.dacout; int line_from = PsndDacLine; + if (line_to >= 312) + line_to = 311; + PsndDacLine = line_to + 1; pos =dac_info[line_from]>>4; @@ -200,34 +186,22 @@ PICO_INTERNAL void PsndDoDAC(int line_to) short *d = PsndOut + pos; for (; len > 0; len--, d++) *d = dout; } - -#if 0 - if (do_pcm) { - int *d = PsndBuffer; - d += (PicoOpt&8) ? pos*2 : pos; - pcm_update(d, len, 1); - } -#endif } // cdda -static pm_file *cdda_stream = NULL; - static void cdda_raw_update(int *buffer, int length) { int ret, cdda_bytes, mult = 1; - if (cdda_stream == NULL) - return; cdda_bytes = length*4; if (PsndRate <= 22050 + 100) mult = 2; if (PsndRate < 22050 - 100) mult = 4; cdda_bytes *= mult; - ret = pm_read(cdda_out_buffer, cdda_bytes, cdda_stream); + ret = pm_read(cdda_out_buffer, cdda_bytes, Pico_mcd->cdda_stream); if (ret < cdda_bytes) { memset((char *)cdda_out_buffer + ret, 0, cdda_bytes - ret); - cdda_stream = NULL; + Pico_mcd->cdda_stream = NULL; return; } @@ -239,51 +213,24 @@ static void cdda_raw_update(int *buffer, int length) } } -PICO_INTERNAL void cdda_start_play(void) +void cdda_start_play(int lba_base, int lba_offset, int lb_len) { - int lba_offset, index, lba_length, i; - - elprintf(EL_STATUS, "cdda play track #%i", Pico_mcd->scd.Cur_Track); - - index = Pico_mcd->scd.Cur_Track - 1; - - lba_offset = Pico_mcd->scd.Cur_LBA - Track_to_LBA(index + 1); - if (lba_offset < 0) lba_offset = 0; - lba_offset += Pico_mcd->TOC.Tracks[index].Offset; - - // find the actual file for this track - for (i = index; i >= 0; i--) - if (Pico_mcd->TOC.Tracks[i].F != NULL) break; - - if (Pico_mcd->TOC.Tracks[i].F == NULL) { - elprintf(EL_STATUS|EL_ANOMALY, "no track?!"); - return; - } - - if (Pico_mcd->TOC.Tracks[i].ftype == TYPE_MP3) + if (Pico_mcd->cdda_type == CT_MP3) { int pos1024 = 0; - lba_length = Pico_mcd->TOC.Tracks[i].Length; - for (i++; i < Pico_mcd->TOC.Last_Track; i++) { - if (Pico_mcd->TOC.Tracks[i].F != NULL) break; - lba_length += Pico_mcd->TOC.Tracks[i].Length; - } - if (lba_offset) - pos1024 = lba_offset * 1024 / lba_length; + pos1024 = lba_offset * 1024 / lb_len; - mp3_start_play(Pico_mcd->TOC.Tracks[index].F, pos1024); + mp3_start_play(Pico_mcd->cdda_stream, pos1024); return; } - cdda_stream = Pico_mcd->TOC.Tracks[i].F; - PicoCDBufferFlush(); // buffering relies on fp not being touched - pm_seek(cdda_stream, lba_offset * 2352, SEEK_SET); - if (Pico_mcd->TOC.Tracks[i].ftype == TYPE_WAV) + pm_seek(Pico_mcd->cdda_stream, (lba_base + lba_offset) * 2352, SEEK_SET); + if (Pico_mcd->cdda_type == CT_WAV) { // skip headers, assume it's 44kHz stereo uncompressed - pm_seek(cdda_stream, 44, SEEK_CUR); + pm_seek(Pico_mcd->cdda_stream, 44, SEEK_CUR); } } @@ -296,7 +243,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; } @@ -308,11 +255,11 @@ static int PsndRender(int offset, int length) int buf32_updated = 0; int *buf32 = PsndBuffer+offset; int stereo = (PicoOpt & 8) >> 3; - // emulating CD && PCM option enabled && PCM chip on && have enabled channels - int do_pcm = (PicoAHW & PAHW_MCD) && (PicoOpt&POPT_EN_MCD_PCM) && - (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,30 +287,35 @@ static int PsndRender(int offset, int length) memset32(buf32, 0, length<s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1)) + if ((PicoAHW & PAHW_MCD) && (PicoOpt & POPT_EN_MCD_CDDA) + && Pico_mcd->cdda_stream != NULL + && !(Pico_mcd->s68k_regs[0x36] & 1)) { // note: only 44, 22 and 11 kHz supported, with forced stereo - int index = Pico_mcd->scd.Cur_Track - 1; - - if (Pico_mcd->TOC.Tracks[index].ftype == TYPE_MP3) + if (Pico_mcd->cdda_type == CT_MP3) mp3_update(buf32, length, stereo); else cdda_raw_update(buf32, length); } + if ((PicoAHW & PAHW_32X) && (PicoOpt & POPT_EN_PWM)) + p32x_pwm_update(buf32, length, stereo); + // convert + limit to normal 16bit output PsndMix_32_to_16l(PsndOut+offset, buf32, length); + pprof_end(sound); + return length; } @@ -373,7 +325,8 @@ PICO_INTERNAL void PsndGetSamples(int y) #if SIMPLE_WRITE_SOUND if (y != 224) return; PsndRender(0, PsndLen); - if (PicoWriteSound) PicoWriteSound(PsndLen); + if (PicoWriteSound) + PicoWriteSound(PsndLen * ((PicoOpt & POPT_EN_STEREO) ? 4 : 2)); PsndClear(); #else static int curr_pos = 0; @@ -383,8 +336,11 @@ PICO_INTERNAL void PsndGetSamples(int y) if (emustatus & 2) curr_pos += PsndRender(curr_pos, PsndLen-PsndLen/2); else curr_pos = PsndRender(0, PsndLen); - if (emustatus&1) emustatus|=2; else emustatus&=~2; - if (PicoWriteSound) PicoWriteSound(curr_pos); + if (emustatus & 1) + emustatus |= 2; + else emustatus &= ~2; + if (PicoWriteSound) + PicoWriteSound(curr_pos * ((PicoOpt & POPT_EN_STEREO) ? 4 : 2)); // clear sound buffer PsndClear(); } @@ -398,7 +354,6 @@ PICO_INTERNAL void PsndGetSamples(int y) PICO_INTERNAL void PsndGetSamplesMS(void) { - int *buf32 = PsndBuffer; int stereo = (PicoOpt & 8) >> 3; int length = PsndLen; @@ -415,11 +370,15 @@ PICO_INTERNAL void PsndGetSamplesMS(void) if (PicoOpt & POPT_EN_PSG) SN76496Update(PsndOut, length, stereo); - // convert + limit to normal 16bit output - PsndMix_32_to_16l(PsndOut, buf32, length); + // 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); + PicoWriteSound(length * ((PicoOpt & POPT_EN_STEREO) ? 4 : 2)); PsndClear(); }