From 7f6e8e7724ed321433ba3948452a0ddf8b159819 Mon Sep 17 00:00:00 2001 From: cam900 Date: Mon, 21 Mar 2022 12:06:32 +0900 Subject: k051649.cpp: Fix input clock, Simplify some routines, Reduce unnecessary variables, Minor cleanups, Add notes (#9433) nemesis.cpp, quickpick5.cpp: Fix sound output routine for sound chips with only 1 outputs nemesis.cpp: Reduce sound output routine duplicates vgmplay.cpp: Remove outdated comments, Fix compatiblity for old VGMs --- src/devices/bus/msx_cart/konami.cpp | 4 +- src/devices/sound/k051649.cpp | 81 ++++++------------------------------- src/devices/sound/k051649.h | 6 --- src/mame/drivers/hcastle.cpp | 2 +- src/mame/drivers/hexion.cpp | 2 +- src/mame/drivers/konmedal.cpp | 4 +- src/mame/drivers/nemesis.cpp | 50 ++++++++--------------- src/mame/drivers/quickpick5.cpp | 5 +-- src/mame/drivers/vgmplay.cpp | 9 +++-- 9 files changed, 43 insertions(+), 120 deletions(-) diff --git a/src/devices/bus/msx_cart/konami.cpp b/src/devices/bus/msx_cart/konami.cpp index 022f45a4c2a..5954cb95091 100644 --- a/src/devices/bus/msx_cart/konami.cpp +++ b/src/devices/bus/msx_cart/konami.cpp @@ -148,7 +148,7 @@ void msx_cart_konami_scc_device::device_add_mconfig(machine_config &config) { // This is actually incorrect. The sound output is passed back into the MSX machine where it is mixed internally and output through the system 'speaker'. SPEAKER(config, "mono").front_center(); - K051649(config, m_k051649, XTAL(10'738'635)/3/2).add_route(ALL_OUTPUTS, "mono", 0.15); + K051649(config, m_k051649, XTAL(10'738'635)/3).add_route(ALL_OUTPUTS, "mono", 0.15); } @@ -559,7 +559,7 @@ void msx_cart_konami_sound_device::device_add_mconfig(machine_config &config) { // This is actually incorrect. The sound output is passed back into the MSX machine where it is mixed internally and output through the system 'speaker'. SPEAKER(config, "mono").front_center(); - K051649(config, m_k052539, XTAL(10'738'635)/3/2).add_route(ALL_OUTPUTS, "mono", 0.15); + K051649(config, m_k052539, XTAL(10'738'635)/3).add_route(ALL_OUTPUTS, "mono", 0.15); } diff --git a/src/devices/sound/k051649.cpp b/src/devices/sound/k051649.cpp index 9a1f748580e..fa122b8fd1a 100644 --- a/src/devices/sound/k051649.cpp +++ b/src/devices/sound/k051649.cpp @@ -28,8 +28,6 @@ #include "k051649.h" #include -#define DEF_GAIN 8 - void k051649_device::scc_map(address_map &map) { map(0x00, 0x7f).rw(FUNC(k051649_device::k051649_waveform_r), FUNC(k051649_device::k051649_waveform_w)); @@ -55,8 +53,6 @@ k051649_device::k051649_device(const machine_config &mconfig, const char *tag, d : device_t(mconfig, K051649, tag, owner, clock) , device_sound_interface(mconfig, *this) , m_stream(nullptr) - , m_rate(0) - , m_mixer_lookup(nullptr) , m_test(0) { } @@ -69,14 +65,7 @@ k051649_device::k051649_device(const machine_config &mconfig, const char *tag, d void k051649_device::device_start() { // get stream channels - m_rate = clock()/16; - m_stream = stream_alloc(0, 1, m_rate); - - // allocate a buffer to mix into - 1 second's worth should be more than enough - m_mixer_buffer.resize(2 * m_rate); - - // build the mixer table - make_mixer_table(5); + m_stream = stream_alloc(0, 1, clock()); // save states save_item(STRUCT_MEMBER(m_channel_list, counter)); @@ -127,14 +116,7 @@ void k051649_device::device_post_load() void k051649_device::device_clock_changed() { - const u32 old_rate = m_rate; - m_rate = clock()/16; - - if (old_rate < m_rate) - { - m_mixer_buffer.resize(2 * m_rate, 0); - } - m_stream->set_sample_rate(m_rate); + m_stream->set_sample_rate(clock()); } @@ -145,40 +127,26 @@ void k051649_device::device_clock_changed() void k051649_device::sound_stream_update(sound_stream &stream, std::vector const &inputs, std::vector &outputs) { // zap the contents of the mixer buffer - std::fill(m_mixer_buffer.begin(), m_mixer_buffer.end(), 0); + outputs[0].fill(0); - for (sound_channel &voice : m_channel_list) + for (int i = 0; i < outputs[0].samples(); i++) { - // channel is halted for freq < 9 - if (voice.frequency > 8) + for (sound_channel &voice : m_channel_list) { - const int v = voice.volume * voice.key; - int a = voice.counter; - int c = voice.clock; - const int step = voice.frequency; - - // add our contribution - for (int i = 0; i < outputs[0].samples(); i++) + // channel is halted for freq < 9 + if (voice.frequency > 8) { - c += 32; - while (c > step) + if ((voice.clock--) <= 0) { - a = (a + 1) & 0x1f; - c -= step+1; + voice.counter = (voice.counter + 1) & 0x1f; + voice.clock = voice.frequency; } - m_mixer_buffer[i] += (voice.waveram[a] * v) >> 3; + // scale to 11 bit digital output on chip + if (voice.key) + outputs[0].add_int(i, (voice.waveram[voice.counter] * voice.volume) >> 4, 1024); } - - // update the counter for this voice - voice.counter = a; - voice.clock = c; } } - - // mix it down - auto &buffer = outputs[0]; - for (int i = 0; i < buffer.samples(); i++) - buffer.put(i, m_mixer_lookup[m_mixer_buffer[i]]); } @@ -299,26 +267,3 @@ u8 k051649_device::k051649_test_r() k051649_test_w(0xff); return 0xff; } - - -//------------------------------------------------- -// build a table to divide by the number of voices -//------------------------------------------------- - -void k051649_device::make_mixer_table(int voices) -{ - // allocate memory - m_mixer_table.resize(512 * voices); - - // find the middle of the table - m_mixer_lookup = &m_mixer_table[256 * voices]; - - // fill in the table - 16 bit case - for (int i = 0; i < (voices * 256); i++) - { - const int val = std::min(32767, i * DEF_GAIN * 16 / voices); - stream_buffer::sample_t fval = stream_buffer::sample_t(val) / 32768.0; - m_mixer_lookup[ i] = fval; - m_mixer_lookup[-i] = -fval; - } -} diff --git a/src/devices/sound/k051649.h b/src/devices/sound/k051649.h index 368ef6c58a9..d9174e00dc9 100644 --- a/src/devices/sound/k051649.h +++ b/src/devices/sound/k051649.h @@ -68,12 +68,6 @@ private: /* global sound parameters */ sound_stream *m_stream; - int m_rate; - - /* mixer tables and internal buffers */ - std::vector m_mixer_table; - stream_buffer::sample_t *m_mixer_lookup; - std::vector m_mixer_buffer; /* chip registers */ u8 m_test; diff --git a/src/mame/drivers/hcastle.cpp b/src/mame/drivers/hcastle.cpp index 42ae4ac82cd..bfa39818725 100644 --- a/src/mame/drivers/hcastle.cpp +++ b/src/mame/drivers/hcastle.cpp @@ -232,7 +232,7 @@ void hcastle_state::hcastle(machine_config &config) ymsnd.irq_handler().set_inputline("audiocpu", INPUT_LINE_NMI); /* from schematic; NMI handler is just a retn */ ymsnd.add_route(ALL_OUTPUTS, "mono", 0.70); - K051649(config, "k051649", 3579545/2).add_route(ALL_OUTPUTS, "mono", 0.45); + K051649(config, "k051649", 3579545).add_route(ALL_OUTPUTS, "mono", 0.45); } /***************************************************************************/ diff --git a/src/mame/drivers/hexion.cpp b/src/mame/drivers/hexion.cpp index 0c762b5855b..e90cf7cb19e 100644 --- a/src/mame/drivers/hexion.cpp +++ b/src/mame/drivers/hexion.cpp @@ -283,7 +283,7 @@ void hexion_state::hexion(machine_config &config) OKIM6295(config, "oki", 1056000, okim6295_device::PIN7_HIGH).add_route(ALL_OUTPUTS, "mono", 0.5); /* KONAMI 051649 // 2212P003 // JAPAN 8910EAJ @ 1D, xtal verified, divider not verified */ - K051649(config, "k051649", XTAL(24'000'000)/16).add_route(ALL_OUTPUTS, "mono", 0.5); + K051649(config, "k051649", XTAL(24'000'000)/8).add_route(ALL_OUTPUTS, "mono", 0.5); } void hexion_state::hexionb(machine_config &config) diff --git a/src/mame/drivers/konmedal.cpp b/src/mame/drivers/konmedal.cpp index c18b0a3ac89..0ac5212c792 100644 --- a/src/mame/drivers/konmedal.cpp +++ b/src/mame/drivers/konmedal.cpp @@ -885,7 +885,7 @@ void konmedal_state::ddboy(machine_config &config) OKIM6295(config, m_oki, XTAL(14'318'181)/14, okim6295_device::PIN7_HIGH); m_oki->add_route(ALL_OUTPUTS, "mono", 1.0); - K051649(config, "k051649", XTAL(14'318'181)/8).add_route(ALL_OUTPUTS, "mono", 0.45); + K051649(config, "k051649", XTAL(14'318'181)/4).add_route(ALL_OUTPUTS, "mono", 0.45); } /* @@ -1025,7 +1025,7 @@ void konmedal_state::shuriboy(machine_config &config) /* sound hardware */ SPEAKER(config, "mono").front_center(); - K051649(config, "k051649", XTAL(24'000'000) / 12).add_route(ALL_OUTPUTS, "mono", 0.45); // divisor unknown + K051649(config, "k051649", XTAL(24'000'000) / 6).add_route(ALL_OUTPUTS, "mono", 0.45); // divisor unknown UPD7759(config, m_upd7759, XTAL(640'000)).add_route(ALL_OUTPUTS, "mono", 0.60); } diff --git a/src/mame/drivers/nemesis.cpp b/src/mame/drivers/nemesis.cpp index 5d3e0934b8d..f8ba4bd4740 100644 --- a/src/mame/drivers/nemesis.cpp +++ b/src/mame/drivers/nemesis.cpp @@ -2060,10 +2060,8 @@ void nemesis_state::salamand(machine_config &config) K007232(config, m_k007232, 3579545); m_k007232->port_write().set(FUNC(nemesis_state::volume_callback)); - m_k007232->add_route(0, "lspeaker", 0.08); - m_k007232->add_route(0, "rspeaker", 0.08); - m_k007232->add_route(1, "lspeaker", 0.08); - m_k007232->add_route(1, "rspeaker", 0.08); + m_k007232->add_route(ALL_OUTPUTS, "lspeaker", 0.08); + m_k007232->add_route(ALL_OUTPUTS, "rspeaker", 0.08); ym2151_device &ymsnd(YM2151(config, "ymsnd", 3579545)); // ymsnd.irq_handler().set_inputline(m_audiocpu, 0); ... Interrupts _are_ generated, I wonder where they go @@ -2101,10 +2099,8 @@ void nemesis_state::blkpnthr(machine_config &config) K007232(config, m_k007232, 3579545); m_k007232->port_write().set(FUNC(nemesis_state::volume_callback)); - m_k007232->add_route(0, "lspeaker", 0.10); - m_k007232->add_route(0, "rspeaker", 0.10); - m_k007232->add_route(1, "lspeaker", 0.10); - m_k007232->add_route(1, "rspeaker", 0.10); + m_k007232->add_route(ALL_OUTPUTS, "lspeaker", 0.10); + m_k007232->add_route(ALL_OUTPUTS, "rspeaker", 0.10); ym2151_device &ymsnd(YM2151(config, "ymsnd", 3579545)); // ymsnd.irq_handler().set_inputline(m_audiocpu, 0); ... Interrupts _are_ generated, I wonder where they go @@ -2138,26 +2134,20 @@ void nemesis_state::citybomb(machine_config &config) m_palette->set_membits(8); /* sound hardware */ - SPEAKER(config, "lspeaker").front_left(); - SPEAKER(config, "rspeaker").front_right(); + SPEAKER(config, "mono").front_center(); GENERIC_LATCH_8(config, "soundlatch"); K007232(config, m_k007232, 3579545); m_k007232->port_write().set(FUNC(nemesis_state::volume_callback)); - m_k007232->add_route(0, "lspeaker", 0.30); - m_k007232->add_route(0, "rspeaker", 0.30); - m_k007232->add_route(1, "lspeaker", 0.30); - m_k007232->add_route(1, "rspeaker", 0.30); + m_k007232->add_route(ALL_OUTPUTS, "mono", 0.30); ym3812_device &ym3812(YM3812(config, "ymsnd", 3579545)); // ym3812.irq_handler().set_inputline("audiocpu", 0); ... Interrupts _are_ generated, I wonder where they go - ym3812.add_route(ALL_OUTPUTS, "lspeaker", 1.0); - ym3812.add_route(ALL_OUTPUTS, "rspeaker", 1.0); + ym3812.add_route(ALL_OUTPUTS, "mono", 1.0); - k051649_device &k051649(K051649(config, "k051649", 3579545/2)); - k051649.add_route(ALL_OUTPUTS, "lspeaker", 0.38); - k051649.add_route(ALL_OUTPUTS, "rspeaker", 0.38); + k051649_device &k051649(K051649(config, "k051649", 3579545)); + k051649.add_route(ALL_OUTPUTS, "mono", 0.38); } void nemesis_state::nyanpani(machine_config &config) @@ -2183,26 +2173,20 @@ void nemesis_state::nyanpani(machine_config &config) m_palette->set_membits(8); /* sound hardware */ - SPEAKER(config, "lspeaker").front_left(); - SPEAKER(config, "rspeaker").front_right(); + SPEAKER(config, "mono").front_center(); GENERIC_LATCH_8(config, "soundlatch"); K007232(config, m_k007232, 3579545); m_k007232->port_write().set(FUNC(nemesis_state::volume_callback)); - m_k007232->add_route(0, "lspeaker", 0.30); - m_k007232->add_route(0, "rspeaker", 0.30); - m_k007232->add_route(1, "lspeaker", 0.30); - m_k007232->add_route(1, "rspeaker", 0.30); + m_k007232->add_route(ALL_OUTPUTS, "mono", 0.30); ym3812_device &ym3812(YM3812(config, "ymsnd", 3579545)); // ym3812.irq_handler().set_inputline("audiocpu", 0); ... Interrupts _are_ generated, I wonder where they go - ym3812.add_route(ALL_OUTPUTS, "lspeaker", 1.0); - ym3812.add_route(ALL_OUTPUTS, "rspeaker", 1.0); + ym3812.add_route(ALL_OUTPUTS, "mono", 1.0); - k051649_device &k051649(K051649(config, "k051649", 3579545/2)); - k051649.add_route(ALL_OUTPUTS, "lspeaker", 0.38); - k051649.add_route(ALL_OUTPUTS, "rspeaker", 0.38); + k051649_device &k051649(K051649(config, "k051649", 3579545)); + k051649.add_route(ALL_OUTPUTS, "mono", 0.38); } void nemesis_state::hcrash(machine_config &config) @@ -2248,10 +2232,8 @@ void nemesis_state::hcrash(machine_config &config) K007232(config, m_k007232, 3579545); m_k007232->port_write().set(FUNC(nemesis_state::volume_callback)); - m_k007232->add_route(0, "lspeaker", 0.10); - m_k007232->add_route(0, "rspeaker", 0.10); - m_k007232->add_route(1, "lspeaker", 0.10); - m_k007232->add_route(1, "rspeaker", 0.10); + m_k007232->add_route(ALL_OUTPUTS, "lspeaker", 0.10); + m_k007232->add_route(ALL_OUTPUTS, "rspeaker", 0.10); ym2151_device &ymsnd(YM2151(config, "ymsnd", 3579545)); // ymsnd.irq_handler().set_inputline(m_audiocpu, 0); ... Interrupts _are_ generated, I wonder where they go diff --git a/src/mame/drivers/quickpick5.cpp b/src/mame/drivers/quickpick5.cpp index b29d56b6861..7f3e443cdc1 100644 --- a/src/mame/drivers/quickpick5.cpp +++ b/src/mame/drivers/quickpick5.cpp @@ -614,12 +614,11 @@ void quickpick5_state::quickpick5(machine_config &config) /* sound hardware */ SPEAKER(config, "mono").front_center(); - K051649(config, m_k051649, XTAL(32'000'000)/18); // xtal is verified, divider is not + K051649(config, m_k051649, XTAL(32'000'000)/9); // xtal is verified, divider is not m_k051649->add_route(ALL_OUTPUTS, "mono", 0.45); OKIM6295(config, m_oki, XTAL(32'000'000)/18, okim6295_device::PIN7_HIGH); - m_oki->add_route(0, "mono", 1.0); - m_oki->add_route(1, "mono", 1.0); + m_oki->add_route(ALL_OUTPUTS, "mono", 1.0); } void quickpick5_state::waijockey(machine_config &config) diff --git a/src/mame/drivers/vgmplay.cpp b/src/mame/drivers/vgmplay.cpp index 9dc0edcf6f0..a9195086193 100644 --- a/src/mame/drivers/vgmplay.cpp +++ b/src/mame/drivers/vgmplay.cpp @@ -2982,9 +2982,12 @@ QUICKLOAD_LOAD_MEMBER(vgmplay_state::load_file) m_okim6295[0]->set_pin7(m_okim6295_pin7[0] ? okim6295_device::PIN7_HIGH : okim6295_device::PIN7_LOW); m_okim6295[1]->set_pin7(m_okim6295_pin7[1] ? okim6295_device::PIN7_HIGH : okim6295_device::PIN7_LOW); - if (setup_device(*m_k051649[0], 0, CT_K051649, 0x9c, 0x161) || - setup_device(*m_k051649[1], 1, CT_K051649, 0x9c, 0x161)) - osd_printf_warning("Warning: file requests an unsupported Konami SCC\n"); + setup_device(*m_k051649[0], 0, CT_K051649, 0x9c, 0x161); + setup_device(*m_k051649[1], 1, CT_K051649, 0x9c, 0x161); + + // HACK: Some VGMs contain the halved clock speed of the sound core inside the SCC + m_k051649[0]->set_clock_scale(m_k051649[0]->unscaled_clock() < 2097152 ? 2.0 : 1.0); + m_k051649[1]->set_clock_scale(m_k051649[1]->unscaled_clock() < 2097152 ? 2.0 : 1.0); setup_device(*m_k054539[0], 0, CT_K054539, 0xa0, 0x161); setup_device(*m_k054539[1], 1, CT_K054539, 0xa0, 0x161); -- cgit v1.2.3