summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/speaker.cpp
blob: d57f9119c2433d830d0cfeb4f16333092987d5d1 (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
93
94
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************

    speaker.cpp

    Speaker output sound device.
    Microphone input sound device.

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

#include "emu.h"
#include "emuopts.h"
#include "speaker.h"



DEFINE_DEVICE_TYPE(SPEAKER, speaker_device, "speaker", "Speaker")
DEFINE_DEVICE_TYPE(MICROPHONE, microphone_device, "microphone", "Microphone")

const sound_io_device::position_name_mapping sound_io_device::position_name_mappings[] = {
	{  0.0,  0.0,  1.0, "Front center" },
	{ -0.2,  0.0,  1.0, "Front left"   },
	{  0.0, -0.5,  1.0, "Front floor" },
	{  0.2,  0.0,  1.0, "Front right" },
	{  0.0,  0.0, -0.5, "Rear center" },
	{ -0.2,  0.0, -0.5, "Rear left" },
	{  0.2,  0.0, -0.5, "Read right" },
	{  0.0,  0.0, -0.1, "Headrest center" },
	{ -0.1,  0.0, -0.1, "Headrest left" },
	{  0.1,  0.0, -0.1, "Headrest right" },
	{  0.0, -0.5,  0.0, "Seat" },
	{  0.0, -0.2,  0.1, "Backrest" },
	{ }
};

std::string sound_io_device::get_position_name(u32 channel) const
{
	for(unsigned int i = 0; position_name_mappings[i].m_name; i++)
		if(m_positions[channel][0] == position_name_mappings[i].m_x && m_positions[channel][1] == position_name_mappings[i].m_y && m_positions[channel][2] == position_name_mappings[i].m_z)
			return position_name_mappings[i].m_name;
	return util::string_format("#%d", channel);
}

sound_io_device &sound_io_device::set_position(u32 channel, double x, double y, double z)
{
	if(channel >= m_positions.size())
		fatalerror("%s: Requested channel %d on %d channel device\n", tag(), channel, m_positions.size());
	m_positions[channel][0] = x;
	m_positions[channel][1] = y;
	m_positions[channel][2] = z;
	return *this;
}

sound_io_device::sound_io_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 channels) :
	device_t(mconfig, type, tag, owner, 0),
	device_sound_interface(mconfig, *this),
	m_positions(channels ? channels : 1)
{
}


sound_io_device::~sound_io_device()
{
}

speaker_device::~speaker_device()
{
}

microphone_device::~microphone_device()
{
}


void speaker_device::device_start()
{
	m_stream = stream_alloc(m_positions.size(), 0, machine().sample_rate());
}

void microphone_device::device_start()
{
	m_stream = stream_alloc(0, m_positions.size(), machine().sample_rate());
}

void speaker_device::sound_stream_update(sound_stream &stream)
{
	machine().sound().output_push(m_id, stream);
}

void microphone_device::sound_stream_update(sound_stream &stream)
{
	machine().sound().input_get(m_id, stream);
}