diff options
author | 2025-04-14 11:31:53 +0200 | |
---|---|---|
committer | 2025-04-27 22:23:20 +0200 | |
commit | d0f1c15a0f6df2dd51a754cb46e6175b7079c8f2 (patch) | |
tree | be35c94340442af08c316a8679089ee68e119fac /src/devices/sound/adc.cpp | |
parent | ec636faeba5c5841c5a4a35b7c9dc2f06a00f538 (diff) |
New sound infrastructure.
Should be added soon:
- mute
- speaker/microphone resampling
To be added a little later:
- compression
- reverb
Needs to be added by someone else:
- coreaudio
- direct
- portaudio
- xaudio2
- js
Diffstat (limited to 'src/devices/sound/adc.cpp')
-rw-r--r-- | src/devices/sound/adc.cpp | 66 |
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") |