ymf278b.cpp : Add DO1/2 Output, Fix buffer when clock is changed (#3806)

* ymf278b.cpp : Add DO1/2 Output,  Fix timer/buffer when clock is changed
fuukifg3.h : Remove unused clock

* ymf278b.cpp : Fix sync

* ymf278b.cpp : Add notes
This commit is contained in:
R. Belmont 2019-03-31 17:00:05 -04:00 committed by GitHub
commit 104e42014e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 15 deletions

View File

@ -41,15 +41,18 @@ void msx_cart_moonsound_device::device_add_mconfig(machine_config &config)
// The moonsound cartridge has a separate stereo output.
SPEAKER(config, "lspeaker").front_left();
SPEAKER(config, "rspeaker").front_right();
YMF278B(config, m_ymf278b, YMF278B_STD_CLOCK);
m_ymf278b->set_addrmap(0, &msx_cart_moonsound_device::ymf278b_map);
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.40);
m_ymf278b->add_route(3, "rspeaker", 0.40);
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);
}

View File

@ -50,6 +50,8 @@
#include "ymf278b.h"
#include "ymf262.h"
#include <algorithm>
#define VERBOSE 0
#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
@ -221,11 +223,12 @@ void ymf278b_device::sound_stream_update(sound_stream &stream, stream_sample_t *
if (&stream == m_stream_ymf262)
{
// TODO : FM only output is DO0, DO2 is actually mixed FM+PCM outputs
ymf262_update_one(m_ymf262, outputs, samples);
return;
}
memset(m_mix_buffer.get(), 0, sizeof(m_mix_buffer[0])*samples*2);
std::fill(m_mix_buffer.begin(), m_mix_buffer.end(), 0);
for (i = 0; i < 24; i++)
{
@ -233,7 +236,7 @@ void ymf278b_device::sound_stream_update(sound_stream &stream, stream_sample_t *
if (slot->active)
{
mixp = m_mix_buffer.get();
mixp = &m_mix_buffer[0];
for (j = 0; j < samples; j++)
{
@ -274,8 +277,20 @@ void ymf278b_device::sound_stream_update(sound_stream &stream, stream_sample_t *
break;
}
*mixp++ += (sample * m_volume[slot->TL+m_pan_left [slot->pan]+(slot->env_vol>>23)])>>17;
*mixp++ += (sample * m_volume[slot->TL+m_pan_right[slot->pan]+(slot->env_vol>>23)])>>17;
if (slot->CH) // DO1 out
{
mixp++;
mixp++;
*mixp++ += (sample * m_volume[slot->TL+m_pan_left [slot->pan]+(slot->env_vol>>23)])>>17;
*mixp++ += (sample * m_volume[slot->TL+m_pan_right[slot->pan]+(slot->env_vol>>23)])>>17;
}
else // DO2 out
{
*mixp++ += (sample * m_volume[slot->TL+m_pan_left [slot->pan]+(slot->env_vol>>23)])>>17;
*mixp++ += (sample * m_volume[slot->TL+m_pan_right[slot->pan]+(slot->env_vol>>23)])>>17;
mixp++;
mixp++;
}
// update frequency
slot->stepptr += slot->step;
@ -293,13 +308,15 @@ void ymf278b_device::sound_stream_update(sound_stream &stream, stream_sample_t *
}
}
mixp = m_mix_buffer.get();
mixp = &m_mix_buffer[0];
vl = m_mix_level[m_pcm_l];
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++;
}
}
@ -780,6 +797,7 @@ u8 ymf278b_device::read(offs_t offset)
//-------------------------------------------------
// device_post_load - device-specific post load
//-------------------------------------------------
void ymf278b_device::device_post_load()
{
ymf262_post_load(m_ymf262);
@ -851,9 +869,16 @@ void ymf278b_device::device_stop()
void ymf278b_device::device_clock_changed()
{
m_stream->set_sample_rate(clock()/768);
int old_rate = m_rate;
m_clock = clock();
m_rate = m_clock/768;
if (m_rate > old_rate)
{
m_mix_buffer.resize(m_rate*4,0);
}
m_stream->set_sample_rate(m_rate);
m_timer_base = m_clock ? attotime::from_hz(m_clock) * (19 * 36) : attotime::zero;
// YMF262 related
@ -969,6 +994,7 @@ void ymf278b_device::device_start()
int i;
m_clock = clock();
m_rate = m_clock / 768;
m_irq_handler.resolve();
m_timer_base = m_clock ? attotime::from_hz(m_clock) * (19*36) : attotime::zero;
@ -982,8 +1008,8 @@ void ymf278b_device::device_start()
m_slots[i].num = i;
}
m_stream = machine().sound().stream_alloc(*this, 0, 2, clock()/768);
m_mix_buffer = std::make_unique<int32_t[]>(44100*2);
m_stream = machine().sound().stream_alloc(*this, 0, 4, m_rate);
m_mix_buffer.resize(m_rate*4,0);
// rate tables
precompute_rate_tables();

View File

@ -127,9 +127,10 @@ private:
emu_timer *m_timer_a, *m_timer_b;
int m_clock;
int m_rate;
sound_stream * m_stream;
std::unique_ptr<int32_t[]> m_mix_buffer;
std::vector<int32_t> m_mix_buffer;
devcb_write_line m_irq_handler;
uint8_t m_last_fm_data;

View File

@ -545,10 +545,12 @@ 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.40);
ymf.add_route(3, "rspeaker", 0.40);
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);
}
/***************************************************************************

View File

@ -13,7 +13,6 @@
#define CPU_CLOCK (XTAL(40'000'000) / 2) /* clock for 68020 */
#define SOUND_CPU_CLOCK (XTAL(12'000'000) / 2) /* clock for Z80 sound CPU */
#define FM_SOUND_CLOCK (XTAL(33'868'800) / 2) /* FM clock */
/* NOTE: YMF278B_STD_CLOCK is defined in /src/emu/sound/ymf278b.h */