From 04956ee6779037e52cbfd971581618ab0f2f200f Mon Sep 17 00:00:00 2001 From: mooglyguy Date: Sat, 23 Nov 2019 17:25:28 +0100 Subject: -multipcm: Added optional compile-time sample logging. [Ryan Holtz] --- src/devices/sound/multipcm.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/devices/sound/multipcm.h | 11 +++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/devices/sound/multipcm.cpp b/src/devices/sound/multipcm.cpp index 2d3315c2c4b..285b6ade701 100644 --- a/src/devices/sound/multipcm.cpp +++ b/src/devices/sound/multipcm.cpp @@ -35,6 +35,7 @@ #include "emu.h" #include "multipcm.h" +#include "wavwrite.h" ALLOW_SAVE_TYPE(multipcm_device::state_t); // allow save_item on a non-fundamental type @@ -368,6 +369,10 @@ void multipcm_device::write_slot(slot_t &slot, int32_t reg, uint8_t data) envelope_generator_calc(slot); slot.m_envelope_gen.m_state = state_t::ATTACK; slot.m_envelope_gen.m_volume = 0; + +#if MULTIPCM_LOG_SAMPLES + dump_sample(slot); +#endif } else { @@ -639,6 +644,38 @@ int16_t multipcm_device::clamp_to_int16(int32_t value) return (int16_t)value; } +#if MULTIPCM_LOG_SAMPLES +void multipcm_device::dump_sample(slot_t &slot) +{ + if (m_logged_map[slot.m_base]) + return; + + m_logged_map[slot.m_base] = true; + + char filebuf[256]; + snprintf(filebuf, 256, "multipcm%08x.wav", slot.m_base); + wav_file *file = wav_open(filebuf, m_stream->sample_rate(), 1); + if (file == nullptr) + return; + + uint32_t offset = slot.m_offset; + bool done = false; + while (!done) + { + int16_t sample = (int16_t) (read_byte(slot.m_base + (offset >> TL_SHIFT)) << 8); + wav_add_data_16(file, &sample, 1); + + offset += 1 << TL_SHIFT; + if (offset >= (slot.m_sample.m_end << TL_SHIFT)) + { + done = true; + } + } + + wav_close(file); +} +#endif + //------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- diff --git a/src/devices/sound/multipcm.h b/src/devices/sound/multipcm.h index abfa8b7c1b9..3f888b8b021 100644 --- a/src/devices/sound/multipcm.h +++ b/src/devices/sound/multipcm.h @@ -5,6 +5,12 @@ #pragma once +#define MULTIPCM_LOG_SAMPLES 0 + +#if MULTIPCM_LOG_SAMPLES +#include +#endif + class multipcm_device : public device_t, public device_sound_interface, public device_rom_interface @@ -130,6 +136,11 @@ private: int16_t clamp_to_int16(int32_t value); +#if MULTIPCM_LOG_SAMPLES + void dump_sample(slot_t &slot); + std::map m_logged_map; +#endif + static constexpr uint32_t TL_SHIFT = 12; static const int32_t VALUE_TO_CHANNEL[32]; -- cgit v1.2.3