move more globals to PicoInterface

similar reasons as before
This commit is contained in:
notaz 2017-10-22 02:04:26 +03:00
parent 075672bf9f
commit 6311a3baf5
27 changed files with 244 additions and 247 deletions

View file

@ -25,31 +25,20 @@ static unsigned short dac_info[312+4]; // pos in sample buffer
// cdda output buffer
short cdda_out_buffer[2*1152];
// for Pico
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, PsndPsgLine;
short *PsndOut=NULL; // PCM data buffer
static int PsndLen_use;
// timers
int timer_a_next_oflow, timer_a_step; // in z80 cycles
int timer_b_next_oflow, timer_b_step;
// sn76496
extern int *sn76496_regs;
static void dac_recalculate(void)
{
int i, dac_cnt, pos, len, lines = Pico.m.pal ? 313 : 262, mid = Pico.m.pal ? 68 : 93;
int lines = Pico.m.pal ? 313 : 262;
int mid = Pico.m.pal ? 68 : 93;
int i, dac_cnt, pos, len;
if (PsndLen <= lines)
if (Pico.snd.len <= lines)
{
// shrinking algo
dac_cnt = -PsndLen;
dac_cnt = -Pico.snd.len;
len=1; pos=0;
dac_info[225] = 1;
@ -60,14 +49,14 @@ static void dac_recalculate(void)
pos++;
dac_cnt += lines;
}
dac_cnt -= PsndLen;
dac_cnt -= Pico.snd.len;
dac_info[i] = pos;
}
}
else
{
// stretching
dac_cnt = PsndLen;
dac_cnt = Pico.snd.len;
pos=0;
for(i = 225; i != 224; i++)
{
@ -78,11 +67,11 @@ static void dac_recalculate(void)
len++;
}
if (i == mid) // midpoint
while(pos+len < PsndLen/2) {
while(pos+len < Pico.snd.len/2) {
dac_cnt -= lines;
len++;
}
dac_cnt += PsndLen;
dac_cnt += Pico.snd.len;
pos += len;
dac_info[i] = pos;
}
@ -112,7 +101,7 @@ void PsndRerate(int preserve_state)
ym2612_pack_state();
memcpy(state, YM2612GetRegs(), 0x204);
}
YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PsndRate);
YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PicoIn.sndRate);
if (preserve_state) {
// feed it back it's own registers, just like after loading state
memcpy(YM2612GetRegs(), state, 0x204);
@ -120,16 +109,16 @@ void PsndRerate(int preserve_state)
}
if (preserve_state) memcpy(state, sn76496_regs, 28*4); // remember old state
SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PsndRate);
SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PicoIn.sndRate);
if (preserve_state) memcpy(sn76496_regs, state, 28*4); // restore old state
if (state)
free(state);
// calculate PsndLen
PsndLen=PsndRate / target_fps;
PsndLen_exc_add=((PsndRate - PsndLen*target_fps)<<16) / target_fps;
PsndLen_exc_cnt=0;
// calculate Pico.snd.len
Pico.snd.len = PicoIn.sndRate / target_fps;
Pico.snd.len_e_add = ((PicoIn.sndRate - Pico.snd.len * target_fps) << 16) / target_fps;
Pico.snd.len_e_cnt = 0;
// recalculate dac info
dac_recalculate();
@ -137,7 +126,7 @@ void PsndRerate(int preserve_state)
// clear all buffers
memset32(PsndBuffer, 0, sizeof(PsndBuffer)/4);
memset(cdda_out_buffer, 0, sizeof(cdda_out_buffer));
if (PsndOut)
if (PicoIn.sndOut)
PsndClear();
// set mixer
@ -150,24 +139,24 @@ void PsndRerate(int preserve_state)
PICO_INTERNAL void PsndStartFrame(void)
{
// compensate for float part of PsndLen
PsndLen_use = PsndLen;
PsndLen_exc_cnt += PsndLen_exc_add;
if (PsndLen_exc_cnt >= 0x10000) {
PsndLen_exc_cnt -= 0x10000;
PsndLen_use++;
// compensate for float part of Pico.snd.len
Pico.snd.len_use = Pico.snd.len;
Pico.snd.len_e_cnt += Pico.snd.len_e_add;
if (Pico.snd.len_e_cnt >= 0x10000) {
Pico.snd.len_e_cnt -= 0x10000;
Pico.snd.len_use++;
}
PsndDacLine = PsndPsgLine = 0;
Pico.snd.dac_line = Pico.snd.psg_line = 0;
Pico.m.status &= ~1;
dac_info[224] = PsndLen_use;
dac_info[224] = Pico.snd.len_use;
}
PICO_INTERNAL void PsndDoDAC(int line_to)
{
int pos, pos1, len;
int dout = ym2612.dacout;
int line_from = PsndDacLine;
int line_from = Pico.snd.dac_line;
if (line_to >= 313)
line_to = 312;
@ -178,23 +167,23 @@ PICO_INTERNAL void PsndDoDAC(int line_to)
if (len <= 0)
return;
PsndDacLine = line_to + 1;
Pico.snd.dac_line = line_to + 1;
if (!PsndOut)
if (!PicoIn.sndOut)
return;
if (PicoIn.opt & POPT_EN_STEREO) {
short *d = PsndOut + pos*2;
short *d = PicoIn.sndOut + pos*2;
for (; len > 0; len--, d+=2) *d += dout;
} else {
short *d = PsndOut + pos;
short *d = PicoIn.sndOut + pos;
for (; len > 0; len--, d++) *d += dout;
}
}
PICO_INTERNAL void PsndDoPSG(int line_to)
{
int line_from = PsndPsgLine;
int line_from = Pico.snd.psg_line;
int pos, pos1, len;
int stereo = 0;
@ -209,16 +198,16 @@ PICO_INTERNAL void PsndDoPSG(int line_to)
if (len <= 0)
return;
PsndPsgLine = line_to + 1;
Pico.snd.psg_line = line_to + 1;
if (!PsndOut || !(PicoIn.opt & POPT_EN_PSG))
if (!PicoIn.sndOut || !(PicoIn.opt & POPT_EN_PSG))
return;
if (PicoIn.opt & POPT_EN_STEREO) {
stereo = 1;
pos <<= 1;
}
SN76496Update(PsndOut + pos, len, stereo);
SN76496Update(PicoIn.sndOut + pos, len, stereo);
}
// cdda
@ -227,8 +216,8 @@ static void cdda_raw_update(int *buffer, int length)
int ret, cdda_bytes, mult = 1;
cdda_bytes = length*4;
if (PsndRate <= 22050 + 100) mult = 2;
if (PsndRate < 22050 - 100) mult = 4;
if (PicoIn.sndRate <= 22050 + 100) mult = 2;
if (PicoIn.sndRate < 22050 - 100) mult = 4;
cdda_bytes *= mult;
ret = pm_read(cdda_out_buffer, cdda_bytes, Pico_mcd->cdda_stream);
@ -270,12 +259,12 @@ void cdda_start_play(int lba_base, int lba_offset, int lb_len)
PICO_INTERNAL void PsndClear(void)
{
int len = PsndLen;
if (PsndLen_exc_add) len++;
int len = Pico.snd.len;
if (Pico.snd.len_e_add) len++;
if (PicoIn.opt & POPT_EN_STEREO)
memset32((int *) PsndOut, 0, len); // assume PsndOut to be aligned
memset32((int *) PicoIn.sndOut, 0, len); // assume PicoIn.sndOut to be aligned
else {
short *out = PsndOut;
short *out = PicoIn.sndOut;
if ((long)out & 2) { *out++ = 0; len--; }
memset32((int *) out, 0, len/2);
if (len & 1) out[len-1] = 0;
@ -294,7 +283,7 @@ static int PsndRender(int offset, int length)
pprof_start(sound);
if (PicoIn.AHW & PAHW_PICO) {
PicoPicoPCMUpdate(PsndOut+offset, length, stereo);
PicoPicoPCMUpdate(PicoIn.sndOut+offset, length, stereo);
return length;
}
@ -330,7 +319,7 @@ static int PsndRender(int offset, int length)
p32x_pwm_update(buf32, length, stereo);
// convert + limit to normal 16bit output
PsndMix_32_to_16l(PsndOut+offset, buf32, length);
PsndMix_32_to_16l(PicoIn.sndOut+offset, buf32, length);
pprof_end(sound);
@ -342,47 +331,47 @@ PICO_INTERNAL void PsndGetSamples(int y)
{
static int curr_pos = 0;
if (ym2612.dacen && PsndDacLine < y)
if (ym2612.dacen && Pico.snd.dac_line < y)
PsndDoDAC(y - 1);
PsndDoPSG(y - 1);
if (y == 224)
{
if (Pico.m.status & 2)
curr_pos += PsndRender(curr_pos, PsndLen-PsndLen/2);
else curr_pos = PsndRender(0, PsndLen_use);
curr_pos += PsndRender(curr_pos, Pico.snd.len-Pico.snd.len/2);
else curr_pos = PsndRender(0, Pico.snd.len_use);
if (Pico.m.status & 1)
Pico.m.status |= 2;
else Pico.m.status &= ~2;
if (PicoWriteSound)
PicoWriteSound(curr_pos * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));
if (PicoIn.writeSound)
PicoIn.writeSound(curr_pos * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));
// clear sound buffer
PsndClear();
PsndDacLine = 224;
Pico.snd.dac_line = 224;
dac_info[224] = 0;
}
else if (Pico.m.status & 3) {
Pico.m.status |= 2;
Pico.m.status &= ~1;
curr_pos = PsndRender(0, PsndLen/2);
curr_pos = PsndRender(0, Pico.snd.len/2);
}
}
PICO_INTERNAL void PsndGetSamplesMS(void)
{
int length = PsndLen_use;
int length = Pico.snd.len_use;
PsndDoPSG(223);
// upmix to "stereo" if needed
if (PicoIn.opt & POPT_EN_STEREO) {
int i, *p;
for (i = length, p = (void *)PsndOut; i > 0; i--, p++)
for (i = length, p = (void *)PicoIn.sndOut; i > 0; i--, p++)
*p |= *p << 16;
}
if (PicoWriteSound != NULL)
PicoWriteSound(length * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));
if (PicoIn.writeSound != NULL)
PicoIn.writeSound(length * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));
PsndClear();
dac_info[224] = 0;