Merge pull request #6271 from cam900/ymf278b_fmrate

ymf278b.cpp : Fix output rate and clock divider of FM part, Fix mixing behavior
This commit is contained in:
ajrhacker 2020-02-07 11:17:24 -05:00 committed by GitHub
commit f0173e7d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 58 deletions

View File

@ -47,12 +47,10 @@ void msx_cart_moonsound_device::device_add_mconfig(machine_config &config)
m_ymf278b->irq_handler().set(FUNC(msx_cart_moonsound_device::irq_w));
m_ymf278b->add_route(0, "lspeaker", 0.50);
m_ymf278b->add_route(1, "rspeaker", 0.50);
m_ymf278b->add_route(2, "lspeaker", 0.50);
m_ymf278b->add_route(3, "rspeaker", 0.50);
m_ymf278b->add_route(4, "lspeaker", 0.40);
m_ymf278b->add_route(5, "rspeaker", 0.40);
m_ymf278b->add_route(6, "lspeaker", 0.40);
m_ymf278b->add_route(7, "rspeaker", 0.40);
m_ymf278b->add_route(2, "lspeaker", 0.40);
m_ymf278b->add_route(3, "rspeaker", 0.40);
m_ymf278b->add_route(4, "lspeaker", 0.50);
m_ymf278b->add_route(5, "rspeaker", 0.50);
}

View File

