1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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")
|