summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/speaker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/speaker.cpp')
-rw-r--r--src/emu/speaker.cpp154
1 files changed, 58 insertions, 96 deletions
diff --git a/src/emu/speaker.cpp b/src/emu/speaker.cpp
index de2ad1127a0..d57f9119c24 100644
--- a/src/emu/speaker.cpp
+++ b/src/emu/speaker.cpp
@@ -5,128 +5,90 @@
speaker.cpp
Speaker output sound device.
+ Microphone input sound device.
***************************************************************************/
#include "emu.h"
+#include "emuopts.h"
#include "speaker.h"
-//**************************************************************************
-// GLOBAL VARIABLES
-//**************************************************************************
-
-// device type definition
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;
+}
-
-//**************************************************************************
-// LIVE SPEAKER DEVICE
-//**************************************************************************
-
-//-------------------------------------------------
-// speaker_device - constructor
-//-------------------------------------------------
-
-speaker_device::speaker_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
- : device_t(mconfig, SPEAKER, tag, owner, clock)
- , device_mixer_interface(mconfig, *this)
- , m_x(0.0)
- , m_y(0.0)
- , m_z(0.0)
-#ifdef MAME_DEBUG
- , m_max_sample(0)
- , m_clipped_samples(0)
- , m_total_samples(0)
-#endif
+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)
{
}
-//-------------------------------------------------
-// ~speaker_device - destructor
-//-------------------------------------------------
+sound_io_device::~sound_io_device()
+{
+}
speaker_device::~speaker_device()
{
-#ifdef MAME_DEBUG
- // log the maximum sample values for all speakers
- if (m_max_sample > 0)
- osd_printf_debug("Speaker \"%s\" - max = %d (gain *= %f) - %d%% samples clipped\n", tag(), m_max_sample, 32767.0 / (m_max_sample ? m_max_sample : 1), (int)((double)m_clipped_samples * 100.0 / m_total_samples));
-#endif
}
+microphone_device::~microphone_device()
+{
+}
-//-------------------------------------------------
-// mix - mix in samples from the speaker's stream
-//-------------------------------------------------
-void speaker_device::mix(s32 *leftmix, s32 *rightmix, int &samples_this_update, bool suppress)
+void speaker_device::device_start()
{
- // skip if no stream
- if (m_mixer_stream == nullptr)
- return;
-
- // update the stream, getting the start/end pointers around the operation
- int numsamples;
- const stream_sample_t *stream_buf = m_mixer_stream->output_since_last_update(0, numsamples);
-
- // set or assert that all streams have the same count
- if (samples_this_update == 0)
- {
- samples_this_update = numsamples;
-
- // reset the mixing streams
- memset(leftmix, 0, samples_this_update * sizeof(*leftmix));
- memset(rightmix, 0, samples_this_update * sizeof(*rightmix));
- }
- assert(samples_this_update == numsamples);
-
-#ifdef MAME_DEBUG
- // debug version: keep track of the maximum sample
- for (int sample = 0; sample < samples_this_update; sample++)
- {
- if (stream_buf[sample] > m_max_sample)
- m_max_sample = stream_buf[sample];
- else if (-stream_buf[sample] > m_max_sample)
- m_max_sample = -stream_buf[sample];
- if (stream_buf[sample] > 32767 || stream_buf[sample] < -32768)
- m_clipped_samples++;
- m_total_samples++;
- }
-#endif
-
- // mix if sound is enabled
- if (!suppress)
- {
- // if the speaker is centered, send to both left and right
- if (m_x == 0)
- for (int sample = 0; sample < samples_this_update; sample++)
- {
- leftmix[sample] += stream_buf[sample];
- rightmix[sample] += stream_buf[sample];
- }
-
- // if the speaker is to the left, send only to the left
- else if (m_x < 0)
- for (int sample = 0; sample < samples_this_update; sample++)
- leftmix[sample] += stream_buf[sample];
-
- // if the speaker is to the right, send only to the right
- else
- for (int sample = 0; sample < samples_this_update; sample++)
- rightmix[sample] += stream_buf[sample];
- }
+ 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());
+}
-//-------------------------------------------------
-// device_start - handle device startup
-//-------------------------------------------------
+void speaker_device::sound_stream_update(sound_stream &stream)
+{
+ machine().sound().output_push(m_id, stream);
+}
-void speaker_device::device_start()
+void microphone_device::sound_stream_update(sound_stream &stream)
{
- // dummy save to make device.c happy
+ machine().sound().input_get(m_id, stream);
}