@ -233,7 +233,7 @@ struct OPL3
signed int phase_modulation2; /* phase modulation input (SLOT 3 in 4 operator channels) */
uint32_t eg_cnt; /* global envelope generator counter */
uint32_t eg_timer; /* global envelope generator counter works at frequency = chipclock/288 (288=8*36) */
uint32_t eg_timer; /* global envelope generator counter works at frequency = chipclock/divider */
uint32_t eg_timer_add; /* step of eg_timer */
uint32_t eg_timer_overflow; /* envelope generator timer overflows every 1 sample (on real chip) */
@ -278,6 +278,7 @@ struct OPL3
uint8_t type; /* chip type */
int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */
int divider; /* clock divider */
double freqbase; /* frequency base */
attotime TimerBase; /* Timer base time (==sampling time)*/
device_t *device;
@ -1342,16 +1343,16 @@ static void OPL3_initalize(OPL3 *chip)
int i;
/* frequency base */
chip->freqbase = (chip->rate) ? ((double)chip->clock / (8.0*36)) / chip->rate : 0;
chip->freqbase = (chip->rate) ? ((double)chip->clock / chip->divider) / chip->rate : 0;
#if 0
chip->rate = (double)chip->clock / (8.0*36);
chip->rate = (double)chip->clock / chip->divider;
chip->freqbase = 1.0;
#endif
/* logerror("YMF262: freqbase=%f\n", chip->freqbase); */
/* Timer base time */
chip->TimerBase = chip->clock ? attotime::from_hz(chip->clock) * (8 * 36) : attotime::zero;
chip->TimerBase = chip->clock ? attotime::from_hz(chip->clock) * chip->divider : attotime::zero;
/* make fnumber -> increment counter table */
for( i=0 ; i < 1024 ; i++ )
@ -2358,7 +2359,7 @@ static void OPL3ResetChip(OPL3 *chip)
/* Create one of virtual YMF262 */
/* 'clock' is chip clock in Hz */
/* 'rate' is sampling rate */
static OPL3 *OPL3Create(device_t *device, int clock, int rate, int type)
static OPL3 *OPL3Create(device_t *device, int clock, int rate, int type, int divider)
{
OPL3 *chip;
@ -2369,6 +2370,7 @@ static OPL3 *OPL3Create(device_t *device, int clock, int rate, int type)
chip->device = device;
chip->type = type;
chip->divider = divider;
OPL3_clock_changed(chip, clock, rate);
/* reset chip */
@ -2535,7 +2537,15 @@ static void OPL3_save_state(OPL3 *chip, device_t *device) {
void * ymf262_init(device_t *device, int clock, int rate)
{
void *chip = OPL3Create(device,clock,rate,OPL3_TYPE_YMF262);
void *chip = OPL3Create(device,clock,rate,OPL3_TYPE_YMF262,8*36);
OPL3_save_state((OPL3 *)chip, device);
return chip;
}
void * ymf278b_init(device_t *device, int clock, int rate)
{
void *chip = OPL3Create(device,clock,rate,OPL3_TYPE_YMF262,19*36);
OPL3_save_state((OPL3 *)chip, device);
return chip;

View File

@ -24,6 +24,8 @@ typedef void (*OPL3_UPDATEHANDLER)(device_t *device,int min_interval_us);
void *ymf262_init(device_t *device, int clock, int rate);
void *ymf278b_init(device_t *device, int clock, int rate);
void ymf262_clock_changed(void *chip, int clock, int rate);
void ymf262_post_load(void *chip);
void ymf262_shutdown(void *chip);

View File

@ -223,19 +223,14 @@ void ymf278b_device::sound_stream_update(sound_stream &stream, stream_sample_t *
int32_t *mixp;
int32_t vl, vr;
if (&stream == m_stream_ymf262)
ymf262_update_one(m_ymf262, outputs, samples);
vl = m_mix_level[m_fm_l];
vr = m_mix_level[m_fm_r];
for (i = 0; i < samples; i++)
{
// TODO : FM only output is DO0, DO2 is actually mixed FM+PCM outputs
ymf262_update_one(m_ymf262, outputs, samples);
vl = m_mix_level[m_fm_l];
vr = m_mix_level[m_fm_r];
for (i = 0; i < samples; i++)
{
// DO2 mixing
outputs[0][i] = (outputs[0][i] * vl) >> 16;
outputs[1][i] = (outputs[1][i] * vr) >> 16;
}
return;
// DO2 mixing
outputs[0][i] = (outputs[0][i] * vl) >> 16;
outputs[1][i] = (outputs[1][i] * vr) >> 16;
}
std::fill(m_mix_buffer.begin(), m_mix_buffer.end(), 0);
@ -323,10 +318,10 @@ void ymf278b_device::sound_stream_update(sound_stream &stream, stream_sample_t *
vr = m_mix_level[m_pcm_r];
for (i = 0; i < samples; i++)
{
outputs[0][i] = (*mixp++ * vl) >> 16;
outputs[1][i] = (*mixp++ * vr) >> 16;
outputs[2][i] = *mixp++;
outputs[3][i] = *mixp++;
outputs[0][i] += (*mixp++ * vl) >> 16;
outputs[1][i] += (*mixp++ * vr) >> 16;
outputs[4][i] = *mixp++;
outputs[5][i] = *mixp++;
}
}
@ -891,9 +886,7 @@ void ymf278b_device::device_clock_changed()
// YMF262 related
int ymf262_clock = clock() / (19/8.0);
ymf262_clock_changed(m_ymf262, ymf262_clock, ymf262_clock / 288);
m_stream_ymf262->set_sample_rate(ymf262_clock / 288);
ymf262_clock_changed(m_ymf262, clock(), m_rate);
}
void ymf278b_device::rom_bank_updated()
@ -1016,7 +1009,7 @@ void ymf278b_device::device_start()
m_slots[i].num = i;
}
m_stream = machine().sound().stream_alloc(*this, 0, 4, m_rate);
m_stream = machine().sound().stream_alloc(*this, 0, 6, m_rate);
m_mix_buffer.resize(m_rate*4,0);
// rate tables
@ -1046,13 +1039,10 @@ void ymf278b_device::device_start()
// YMF262 related
/* stream system initialize */
int ymf262_clock = clock() / (19/8.0);
m_ymf262 = ymf262_init(this, ymf262_clock, ymf262_clock / 288);
m_ymf262 = ymf278b_init(this, clock(), m_rate);
if (!m_ymf262)
throw emu_fatalerror("ymf278b_device(%s): Error creating YMF262 chip", tag());
m_stream_ymf262 = machine().sound().stream_alloc(*this, 0, 4, ymf262_clock / 288);
/* YMF262 setup */
ymf262_set_timer_handler (m_ymf262, ymf278b_device::static_timer_handler, this);
ymf262_set_irq_handler (m_ymf262, ymf278b_device::static_irq_handler, this);

View File

@ -88,7 +88,7 @@ private:
void precompute_rate_tables();
void register_save_state();
void update_request() { m_stream_ymf262->update(); }
void update_request() { m_stream->update(); }
static void static_irq_handler(device_t *param, int irq) { }
static void static_timer_handler(device_t *param, int c, const attotime &period) { }
@ -134,7 +134,6 @@ private:
// ymf262
void *m_ymf262;
sound_stream * m_stream_ymf262;
};
DECLARE_DEVICE_TYPE(YMF278B, ymf278b_device)

View File

@ -557,12 +557,10 @@ void fuuki32_state::fuuki32(machine_config &config)
ymf.irq_handler().set_inputline("soundcpu", 0);
ymf.add_route(0, "lspeaker", 0.50);
ymf.add_route(1, "rspeaker", 0.50);
ymf.add_route(2, "lspeaker", 0.50);
ymf.add_route(3, "rspeaker", 0.50);
ymf.add_route(4, "lspeaker", 0.40);
ymf.add_route(5, "rspeaker", 0.40);
ymf.add_route(6, "lspeaker", 0.40);
ymf.add_route(7, "rspeaker", 0.40);
ymf.add_route(2, "lspeaker", 0.40);
ymf.add_route(3, "rspeaker", 0.40);
ymf.add_route(4, "lspeaker", 0.50);
ymf.add_route(5, "rspeaker", 0.50);
}
/***************************************************************************

View File

@ -648,8 +648,6 @@ void psikyo4_state::ps4big(machine_config &config)
ymf.add_route(3, "lspeaker", 1.0);
ymf.add_route(4, "rspeaker", 1.0);
ymf.add_route(5, "lspeaker", 1.0);
ymf.add_route(6, "rspeaker", 1.0);
ymf.add_route(7, "lspeaker", 1.0);
}
void psikyo4_state::ps4small(machine_config &config)

View File

@ -3592,25 +3592,21 @@ void vgmplay_state::vgmplay(machine_config &config)
// TODO: prevent error.log spew
YMF278B(config, m_ymf278b[0], 0);
m_ymf278b[0]->set_addrmap(0, &vgmplay_state::ymf278b_map<0>);
m_ymf278b[0]->add_route(0, "lspeaker", 0.25);
m_ymf278b[0]->add_route(1, "rspeaker", 0.25);
m_ymf278b[0]->add_route(2, "lspeaker", 0.25);
m_ymf278b[0]->add_route(3, "rspeaker", 0.25);
m_ymf278b[0]->add_route(0, "lspeaker", 1.00);
m_ymf278b[0]->add_route(1, "rspeaker", 1.00);
m_ymf278b[0]->add_route(2, "lspeaker", 1.00);
m_ymf278b[0]->add_route(3, "rspeaker", 1.00);
m_ymf278b[0]->add_route(4, "lspeaker", 1.00);
m_ymf278b[0]->add_route(5, "rspeaker", 1.00);
m_ymf278b[0]->add_route(6, "lspeaker", 1.00);
m_ymf278b[0]->add_route(7, "rspeaker", 1.00);
YMF278B(config, m_ymf278b[1], 0);
m_ymf278b[1]->set_addrmap(0, &vgmplay_state::ymf278b_map<1>);
m_ymf278b[1]->add_route(0, "lspeaker", 0.25);
m_ymf278b[1]->add_route(1, "rspeaker", 0.25);
m_ymf278b[1]->add_route(2, "lspeaker", 0.25);
m_ymf278b[1]->add_route(3, "rspeaker", 0.25);
m_ymf278b[1]->add_route(0, "lspeaker", 1.00);
m_ymf278b[1]->add_route(1, "rspeaker", 1.00);
m_ymf278b[1]->add_route(2, "lspeaker", 1.00);
m_ymf278b[1]->add_route(3, "rspeaker", 1.00);
m_ymf278b[1]->add_route(4, "lspeaker", 1.00);
m_ymf278b[1]->add_route(5, "rspeaker", 1.00);
m_ymf278b[1]->add_route(6, "lspeaker", 1.00);
m_ymf278b[1]->add_route(7, "rspeaker", 1.00);
YMF271(config, m_ymf271[0], 0);
m_ymf271[0]->set_addrmap(0, &vgmplay_state::ymf271_map<0>);