summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices
diff options
context:
space:
mode:
authorGravatarGravatar mooglyguy <therealmogminer@gmail.com>2019-11-23 17:25:28 +0100
committerGravatarGravatar mooglyguy <therealmogminer@gmail.com>2019-11-23 17:25:47 +0100
commit04956ee6779037e52cbfd971581618ab0f2f200f (patch)
tree2b853e4533a86f4cc764b54d81e70bd0da40a1bb /src/devices
parent8637500ca53ce789d2f0dac81cd91b268fde2d94 (diff)
-multipcm: Added optional compile-time sample logging. [Ryan Holtz]
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/sound/multipcm.cpp37
-rw-r--r--src/devices/sound/multipcm.h11
2 files changed, 48 insertions, 0 deletions
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 <map>
+#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<uint32_t, bool> m_logged_map;
+#endif
+
static constexpr uint32_t TL_SHIFT = 12;
static const int32_t VALUE_TO_CHANNEL[32];