summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/adc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/sound/adc.cpp')
-rw-r--r--src/devices/sound/adc.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/devices/sound/adc.cpp b/src/devices/sound/adc.cpp
new file mode 100644
index 00000000000..3f2ee0b3175
--- /dev/null
+++ b/src/devices/sound/adc.cpp
@@ -0,0 +1,66 @@
+// license:BSD-3-Clause
+// copyright-holders: Olivier Galibert
+
+// ADCs, unsigned or signed two-complement
+
+#include "emu.h"
+#include "adc.h"
+
+
+zn449_device::zn449_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+ : device_t(mconfig, ZN449, tag, owner, clock),
+ device_sound_interface(mconfig, *this),
+ m_stream(nullptr),
+ m_current_value(0)
+{
+}
+
+u8 zn449_device::read()
+{
+ m_stream->update();
+ return m_current_value;
+}
+
+void zn449_device::device_start()
+{
+ save_item(NAME(m_current_value));
+ m_stream = stream_alloc(1, 0, SAMPLE_RATE_INPUT_ADAPTIVE);
+}
+
+void zn449_device::sound_stream_update(sound_stream &stream)
+{
+ sound_stream::sample_t last_sample = stream.get(0, stream.samples()-1);
+ m_current_value = 128 * last_sample + 128;
+}
+
+DEFINE_DEVICE_TYPE(ZN449, zn449_device, "zn449", "ZN449 ADC")
+
+
+
+adc10_device::adc10_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+ : device_t(mconfig, ADC10, tag, owner, clock),
+ device_sound_interface(mconfig, *this),
+ m_stream(nullptr),
+ m_current_value(0)
+{
+}
+
+u16 adc10_device::read()
+{
+ m_stream->update();
+ return m_current_value;
+}
+
+void adc10_device::device_start()
+{
+ save_item(NAME(m_current_value));
+ m_stream = stream_alloc(1, 0, SAMPLE_RATE_INPUT_ADAPTIVE);
+}
+
+void adc10_device::sound_stream_update(sound_stream &stream)
+{
+ sound_stream::sample_t last_sample = stream.get(0, stream.samples()-1);
+ m_current_value = std::clamp(int(512 * last_sample), -512, 511);
+}
+
+DEFINE_DEVICE_TYPE(ADC10, adc10_device, "adc10", "10-bits signed ADC")