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
|
// license:BSD-3-Clause
// copyright-holders:Derrick Renaud, Couriersud
#include "emu.h"
#include "flt_vol.h"
// device type definition
DEFINE_DEVICE_TYPE(FILTER_VOLUME, filter_volume_device, "filter_volume", "Volume Filter")
//-------------------------------------------------
// filter_volume_device - constructor
//-------------------------------------------------
filter_volume_device::filter_volume_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock) :
device_t(mconfig, FILTER_VOLUME, tag, owner, clock),
device_sound_interface(mconfig, *this),
m_stream(nullptr),
m_gain(0)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void filter_volume_device::device_start()
{
m_gain = 1.0;
m_stream = stream_alloc(1, 1, SAMPLE_RATE_OUTPUT_ADAPTIVE);
save_item(NAME(m_gain));
}
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
void filter_volume_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
for (int i = 0; i < outputs[0].samples(); i++)
outputs[0].put(i, inputs[0].get(i) * m_gain);
}
void filter_volume_device::flt_volume_set_volume(float volume)
{
m_stream->update();
m_gain = volume;
}
|