summaryrefslogtreecommitdiffstats
path: root/src/emu/sound/flt_vol.c
blob: eac2ca7ac7a0b29ebd03036c5ed97f1ad0f3349c (plain) (blame)
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
#include "emu.h"
#include "flt_vol.h"


// device type definition
const device_type FILTER_VOLUME = &device_creator<filter_volume_device>;

//-------------------------------------------------
//  qsound_device - constructor
//-------------------------------------------------

filter_volume_device::filter_volume_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, FILTER_VOLUME, "Volume Filter", tag, owner, clock),
		device_sound_interface(mconfig, *this),
		m_stream(NULL),
		m_gain(0)
{
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void filter_volume_device::device_start()
{
	m_gain = 0x100;
	m_stream = stream_alloc(1, 1, machine().sample_rate());
}


//-------------------------------------------------
//  sound_stream_update - handle a stream update
//-------------------------------------------------

void filter_volume_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
	stream_sample_t *src = inputs[0];
	stream_sample_t *dst = outputs[0];

	while (samples--)
		*dst++ = (*src++ * m_gain) >> 8;
}



void filter_volume_device::flt_volume_set_volume(float volume)
{
	m_gain = (int)(volume * 256);
}