fmod/core/channel_control/
panning.rs

1// Copyright (c) 2024 Lily Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use std::ffi::c_float;
8
9use fmod_sys::*;
10
11use crate::ChannelControl;
12
13impl ChannelControl {
14    /// Sets the left/right pan level.
15    ///
16    /// This is a convenience function to avoid passing a matrix, it will overwrite values set via ChannelControl::setMixLevelsInput,
17    /// ChannelControl::setMixLevelsOutput and ChannelControl::setMixMatrix.
18    ///
19    /// Mono inputs are panned from left to right using constant power panning (non linear fade).
20    ///  Stereo and greater inputs will isolate the front left and right input channels and fade them up and down based on the pan value (silencing other channels).
21    /// The output channel count will always match the System speaker mode set via System::setSoftwareFormat.
22    ///
23    /// If the System is initialized with FMOD_SPEAKERMODE_RAW calling this function will produce silence.
24    pub fn set_pan(&self, pan: c_float) -> Result<()> {
25        unsafe { FMOD_ChannelControl_SetPan(self.inner, pan).to_result() }
26    }
27
28    /// Sets the incoming volume level for each channel of a multi-channel signal.
29    ///
30    /// This is a convenience function to avoid passing a matrix, it will overwrite values set via ChannelControl::setPan,
31    /// ChannelControl::setMixLevelsOutput and ChannelControl::setMixMatrix.
32    ///
33    /// #### NOTE: Currently only supported for Channel, not ChannelGroup.
34    pub fn set_mix_levels_input(&self, levels: &mut [c_float]) -> Result<()> {
35        // probably shouldn't be mutable but it's more safe that way?
36        // FIXME do we need to enforce a max length?
37        unsafe {
38            FMOD_ChannelControl_SetMixLevelsInput(
39                self.inner,
40                levels.as_mut_ptr(),
41                levels.len() as i32,
42            )
43            .to_result()
44        }
45    }
46
47    /// Sets the outgoing volume levels for each speaker.
48    ///
49    /// Specify the level for a given output speaker, if the channel count of the input and output do not match,
50    /// channels will be up/down mixed as appropriate to approximate the given speaker values.
51    /// For example stereo input with 5.1 output will use the center parameter to distribute signal to the center speaker from front left and front right channels.
52    ///
53    /// This is a convenience function to avoid passing a matrix, it will overwrite values set via ChannelControl::setPan, ChannelControl::setMixLevelsInput and ChannelControl::setMixMatrix.
54    ///
55    /// The output channel count will always match the System speaker mode set via System::setSoftwareFormat.
56    ///
57    /// If the System is initialized with FMOD_SPEAKERMODE_RAW calling this function will produce silence.
58    #[allow(clippy::too_many_arguments)] // no fixing this
59    pub fn set_mix_levels_output(
60        &self,
61        front_left: c_float,
62        front_right: c_float,
63        center: c_float,
64        lfe: c_float,
65        surround_left: c_float,
66        surround_right: c_float,
67        back_left: c_float,
68        back_right: c_float,
69    ) -> Result<()> {
70        unsafe {
71            FMOD_ChannelControl_SetMixLevelsOutput(
72                self.inner,
73                front_left,
74                front_right,
75                center,
76                lfe,
77                surround_left,
78                surround_right,
79                back_left,
80                back_right,
81            )
82            .to_result()
83        }
84    }
85
86    // TODO: mix matrix
87}