-multipcm: Added optional compile-time sample logging. [Ryan Holtz]

This commit is contained in:
mooglyguy 2019-11-23 17:25:28 +01:00
parent 8637500ca5
commit 04956ee677
2 changed files with 48 additions and 0 deletions

View File

@ -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
//-------------------------------------------------

View File

@ -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];