static int PsndBuffer[2*44100/50];\r
\r
// dac\r
-static unsigned short dac_info[312]; // pppppppp ppppllll, p - pos in buff, l - length to write for this sample\r
+static unsigned short dac_info[312+4]; // pppppppp ppppllll, p - pos in buff, l - length to write for this sample\r
+\r
+// cdda output buffer\r
+short cdda_out_buffer[2*1152];\r
\r
// for Pico\r
int PsndRate=0;\r
int PsndLen=0; // number of mono samples, multiply by 2 for stereo\r
int PsndLen_exc_add=0; // this is for non-integer sample counts per line, eg. 22050/60\r
int PsndLen_exc_cnt=0;\r
+int PsndDacLine=0;\r
short *PsndOut=NULL; // PCM data buffer\r
\r
+// timers\r
+int timer_a_next_oflow, timer_a_step, timer_a_offset; // in z80 cycles\r
+int timer_b_next_oflow, timer_b_step, timer_b_offset;\r
+\r
// sn76496\r
extern int *sn76496_regs;\r
\r
{\r
int i, dac_cnt, pos, len, lines = Pico.m.pal ? 312 : 262, mid = Pico.m.pal ? 68 : 93;\r
\r
- if(PsndLen <= lines) {\r
+ if (PsndLen <= lines)\r
+ {\r
// shrinking algo\r
dac_cnt = -PsndLen;\r
len=1; pos=0;\r
dac_info[225] = 1;\r
\r
- for(i=226; i != 225; i++) {\r
+ for(i=226; i != 225; i++)\r
+ {\r
if (i >= lines) i = 0;\r
len = 0;\r
if(dac_cnt < 0) {\r
dac_cnt -= PsndLen;\r
dac_info[i] = (pos<<4)|len;\r
}\r
- } else {\r
+ }\r
+ else\r
+ {\r
// stretching\r
dac_cnt = PsndLen;\r
pos=0;\r
- for(i = 225; i != 224; i++) {\r
+ for(i = 225; i != 224; i++)\r
+ {\r
if (i >= lines) i = 0;\r
len=0;\r
while(dac_cnt >= 0) {\r
if (PsndLen_exc_add) len++;\r
dac_info[224] = (pos<<4)|len;\r
}\r
+ for (i = lines; i < sizeof(dac_info) / sizeof(dac_info[0]); i++)\r
+ dac_info[i] = 0;\r
//for(i=len=0; i < lines; i++) {\r
// printf("%03i : %03i : %i\n", i, dac_info[i]>>4, dac_info[i]&0xf);\r
// len+=dac_info[i]&0xf;\r
// also clear the internal registers+addr line\r
ym2612_regs = YM2612GetRegs();\r
memset(ym2612_regs, 0, 0x200+4);\r
- z80startCycle = z80stopCycle = 0;\r
+ timers_reset();\r
\r
PsndRerate(0);\r
}\r
int target_fps = Pico.m.pal ? 50 : 60;\r
\r
// not all rates are supported in MCD mode due to mp3 decoder limitations\r
- if (PicoMCD & 1) {\r
+ if (PicoAHW & PAHW_MCD) {\r
if (PsndRate != 11025 && PsndRate != 22050 && PsndRate != 44100) PsndRate = 22050;\r
- PicoOpt |= 8; // force stereo\r
+ PicoOpt |= POPT_EN_STEREO; // force stereo\r
}\r
\r
if (preserve_state) {\r
state = malloc(0x200);\r
if (state == NULL) return;\r
memcpy(state, YM2612GetRegs(), 0x200);\r
- if ((PicoMCD & 1) && Pico_mcd->m.audio_track)\r
- Pico_mcd->m.audio_offset = mp3_get_offset();\r
}\r
YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PsndRate);\r
if (preserve_state) {\r
// feed it back it's own registers, just like after loading state\r
memcpy(YM2612GetRegs(), state, 0x200);\r
YM2612PicoStateLoad();\r
- if ((PicoMCD & 1) && Pico_mcd->m.audio_track)\r
- mp3_start_play(Pico_mcd->TOC.Tracks[Pico_mcd->m.audio_track].F, Pico_mcd->m.audio_offset);\r
+ if ((PicoAHW & PAHW_MCD) && !(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1))\r
+ cdda_start_play();\r
}\r
\r
if (preserve_state) memcpy(state, sn76496_regs, 28*4); // remember old state\r
// recalculate dac info\r
dac_recalculate();\r
\r
- if (PicoMCD & 1)\r
+ if (PicoAHW & PAHW_MCD)\r
pcm_set_rate(PsndRate);\r
\r
// clear all buffers\r
memset32(PsndBuffer, 0, sizeof(PsndBuffer)/4);\r
+ memset(cdda_out_buffer, 0, sizeof(cdda_out_buffer));\r
if (PsndOut)\r
PsndClear();\r
\r
// set mixer\r
- PsndMix_32_to_16l = (PicoOpt & 8) ? mix_32_to_16l_stereo : mix_32_to_16_mono;\r
+ PsndMix_32_to_16l = (PicoOpt & POPT_EN_STEREO) ? mix_32_to_16l_stereo : mix_32_to_16_mono;\r
+\r
+ if (PicoAHW & PAHW_PICO)\r
+ PicoReratePico();\r
}\r
\r
\r
-// This is called once per raster (aka line), but not necessarily for every line\r
-PICO_INTERNAL void Psnd_timers_and_dac(int raster)\r
+PICO_INTERNAL void PsndDoDAC(int line_to)\r
{\r
- int pos, len;\r
- int do_dac = PsndOut && (PicoOpt&1) && *ym2612_dacen;\r
-// int do_pcm = PsndOut && (PicoMCD&1) && (PicoOpt&0x400);\r
+ int pos, pos1, len;\r
+ int dout = ym2612.dacout;\r
+ int line_from = PsndDacLine;\r
\r
- // Our raster lasts 63.61323/64.102564 microseconds (NTSC/PAL)\r
- YM2612PicoTick(1);\r
+ PsndDacLine = line_to + 1;\r
\r
- if (!do_dac /*&& !do_pcm*/) return;\r
-\r
- pos=dac_info[raster], len=pos&0xf;\r
+ pos =dac_info[line_from]>>4;\r
+ pos1=dac_info[line_to];\r
+ len = ((pos1>>4)-pos) + (pos1&0xf);\r
if (!len) return;\r
\r
- pos>>=4;\r
-\r
- if (do_dac) {\r
+ if (PicoOpt & POPT_EN_STEREO) {\r
short *d = PsndOut + pos*2;\r
- int dout = *ym2612_dacout;\r
- if(PicoOpt&8) {\r
- // some manual loop unrolling here :)\r
- d[0] = dout;\r
- if (len > 1) {\r
- d[2] = dout;\r
- if (len > 2)\r
- d[4] = dout;\r
- }\r
- } else {\r
- short *d = PsndOut + pos;\r
- d[0] = dout;\r
- if (len > 1) {\r
- d[1] = dout;\r
- if (len > 2)\r
- d[2] = dout;\r
- }\r
- }\r
+ for (; len > 0; len--, d+=2) *d = dout;\r
+ } else {\r
+ short *d = PsndOut + pos;\r
+ for (; len > 0; len--, d++) *d = dout;\r
}\r
\r
#if 0\r
#endif\r
}\r
\r
+// cdda\r
+static pm_file *cdda_stream = NULL;\r
+\r
+static void cdda_raw_update(int *buffer, int length)\r
+{\r
+ int ret, cdda_bytes;\r
+ if (cdda_stream == NULL) return;\r
+\r
+ cdda_bytes = length*4;\r
+ if (PsndRate <= 22050) cdda_bytes *= 2;\r
+ if (PsndRate < 22050) cdda_bytes *= 2;\r
+\r
+ ret = pm_read(cdda_out_buffer, cdda_bytes, cdda_stream);\r
+ if (ret < cdda_bytes) {\r
+ memset((char *)cdda_out_buffer + ret, 0, cdda_bytes - ret);\r
+ cdda_stream = NULL;\r
+ return;\r
+ }\r
+\r
+ // now mix\r
+ switch (PsndRate) {\r
+ case 44100: mix_16h_to_32(buffer, cdda_out_buffer, length*2); break;\r
+ case 22050: mix_16h_to_32_s1(buffer, cdda_out_buffer, length*2); break;\r
+ case 11025: mix_16h_to_32_s2(buffer, cdda_out_buffer, length*2); break;\r
+ }\r
+}\r
+\r
+PICO_INTERNAL void cdda_start_play(void)\r
+{\r
+ int lba_offset, index, lba_length, i;\r
+\r
+ elprintf(EL_STATUS, "cdda play track #%i", Pico_mcd->scd.Cur_Track);\r
+\r
+ index = Pico_mcd->scd.Cur_Track - 1;\r
+\r
+ lba_offset = Pico_mcd->scd.Cur_LBA - Track_to_LBA(index + 1);\r
+ if (lba_offset < 0) lba_offset = 0;\r
+ lba_offset += Pico_mcd->TOC.Tracks[index].Offset;\r
+\r
+ // find the actual file for this track\r
+ for (i = index; i >= 0; i--)\r
+ if (Pico_mcd->TOC.Tracks[i].F != NULL) break;\r
+\r
+ if (Pico_mcd->TOC.Tracks[i].F == NULL) {\r
+ elprintf(EL_STATUS|EL_ANOMALY, "no track?!");\r
+ return;\r
+ }\r
+\r
+ if (Pico_mcd->TOC.Tracks[i].ftype == TYPE_MP3)\r
+ {\r
+ int pos1024 = 0;\r
+\r
+ lba_length = Pico_mcd->TOC.Tracks[i].Length;\r
+ for (i++; i < Pico_mcd->TOC.Last_Track; i++) {\r
+ if (Pico_mcd->TOC.Tracks[i].F != NULL) break;\r
+ lba_length += Pico_mcd->TOC.Tracks[i].Length;\r
+ }\r
+\r
+ if (lba_offset)\r
+ pos1024 = lba_offset * 1024 / lba_length;\r
+\r
+ mp3_start_play(Pico_mcd->TOC.Tracks[index].F, pos1024);\r
+ return;\r
+ }\r
+\r
+ cdda_stream = Pico_mcd->TOC.Tracks[i].F;\r
+ PicoCDBufferFlush(); // buffering relies on fp not being touched\r
+ pm_seek(cdda_stream, lba_offset * 2352, SEEK_SET);\r
+ if (Pico_mcd->TOC.Tracks[i].ftype == TYPE_WAV)\r
+ {\r
+ // skip headers, assume it's 44kHz stereo uncompressed\r
+ pm_seek(cdda_stream, 44, SEEK_CUR);\r
+ }\r
+}\r
+\r
\r
PICO_INTERNAL void PsndClear(void)\r
{\r
int len = PsndLen;\r
if (PsndLen_exc_add) len++;\r
- if (PicoOpt & 8)\r
+ if (PicoOpt & POPT_EN_STEREO)\r
memset32((int *) PsndOut, 0, len); // assume PsndOut to be aligned\r
else {\r
short *out = PsndOut;\r
int *buf32 = PsndBuffer+offset;\r
int stereo = (PicoOpt & 8) >> 3;\r
// emulating CD && PCM option enabled && PCM chip on && have enabled channels\r
- int do_pcm = (PicoMCD&1) && (PicoOpt&0x400) && (Pico_mcd->pcm.control & 0x80) && Pico_mcd->pcm.enabled;\r
+ int do_pcm = (PicoAHW & PAHW_MCD) && (PicoOpt&POPT_EN_MCD_PCM) &&\r
+ (Pico_mcd->pcm.control & 0x80) && Pico_mcd->pcm.enabled;\r
offset <<= stereo;\r
\r
#if !SIMPLE_WRITE_SOUND\r
#endif\r
\r
// PSG\r
- if (PicoOpt & 2)\r
+ if (PicoOpt & POPT_EN_PSG)\r
SN76496Update(PsndOut+offset, length, stereo);\r
\r
+ if (PicoAHW & PAHW_PICO) {\r
+ PicoPicoPCMUpdate(PsndOut+offset, length, stereo);\r
+ return length;\r
+ }\r
+\r
// Add in the stereo FM buffer\r
- if (PicoOpt & 1) {\r
+ if (PicoOpt & POPT_EN_FM) {\r
buf32_updated = YM2612UpdateOne(buf32, length, stereo, 1);\r
} else\r
memset32(buf32, 0, length<<stereo);\r
\r
// CD: CDDA audio\r
// CD mode, cdda enabled, not data track, CDC is reading\r
- if ((PicoMCD & 1) && (PicoOpt & 0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1))\r
- mp3_update(buf32, length, stereo);\r
+ if ((PicoAHW & PAHW_MCD) && (PicoOpt & POPT_EN_MCD_CDDA) &&\r
+ !(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1))\r
+ {\r
+ // note: only 44, 22 and 11 kHz supported, with forced stereo\r
+ int index = Pico_mcd->scd.Cur_Track - 1;\r
+\r
+ if (Pico_mcd->TOC.Tracks[index].ftype == TYPE_MP3)\r
+ mp3_update(buf32, length, stereo);\r
+ else\r
+ cdda_raw_update(buf32, length);\r
+ }\r
\r
// convert + limit to normal 16bit output\r
PsndMix_32_to_16l(PsndOut+offset, buf32, length);\r
}\r
\r
\r
+// -----------------------------------------------------------------\r
+// z80 stuff\r
+\r
\r
#if defined(_USE_MZ80)\r
\r