diff options
author | 2025-04-14 11:31:53 +0200 | |
---|---|---|
committer | 2025-04-14 22:28:31 +0200 | |
commit | cef6157803320544651bfc96457d2f8a6df0abd6 (patch) | |
tree | f8a64867e3d654cdcad5f4c24824ea82e2c77194 /src/devices/sound/adc.cpp | |
parent | 9473c027358e1a2d5c93d240a48052368f9d3b84 (diff) |
New sound infrastructure.sound
Should be added soon:
- mute
- lua hookup (with documentation)
- 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") |