summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/okim6295.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/sound/okim6295.cpp')
-rw-r--r--src/devices/sound/okim6295.cpp90
1 files changed, 47 insertions, 43 deletions
diff --git a/src/devices/sound/okim6295.cpp b/src/devices/sound/okim6295.cpp
index 10375f7736a..d4006fea1da 100644
--- a/src/devices/sound/okim6295.cpp
+++ b/src/devices/sound/okim6295.cpp
@@ -2,7 +2,7 @@
// copyright-holders:Mirko Buffoni,Aaron Giles
/***************************************************************************
- okim6295.h
+ okim6295.cpp
OKIM 6295 ADCPM sound chip.
@@ -56,24 +56,24 @@ DEFINE_DEVICE_TYPE(OKIM6295, okim6295_device, "okim6295", "OKI MSM6295 ADPCM")
// volume lookup table. The manual lists only 9 steps, ~3dB per step. Given the dB values,
// that seems to map to a 5-bit volume control. Any volume parameter beyond the 9th index
// results in silent playback.
-const uint8_t okim6295_device::s_volume_table[16] =
+const stream_buffer::sample_t okim6295_device::s_volume_table[16] =
{
- 0x20, // 0 dB
- 0x16, // -3.2 dB
- 0x10, // -6.0 dB
- 0x0b, // -9.2 dB
- 0x08, // -12.0 dB
- 0x06, // -14.5 dB
- 0x04, // -18.0 dB
- 0x03, // -20.5 dB
- 0x02, // -24.0 dB
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
+ stream_buffer::sample_t(0x20) / stream_buffer::sample_t(0x20), // 0 dB
+ stream_buffer::sample_t(0x16) / stream_buffer::sample_t(0x20), // -3.2 dB
+ stream_buffer::sample_t(0x10) / stream_buffer::sample_t(0x20), // -6.0 dB
+ stream_buffer::sample_t(0x0b) / stream_buffer::sample_t(0x20), // -9.2 dB
+ stream_buffer::sample_t(0x08) / stream_buffer::sample_t(0x20), // -12.0 dB
+ stream_buffer::sample_t(0x06) / stream_buffer::sample_t(0x20), // -14.5 dB
+ stream_buffer::sample_t(0x04) / stream_buffer::sample_t(0x20), // -18.0 dB
+ stream_buffer::sample_t(0x03) / stream_buffer::sample_t(0x20), // -20.5 dB
+ stream_buffer::sample_t(0x02) / stream_buffer::sample_t(0x20), // -24.0 dB
+ stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20),
+ stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20),
+ stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20),
+ stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20),
+ stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20),
+ stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20),
+ stream_buffer::sample_t(0x00) / stream_buffer::sample_t(0x20),
};
@@ -85,14 +85,14 @@ const uint8_t okim6295_device::s_volume_table[16] =
// okim6295_device - constructor
//-------------------------------------------------
-okim6295_device::okim6295_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
- : device_t(mconfig, OKIM6295, tag, owner, clock),
- device_sound_interface(mconfig, *this),
- device_rom_interface(mconfig, *this, 18),
- m_region(*this, DEVICE_SELF),
- m_command(-1),
- m_stream(nullptr),
- m_pin7_state(~uint8_t(0))
+okim6295_device::okim6295_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
+ device_t(mconfig, OKIM6295, tag, owner, clock),
+ device_sound_interface(mconfig, *this),
+ device_rom_interface(mconfig, *this),
+ m_region(*this, DEVICE_SELF),
+ m_command(-1),
+ m_stream(nullptr),
+ m_pin7_state(~uint8_t(0))
{
}
@@ -118,7 +118,7 @@ void okim6295_device::device_start()
// create the stream
int divisor = m_pin7_state ? 132 : 165;
- m_stream = machine().sound().stream_alloc(*this, 0, 1, clock() / divisor);
+ m_stream = stream_alloc(0, 1, clock() / divisor);
save_item(NAME(m_command));
save_item(NAME(m_pin7_state));
@@ -171,26 +171,30 @@ void okim6295_device::device_clock_changed()
//-------------------------------------------------
-// stream_generate - handle update requests for
+// sound_stream_update - handle update requests for
// our sound stream
//-------------------------------------------------
-void okim6295_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
+void okim6295_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
// reset the output stream
- memset(outputs[0], 0, samples * sizeof(*outputs[0]));
+ outputs[0].fill(0);
// iterate over voices and accumulate sample data
for (auto & elem : m_voice)
- elem.generate_adpcm(*this, outputs[0], samples);
+ elem.generate_adpcm(*this, outputs[0]);
+
+ for (int i = 0; i < outputs[0].samples(); i++)
+ outputs[0].put(i, std::clamp(outputs[0].getraw(i), -1.0f, 1.0f));
}
//-------------------------------------------------
-// rom_bank_updated - the rom bank has changed
+// rom_bank_pre_change - refresh the stream if the
+// ROM banking changes
//-------------------------------------------------
-void okim6295_device::rom_bank_updated()
+void okim6295_device::rom_bank_pre_change()
{
m_stream->update();
}
@@ -322,12 +326,12 @@ void okim6295_device::write(uint8_t command)
// okim_voice - constructor
//-------------------------------------------------
-okim6295_device::okim_voice::okim_voice()
- : m_playing(false),
- m_base_offset(0),
- m_sample(0),
- m_count(0),
- m_volume(0)
+okim6295_device::okim_voice::okim_voice() :
+ m_playing(false),
+ m_base_offset(0),
+ m_sample(0),
+ m_count(0),
+ m_volume(0)
{
}
@@ -337,21 +341,21 @@ okim6295_device::okim_voice::okim_voice()
// add them to an output stream
//-------------------------------------------------
-void okim6295_device::okim_voice::generate_adpcm(device_rom_interface &rom, stream_sample_t *buffer, int samples)
+void okim6295_device::okim_voice::generate_adpcm(device_rom_interface &rom, write_stream_view &buffer)
{
// skip if not active
if (!m_playing)
return;
// loop while we still have samples to generate
- while (samples-- != 0)
+ for (int sampindex = 0; sampindex < buffer.samples(); sampindex++)
{
// fetch the next sample byte
int nibble = rom.read_byte(m_base_offset + m_sample / 2) >> (((m_sample & 1) << 2) ^ 4);
// output to the buffer, scaling by the volume
- // signal in range -2048..2047, volume in range 2..32 => signal * volume / 2 in range -32768..32767
- *buffer++ += m_adpcm.clock(nibble) * m_volume / 2;
+ // signal in range -2048..2047
+ buffer.add_int(sampindex, m_adpcm.clock(nibble) * m_volume, 2048);
// next!
if (++m_sample >= m_count)