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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// license:BSD-3-Clause
// copyright-holders:Juergen Buchmueller
#include "emu.h"
#include "tms3615.h"
const int tms3615_device::divisor[TMS3615_TONES] = { 478, 451, 426, 402, 379, 358, 338, 319, 301, 284, 268, 253, 239 };
// device type definition
DEFINE_DEVICE_TYPE(TMS3615, tms3615_device, "tms3615", "TMS3615")
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// tms3615_device - constructor
//-------------------------------------------------
tms3615_device::tms3615_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, TMS3615, tag, owner, clock)
, device_sound_interface(mconfig, *this)
, m_channel(nullptr)
, m_samplerate(0)
, m_basefreq(0)
, m_output8(0)
, m_output16(0)
, m_enable(0)
{
std::fill(std::begin(m_counter8), std::end(m_counter8), 0);
std::fill(std::begin(m_counter16), std::end(m_counter16), 0);
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void tms3615_device::device_start()
{
m_channel = stream_alloc(0, 2, clock()/8);
m_samplerate = clock()/8;
m_basefreq = clock();
}
//-------------------------------------------------
// sound_stream_update_legacy - handle a stream update
//-------------------------------------------------
void tms3615_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
auto &buffer8 = outputs[FOOTAGE_8];
auto &buffer16 = outputs[FOOTAGE_16];
int samplerate = buffer8.sample_rate();
constexpr stream_buffer::sample_t VMAX = 1.0f / stream_buffer::sample_t(TMS3615_TONES);
while (!buffer8.done())
{
stream_buffer::sample_t sum8 = 0, sum16 = 0;
for (int tone = 0; tone < TMS3615_TONES; tone++)
{
// 8'
m_counter8[tone] -= (m_basefreq / divisor[tone]);
while( m_counter8[tone] <= 0 )
{
m_counter8[tone] += samplerate;
m_output8 ^= 1 << tone;
}
if (m_output8 & m_enable & (1 << tone))
{
sum8 += VMAX;
}
// 16'
m_counter16[tone] -= (m_basefreq / divisor[tone] / 2);
while( m_counter16[tone] <= 0 )
{
m_counter16[tone] += samplerate;
m_output16 ^= 1 << tone;
}
if (m_output16 & m_enable & (1 << tone))
{
sum16 += VMAX;
}
}
buffer8.put(sum8);
buffer16.put(sum16);
}
}
void tms3615_device::enable_w(int enable)
{
m_enable = enable;
}
|