summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/dac.cpp
blob: d51b51c1410e8118892f24a4dea894f0fba73a69 (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
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
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************

    dac.c

    DAC device emulator.

***************************************************************************/

#include "emu.h"
#include "dac.h"


// device type definition
const device_type DAC = &device_creator<dac_device>;


//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  dac_device - constructor
//-------------------------------------------------

dac_device::dac_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, DAC, "DAC", tag, owner, clock, "dac", __FILE__),
		device_sound_interface(mconfig, *this),
		m_stream(nullptr),
		m_output(0)
{
}


//-------------------------------------------------
//  write_unsigned8 - write an 8-bit value,
//  keeping the scaled result unsigned
//-------------------------------------------------

WRITE8_MEMBER( dac_device::write_unsigned8 )
{
	write_unsigned8(data);
}


//-------------------------------------------------
//  write_signed8 - write an 8-bit value,
//  keeping the scaled result signed
//-------------------------------------------------

WRITE8_MEMBER( dac_device::write_signed8 )
{
	write_signed8(data);
}


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

void dac_device::device_start()
{
	// create the stream
	m_stream = stream_alloc(0, 1, DEFAULT_SAMPLE_RATE);

	// register for save states
	save_item(NAME(m_output));
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void dac_device::device_reset()
{
	m_output = 0;
}


//-------------------------------------------------
//  sound_stream_update - handle update requests
//  for our sound stream
//-------------------------------------------------

void dac_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
	// just fill with current value
	for (int samp = 0; samp < samples; samp++)
		outputs[0][samp] = m_output;
}