diff options
| author | 2023-09-09 21:19:24 +0200 | |
|---|---|---|
| committer | 2023-09-09 21:19:35 +0200 | |
| commit | 688d6e212814ad041c2d382020bf320c2dafabbf (patch) | |
| tree | a1fc1857438709c50b90aecdf35102c066ab71ba /src/emu/speaker.cpp | |
| parent | 80615f2ea9a3008db0c6332a908bc43c00610e61 (diff) | |
sound: add configurable speaker panning
Diffstat (limited to 'src/emu/speaker.cpp')
| -rw-r--r-- | src/emu/speaker.cpp | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/src/emu/speaker.cpp b/src/emu/speaker.cpp index 3cbb14355a4..0755aab5af3 100644 --- a/src/emu/speaker.cpp +++ b/src/emu/speaker.cpp @@ -37,6 +37,8 @@ speaker_device::speaker_device(const machine_config &mconfig, const char *tag, d , m_x(0.0) , m_y(0.0) , m_z(0.0) + , m_pan(1.0) + , m_defpan(1.0) , m_current_max(0) , m_samples_this_bucket(0) { @@ -53,6 +55,35 @@ speaker_device::~speaker_device() //------------------------------------------------- +// set_position - set speaker position +//------------------------------------------------- + +speaker_device &speaker_device::set_position(double x, double y, double z) +{ + // as mentioned in the header file, y and z params currently have no effect + m_x = x; + m_y = y; + m_z = z; + + // hard pan to left + if (m_x < 0.0) + set_pan(0.0f); + + // hard pan to right + else if (m_x > 0.0) + set_pan(2.0f); + + // center (mono) + else + set_pan(1.0f); + + m_defpan = m_pan; + + return *this; +} + + +//------------------------------------------------- // mix - mix in samples from the speaker's stream //------------------------------------------------- @@ -89,24 +120,29 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample // mix if sound is enabled if (!suppress) { - // if the speaker is centered, send to both left and right - if (m_x == 0) + // if the speaker is hard panned to the left, send only to the left + if (m_pan == 0.0f) for (int sample = 0; sample < expected_samples; sample++) - { - stream_buffer::sample_t cursample = view.get(sample); - leftmix[sample] += cursample; - rightmix[sample] += cursample; - } + leftmix[sample] += view.get(sample); - // if the speaker is to the left, send only to the left - else if (m_x < 0) + // if the speaker is hard panned to the right, send only to the right + else if (m_pan == 2.0f) for (int sample = 0; sample < expected_samples; sample++) - leftmix[sample] += view.get(sample); + rightmix[sample] += view.get(sample); - // if the speaker is to the right, send only to the right + // otherwise, send to both else + { + const float leftpan = (m_pan <= 1.0f) ? 1.0f : 2.0f - m_pan; + const float rightpan = (m_pan >= 1.0f) ? 1.0f : m_pan; + for (int sample = 0; sample < expected_samples; sample++) - rightmix[sample] += view.get(sample); + { + stream_buffer::sample_t cursample = view.get(sample); + leftmix[sample] += cursample * leftpan; + rightmix[sample] += cursample * rightpan; + } + } } } @@ -117,7 +153,6 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample void speaker_device::device_start() { - // dummy save to make device.c happy } @@ -187,4 +222,3 @@ void speaker_device::device_stop() } } } - |
