mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-04 23:07:46 -04:00
sound, don't reinitialize after menu if not needed
This commit is contained in:
parent
67c9ba38cb
commit
864ac1d6a6
4 changed files with 44 additions and 23 deletions
|
@ -279,6 +279,15 @@ static void SN76496_set_gain(struct SN76496 *R,int gain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//static
|
||||||
|
void SN76496_set_clockrate(int clock,int sample_rate)
|
||||||
|
{
|
||||||
|
struct SN76496 *R = &ono_sn;
|
||||||
|
|
||||||
|
R->SampleRate = sample_rate;
|
||||||
|
SN76496_set_clock(R,clock);
|
||||||
|
}
|
||||||
|
|
||||||
//static
|
//static
|
||||||
int SN76496_init(int clock,int sample_rate)
|
int SN76496_init(int clock,int sample_rate)
|
||||||
{
|
{
|
||||||
|
@ -287,8 +296,7 @@ int SN76496_init(int clock,int sample_rate)
|
||||||
|
|
||||||
//R->Channel = stream_create(0,1, sample_rate,R,SN76496Update);
|
//R->Channel = stream_create(0,1, sample_rate,R,SN76496Update);
|
||||||
|
|
||||||
R->SampleRate = sample_rate;
|
SN76496_set_clockrate(clock,sample_rate);
|
||||||
SN76496_set_clock(R,clock);
|
|
||||||
|
|
||||||
for (i = 0;i < 4;i++) R->Volume[i] = 0;
|
for (i = 0;i < 4;i++) R->Volume[i] = 0;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
void SN76496Write(int data);
|
void SN76496Write(int data);
|
||||||
void SN76496Update(short *buffer,int length,int stereo);
|
void SN76496Update(short *buffer,int length,int stereo);
|
||||||
void SN76496Config(int panning);
|
void SN76496Config(int panning);
|
||||||
|
void SN76496_set_clockrate(int clock,int sample_rate);
|
||||||
int SN76496_init(int clock,int sample_rate);
|
int SN76496_init(int clock,int sample_rate);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,7 +33,6 @@ static int (*PsndFMUpdate)(s32 *buffer, int length, int stereo, int is_buf_empty
|
||||||
|
|
||||||
// ym2413
|
// ym2413
|
||||||
static OPLL *opll = NULL;
|
static OPLL *opll = NULL;
|
||||||
static OPLL old_opll;
|
|
||||||
static struct {
|
static struct {
|
||||||
uint32_t adr;
|
uint32_t adr;
|
||||||
uint8_t reg[sizeof(opll->reg)];
|
uint8_t reg[sizeof(opll->reg)];
|
||||||
|
@ -152,6 +151,10 @@ static int YM2612UpdateONE(s32 *buffer, int length, int stereo, int is_buf_empty
|
||||||
return YM2612UpdateOne(buffer, length, stereo, is_buf_empty);
|
return YM2612UpdateOne(buffer, length, stereo, is_buf_empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ymclock;
|
||||||
|
static int ymrate;
|
||||||
|
static int ymopts;
|
||||||
|
|
||||||
// to be called after changing sound rate or chips
|
// to be called after changing sound rate or chips
|
||||||
void PsndRerate(int preserve_state)
|
void PsndRerate(int preserve_state)
|
||||||
{
|
{
|
||||||
|
@ -159,54 +162,58 @@ void PsndRerate(int preserve_state)
|
||||||
int target_fps = Pico.m.pal ? 50 : 60;
|
int target_fps = Pico.m.pal ? 50 : 60;
|
||||||
int target_lines = Pico.m.pal ? 313 : 262;
|
int target_lines = Pico.m.pal ? 313 : 262;
|
||||||
int sms_clock = Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15;
|
int sms_clock = Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15;
|
||||||
|
int ym2413_rate = (sms_clock + 36) / 72;
|
||||||
int ym2612_clock = Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7;
|
int ym2612_clock = Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7;
|
||||||
int ym2612_rate = YM2612_NATIVE_RATE();
|
int ym2612_rate = YM2612_NATIVE_RATE();
|
||||||
int ym2413_rate = (sms_clock + 36) / 72;
|
int ym2612_init = !preserve_state;
|
||||||
|
|
||||||
if (preserve_state) {
|
// don't init YM2612 if preserve_state and no parameter changes
|
||||||
|
ym2612_init |= ymclock != ym2612_clock || ymopts != (PicoIn.opt & (POPT_DIS_FM_SSGEG|POPT_EN_FM_DAC));
|
||||||
|
ym2612_init |= ymrate != (PicoIn.opt & POPT_EN_FM_FILTER ? ym2612_rate : PicoIn.sndRate);
|
||||||
|
ymclock = ym2612_clock;
|
||||||
|
ymrate = (PicoIn.opt & POPT_EN_FM_FILTER ? ym2612_rate : PicoIn.sndRate);
|
||||||
|
ymopts = PicoIn.opt & (POPT_DIS_FM_SSGEG|POPT_EN_FM_DAC);
|
||||||
|
|
||||||
|
if (preserve_state && ym2612_init) {
|
||||||
state = malloc(0x204);
|
state = malloc(0x204);
|
||||||
if (state == NULL) return;
|
if (state == NULL) return;
|
||||||
ym2612_pack_state();
|
ym2612_pack_state();
|
||||||
memcpy(state, YM2612GetRegs(), 0x204);
|
memcpy(state, YM2612GetRegs(), 0x204);
|
||||||
|
|
||||||
if (opll != NULL)
|
|
||||||
memcpy(&old_opll, opll, sizeof(OPLL)); // remember old state
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PicoIn.AHW & PAHW_SMS) {
|
if (PicoIn.AHW & PAHW_SMS) {
|
||||||
OPLL_setRate(opll, ym2413_rate);
|
OPLL_setRate(opll, ym2413_rate);
|
||||||
OPLL_reset(opll);
|
if (!preserve_state)
|
||||||
|
OPLL_reset(opll);
|
||||||
YMFM_setup_FIR(ym2413_rate, PicoIn.sndRate, 0);
|
YMFM_setup_FIR(ym2413_rate, PicoIn.sndRate, 0);
|
||||||
PsndFMUpdate = YM2413UpdateFIR;
|
PsndFMUpdate = YM2413UpdateFIR;
|
||||||
} else if ((PicoIn.opt & POPT_EN_FM_FILTER) && ym2612_rate != PicoIn.sndRate) {
|
} else if ((PicoIn.opt & POPT_EN_FM_FILTER) && ym2612_rate != PicoIn.sndRate) {
|
||||||
// polyphase FIR resampler, resampling directly from native to output rate
|
// polyphase FIR resampler, resampling directly from native to output rate
|
||||||
YM2612Init(ym2612_clock, ym2612_rate,
|
if (ym2612_init)
|
||||||
|
YM2612Init(ym2612_clock, ym2612_rate,
|
||||||
((PicoIn.opt&POPT_DIS_FM_SSGEG) ? 0 : ST_SSG) |
|
((PicoIn.opt&POPT_DIS_FM_SSGEG) ? 0 : ST_SSG) |
|
||||||
((PicoIn.opt&POPT_EN_FM_DAC) ? ST_DAC : 0));
|
((PicoIn.opt&POPT_EN_FM_DAC) ? ST_DAC : 0));
|
||||||
YMFM_setup_FIR(ym2612_rate, PicoIn.sndRate, PicoIn.opt & POPT_EN_STEREO);
|
YMFM_setup_FIR(ym2612_rate, PicoIn.sndRate, PicoIn.opt & POPT_EN_STEREO);
|
||||||
PsndFMUpdate = YM2612UpdateFIR;
|
PsndFMUpdate = YM2612UpdateFIR;
|
||||||
} else {
|
} else {
|
||||||
YM2612Init(ym2612_clock, PicoIn.sndRate,
|
if (ym2612_init)
|
||||||
|
YM2612Init(ym2612_clock, PicoIn.sndRate,
|
||||||
((PicoIn.opt&POPT_DIS_FM_SSGEG) ? 0 : ST_SSG) |
|
((PicoIn.opt&POPT_DIS_FM_SSGEG) ? 0 : ST_SSG) |
|
||||||
((PicoIn.opt&POPT_EN_FM_DAC) ? ST_DAC : 0));
|
((PicoIn.opt&POPT_EN_FM_DAC) ? ST_DAC : 0));
|
||||||
PsndFMUpdate = YM2612UpdateONE;
|
PsndFMUpdate = YM2612UpdateONE;
|
||||||
}
|
}
|
||||||
if (preserve_state) {
|
|
||||||
|
if (preserve_state && ym2612_init) {
|
||||||
// feed it back it's own registers, just like after loading state
|
// feed it back it's own registers, just like after loading state
|
||||||
memcpy(YM2612GetRegs(), state, 0x204);
|
memcpy(YM2612GetRegs(), state, 0x204);
|
||||||
ym2612_unpack_state();
|
ym2612_unpack_state();
|
||||||
|
free(state);
|
||||||
if (opll != NULL) {
|
|
||||||
memcpy(&opll->adr, &old_opll.adr, sizeof(OPLL)-20); // restore old state
|
|
||||||
OPLL_forceRefresh(opll);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preserve_state) memcpy(state, sn76496_regs, 28*4); // remember old state
|
if (preserve_state)
|
||||||
SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PicoIn.sndRate);
|
SN76496_set_clockrate(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PicoIn.sndRate);
|
||||||
if (preserve_state) memcpy(sn76496_regs, state, 28*4); // restore old state
|
else
|
||||||
|
SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PicoIn.sndRate);
|
||||||
if (state)
|
|
||||||
free(state);
|
|
||||||
|
|
||||||
// calculate Pico.snd.len
|
// calculate Pico.snd.len
|
||||||
Pico.snd.len = PicoIn.sndRate / target_fps;
|
Pico.snd.len = PicoIn.sndRate / target_fps;
|
||||||
|
|
|
@ -193,6 +193,8 @@ UINT16 ym_tl_tab2[13*TL_RES_LEN];
|
||||||
/* sin waveform table in 'decibel' scale (use only period/4 values) */
|
/* sin waveform table in 'decibel' scale (use only period/4 values) */
|
||||||
static UINT16 ym_sin_tab[256];
|
static UINT16 ym_sin_tab[256];
|
||||||
|
|
||||||
|
static int ym_init_tab;
|
||||||
|
|
||||||
/* sustain level table (3dB per step) */
|
/* sustain level table (3dB per step) */
|
||||||
/* bit0, bit1, bit2, bit3, bit4, bit5, bit6 */
|
/* bit0, bit1, bit2, bit3, bit4, bit5, bit6 */
|
||||||
/* 1, 2, 4, 8, 16, 32, 64 (value)*/
|
/* 1, 2, 4, 8, 16, 32, 64 (value)*/
|
||||||
|
@ -1467,6 +1469,9 @@ static void init_tables(void)
|
||||||
signed int n;
|
signed int n;
|
||||||
double o,m;
|
double o,m;
|
||||||
|
|
||||||
|
if (ym_init_tab) return;
|
||||||
|
ym_init_tab = 1;
|
||||||
|
|
||||||
for (i=0; i < 256; i++)
|
for (i=0; i < 256; i++)
|
||||||
{
|
{
|
||||||
/* non-standard sinus */
|
/* non-standard sinus */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue