pub struct Channel { /* private fields */ }
Expand description
A source of audio signal that connects to the ChannelGroup
mixing hierarchy.
Create with System::play_sound
or System::play_dsp
.
Implementations§
Source§impl Channel
impl Channel
Sourcepub fn is_virtual(&self) -> Result<bool>
pub fn is_virtual(&self) -> Result<bool>
Retrieves whether the Channel is being emulated by the virtual voice system.
See the Virtual Voices guide for more information.
Sourcepub fn get_current_sound(&self) -> Result<Option<Sound>>
pub fn get_current_sound(&self) -> Result<Option<Sound>>
Source§impl Channel
impl Channel
Sourcepub fn set_frequency(&self, frequency: c_float) -> Result<()>
pub fn set_frequency(&self, frequency: c_float) -> Result<()>
Sets the frequency or playback rate.
Default frequency is determined by the audio format of the Sound or DSP.
Sounds opened as Mode::CREATE_SAMPLE
(not Mode::CREATE_STREAM
or Mode::CREATE_COMPRESSED_SAMPLE
) can be played backwards by giving a negative frequency.
Sourcepub fn get_frequency(&self) -> Result<c_float>
pub fn get_frequency(&self) -> Result<c_float>
Retrieves the playback frequency or playback rate.
Sourcepub fn set_priority(&self, priority: c_int) -> Result<()>
pub fn set_priority(&self, priority: c_int) -> Result<()>
Sets the priority used for virtual voice ordering.
Priority is used as a coarse grain control for the virtual voice system, lower priority Channel
s will always be stolen before higher ones.
For Channel
s of equal priority, those with the quietest ChannelControl::get_audibility
value will be stolen first.
See the Virtual Voices guide for more information.
Sourcepub fn get_priority(&self) -> Result<c_int>
pub fn get_priority(&self) -> Result<c_int>
Retrieves the priority used for virtual voice ordering.
Priority is used as a coarse grain control for the virtual voice system, lower priority Channel
s will always be stolen before higher ones.
For Channel
s of equal priority, those with the quietest ChannelControl::get_audibility
value will be stolen first.
See the Virtual Voices guide for more information.
Sourcepub fn set_position(&self, position: c_uint, time_unit: TimeUnit) -> Result<()>
pub fn set_position(&self, position: c_uint, time_unit: TimeUnit) -> Result<()>
Sets the current playback position.
Certain TimeUnit
types are always available: TimeUnit::PCM
, TimeUnit::PCMBytes
and TimeUnit::MS
.
The others are format specific such as TimeUnit::ModOrder
/ TimeUnit::ModRow
/ TimeUnit::ModPattern
which is specific to files of type MOD / S3M / XM / IT.
If playing a Sound created with System::create_stream
or Mode::CREATE_STREAM
changing the position may cause a slow reflush operation while the file seek and decode occurs.
You can avoid this by creating the stream with Mode::NONBLOCKING
.
This will cause the stream to go into FMOD_OPENSTATE_SETPOSITION
state (see Sound::get_open_state
) and Sound commands will return FMOD_RESULT::FMOD_ERR_NOTREADY
.
Channel::get_position
will also not update until this non-blocking set position operation has completed.
Using a VBR source that does not have an associated seek table or seek information (such as MP3 or MOD/S3M/XM/IT) may cause inaccurate seeking if you specify TimeUnit::MS
or TimeUnit::PCM
.
If you want FMOD to create a PCM vs bytes seek table so that seeking is accurate, you will have to specify Mode::ACCURATE_TIME
when loading or opening the sound.
This means there is a slight delay as FMOD scans the whole file when loading the sound to create this table.
Sourcepub fn get_position(&self, time_unit: TimeUnit) -> Result<c_uint>
pub fn get_position(&self, time_unit: TimeUnit) -> Result<c_uint>
Retrieves the current playback position.
Certain TimeUnit
types are always available: TimeUnit::PCM
, TimeUnit::PCMBytes
and TimeUnit::MS
.
The others are format specific such as TimeUnit::ModOrder
/ TimeUnit::ModRow
/ TimeUnit::ModPattern
which is specific to files of type MOD / S3M / XM / IT.
If TimeUnit::MS
or TimeUnit::PCMBytes
are used, the value is internally converted from TimeUnit::PCM
, so the retrieved value may not exactly match the set value.
Sourcepub fn set_channel_group(&self, channel_group: ChannelGroup) -> Result<()>
pub fn set_channel_group(&self, channel_group: ChannelGroup) -> Result<()>
Sets the ChannelGroup
this object outputs to.
A ChannelGroup
may contain many Channels.
Channel
s may only output to a single ChannelGroup
. This operation will remove it from the previous group first.
Sourcepub fn get_channel_group(&self) -> Result<ChannelGroup>
pub fn get_channel_group(&self) -> Result<ChannelGroup>
Retrieves the ChannelGroup
this object outputs to.
Sourcepub fn set_loop_count(&self, loop_count: c_int) -> Result<()>
pub fn set_loop_count(&self, loop_count: c_int) -> Result<()>
Sets the number of times to loop before stopping.
The ‘mode’ of the Sound or Channel must be Mode::LOOP_NORMAL
or Mode::LOOP_BIDI
for this function to work.
Sourcepub fn get_loop_count(&self) -> Result<c_int>
pub fn get_loop_count(&self) -> Result<c_int>
Retrieves the number of times to loop before stopping.
This is the current loop countdown value that will decrement as it plays until reaching 0.
Reset with Channel::set_loop_count
.
Sourcepub fn set_loop_points(
&self,
start: c_uint,
start_type: TimeUnit,
end: c_uint,
end_type: TimeUnit,
) -> Result<()>
pub fn set_loop_points( &self, start: c_uint, start_type: TimeUnit, end: c_uint, end_type: TimeUnit, ) -> Result<()>
Sets the loop start and end points.
Loop points may only be set on a Channel playing a Sound, not a Channel playing a DSP (See System::playDSP
).
Valid TimeUnit
types are TimeUnit::PCM
, TimeUnit::MS
, TimeUnit::PCMBytes
. Any other time units return FMOD_RESULT::FMOD_ERR_FORMAT
.
If TimeUnit::MS
or TimeUnit::PCMBytes
, the value is internally converted to TimeUnit::PCM
.
The Channel’s mode must be set to Mode::LOOP_NORMAL
or Mode::LOOP_BIDI
for loop points to affect playback.
Sourcepub fn get_loop_points(
&self,
start_type: TimeUnit,
end_type: TimeUnit,
) -> Result<(c_uint, c_uint)>
pub fn get_loop_points( &self, start_type: TimeUnit, end_type: TimeUnit, ) -> Result<(c_uint, c_uint)>
Retrieves the loop start and end points.
Valid TimeUnit
types are TimeUnit::PCM
, TimeUnit::MS
, TimeUnit::PCMBytes
. Any other time units return FMOD_RESULT::FMOD_ERR_FORMAT
.
If TimeUnit::MS
or TimeUnit::PCMBytes
are used, the value is internally converted from TimeUnit::PCM
, so the retrieved value may not exactly match the set value.
Source§impl Channel
impl Channel
Sourcepub unsafe fn from_ffi(value: *mut FMOD_CHANNEL) -> Self
pub unsafe fn from_ffi(value: *mut FMOD_CHANNEL) -> Self
§Safety
value
must be a valid pointer either aquired from Self::as_ptr
or FMOD.
§Panics
Panics if value
is null.
Sourcepub fn as_ptr(self) -> *mut FMOD_CHANNEL
pub fn as_ptr(self) -> *mut FMOD_CHANNEL
Converts self
into its raw representation.
Methods from Deref<Target = ChannelControl>§
Sourcepub fn set_callback<C: ChannelControlCallback>(&self) -> Result<()>
pub fn set_callback<C: ChannelControlCallback>(&self) -> Result<()>
Sets the callback for ChannelControl
level notifications.
pub const DSP_HEAD: FMOD_CHANNELCONTROL_DSP_INDEX = -1i32
pub const DSP_TAIL: FMOD_CHANNELCONTROL_DSP_INDEX = -3i32
pub const DSP_FADER: FMOD_CHANNELCONTROL_DSP_INDEX = -2i32
Sourcepub fn add_dsp(&self, index: c_int, dsp: Dsp) -> Result<()>
pub fn add_dsp(&self, index: c_int, dsp: Dsp) -> Result<()>
Adds a DSP unit to the specified index in the DSP chain.
If dsp is already added to an existing object it will be removed and then added to this object.
For detailed information on FMOD’s DSP network, read the DSP Architecture and Usage white paper.
Sourcepub fn remove_dsp(&self, dsp: Dsp) -> Result<()>
pub fn remove_dsp(&self, dsp: Dsp) -> Result<()>
Removes the specified DSP unit from the DSP chain.
Sourcepub fn get_dsp_count(&self) -> Result<c_int>
pub fn get_dsp_count(&self) -> Result<c_int>
Retrieves the number of DSP units in the DSP chain.
Sourcepub fn get_dsp(&self, index: c_int) -> Result<Dsp>
pub fn get_dsp(&self, index: c_int) -> Result<Dsp>
Retrieves the DSP unit at the specified index in the DSP chain.
Sourcepub fn set_dsp_index(&self, dsp: Dsp, index: c_int) -> Result<()>
pub fn set_dsp_index(&self, dsp: Dsp, index: c_int) -> Result<()>
Sets the index in the DSP chain of the specified DSP.
This will move a DSP already in the DSP chain to a new offset.
Sourcepub fn get_dsp_index(&self, dsp: Dsp) -> Result<c_int>
pub fn get_dsp_index(&self, dsp: Dsp) -> Result<c_int>
Retrieves the index of a DSP inside the Channel or ChannelGroup
’s DSP chain.
Sourcepub fn set_reverb_properties(&self, instance: c_int, wet: c_float) -> Result<()>
pub fn set_reverb_properties(&self, instance: c_int, wet: c_float) -> Result<()>
Sets the wet / send level for a particular reverb instance.
Channels are automatically connected to all existing reverb instances due to the default wet level of 1.
ChannelGroups
however will not send to any reverb by default requiring an explicit call to this function.
ChannelGroup
reverb is optimal for the case where you want to send 1 mixed signal to the reverb, rather than a lot of individual Channel reverb sends.
It is advisable to do this to reduce CPU if you have many Channels inside a ChannelGroup
.
When setting a wet level for a ChannelGroup
, any Channels under that ChannelGroup
will still have their existing sends to the reverb.
To avoid this doubling up you should explicitly set the Channel wet levels to 0.
Sourcepub fn get_reverb_properties(&self, instance: c_int) -> Result<c_float>
pub fn get_reverb_properties(&self, instance: c_int) -> Result<c_float>
Retrieves the wet / send level for a particular reverb instance.
Sourcepub fn set_low_pass_gain(&self, gain: c_float) -> Result<()>
pub fn set_low_pass_gain(&self, gain: c_float) -> Result<()>
Sets the gain of the dry signal when built in lowpass / distance filtering is applied.
Requires the built in lowpass to be created with FMOD_INIT_CHANNEL_LOWPASS
or FMOD_INIT_CHANNEL_DISTANCEFILTER
.
§NOTE: Currently only supported for Channel, not ChannelGroup
.
Sourcepub fn get_low_pass_gain(&self) -> Result<c_float>
pub fn get_low_pass_gain(&self) -> Result<c_float>
Retrieves the gain of the dry signal when built in lowpass / distance filtering is applied.
Requires the built in lowpass to be created with FMOD_INIT_CHANNEL_LOWPASS
or FMOD_INIT_CHANNEL_DISTANCEFILTER
.
§NOTE: Currently only supported for Channel, not ChannelGroup
.
Sourcepub fn get_userdata(&self) -> Result<*mut c_void>
pub fn get_userdata(&self) -> Result<*mut c_void>
Retrieves user data.
Sourcepub fn get_system(&self) -> Result<System>
pub fn get_system(&self) -> Result<System>
Retrieves the System
that created this object.
Sourcepub fn set_pan(&self, pan: c_float) -> Result<()>
pub fn set_pan(&self, pan: c_float) -> Result<()>
Sets the left/right pan level.
This is a convenience function to avoid passing a matrix, it will overwrite values set via ChannelControl::set_mix_levels_input
,
ChannelControl::set_mix_levels_output
and ChannelControl::set_mix_matrix
.
Mono inputs are panned from left to right using constant power panning (non linear fade).
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).
The output channel count will always match the System speaker mode set via SystemBuilder::software_format
.
If the System is initialized with FMOD_SPEAKERMODE_RAW
calling this function will produce silence.
Sourcepub fn set_mix_levels_input(&self, levels: &mut [c_float]) -> Result<()>
pub fn set_mix_levels_input(&self, levels: &mut [c_float]) -> Result<()>
Sets the incoming volume level for each channel of a multi-channel signal.
This is a convenience function to avoid passing a matrix, it will overwrite values set via ChannelControl::set_pan
,
ChannelControl::set_mix_levels_output
and ChannelControl::set_mix_matrix
.
§NOTE: Currently only supported for Channel, not ChannelGroup
.
Sourcepub fn set_mix_levels_output(
&self,
front_left: c_float,
front_right: c_float,
center: c_float,
lfe: c_float,
surround_left: c_float,
surround_right: c_float,
back_left: c_float,
back_right: c_float,
) -> Result<()>
pub fn set_mix_levels_output( &self, front_left: c_float, front_right: c_float, center: c_float, lfe: c_float, surround_left: c_float, surround_right: c_float, back_left: c_float, back_right: c_float, ) -> Result<()>
Sets the outgoing volume levels for each speaker.
Specify the level for a given output speaker, if the channel count of the input and output do not match, channels will be up/down mixed as appropriate to approximate the given speaker values. 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.
This is a convenience function to avoid passing a matrix, it will overwrite values set via ChannelControl::set_pan
, ChannelControl::set_mix_levels_input
and ChannelControl::set_mix_matrix
.
The output channel count will always match the System speaker mode set via SystemBuilder::software_format
.
If the System is initialized with FMOD_SPEAKERMODE_RAW
calling this function will produce silence.
Sourcepub fn set_mix_matrix<const IN: usize, const OUT: usize>(
&self,
matrix: [[f32; IN]; OUT],
) -> Result<()>
pub fn set_mix_matrix<const IN: usize, const OUT: usize>( &self, matrix: [[f32; IN]; OUT], ) -> Result<()>
Sets a two-dimensional pan matrix that maps the signal from input channels (columns) to output speakers (rows).
This will overwrite values set via ChannelControl::set_pan
, ChannelControl::set_mix_levels_input
and ChannelControl::set_mix_levels_output
.
Sourcepub fn get_mix_matrix<const IN: usize, const OUT: usize>(
&self,
) -> Result<([[f32; IN]; OUT], c_int, c_int)>
pub fn get_mix_matrix<const IN: usize, const OUT: usize>( &self, ) -> Result<([[f32; IN]; OUT], c_int, c_int)>
Retrieves a 2 dimensional pan matrix that maps the signal from input channels (columns) to output speakers (rows).
Matrix element values can be below 0 to invert a signal and above 1 to amplify the signal. Note that increasing the signal level too far may cause audible distortion.
Sourcepub fn is_playing(&self) -> Result<bool>
pub fn is_playing(&self) -> Result<bool>
Retrieves the playing state.
A Channel
is considered playing after System::playSound
or System::playDSP
, even if it is paused.
A ChannelGroup
is considered playing if it has any playing Channel
s.
Sourcepub fn stop(&self) -> Result<()>
pub fn stop(&self) -> Result<()>
Stops the Channel (or all Channel
s in nested ChannelGroup
s) from playing.
This will free up internal resources for reuse by the virtual voice system.
Channel
s are stopped automatically when their playback position reaches the length of the Sound being played.
This is not the case however if the Channel
is playing a DSP or the Sound is looping,
in which case the Channel
will continue playing until stop is called. Once stopped,
the Channel
handle will become invalid and can be discarded and any API calls made with it will return FMOD_RESULT::FMOD_ERR_INVALID_HANDLE
.
Sourcepub fn set_paused(&self, paused: bool) -> Result<()>
pub fn set_paused(&self, paused: bool) -> Result<()>
Sets the paused state.
Pause halts playback which effectively freezes Channel::get_position
and ChannelControl::getDSPClock
values.
An individual pause state is kept for each object,
pausing a parent ChannelGroup
will effectively pause this object however when queried the individual pause state is returned.
Sourcepub fn get_paused(&self) -> Result<bool>
pub fn get_paused(&self) -> Result<bool>
Retrieves the paused state.
An individual pause state is kept for each object,
a parent ChannelGroup
being paused will effectively pause this object however when queried the individual pause state is returned.
Sourcepub fn set_mode(&self, mode: Mode) -> Result<()>
pub fn set_mode(&self, mode: Mode) -> Result<()>
Sets the playback mode that controls how this object behaves.
Modes supported:
Mode::LOOP_OFF
Mode::LOOP_NORMAL
Mode::LOOP_BIDI
Mode::D2
Mode::D3
Mode::HEADRELATIVE_3D
Mode::WORLDRELATIVE_3D
Mode::INVERSE_ROLLOFF_3D
Mode::LINEAR_ROLLOFF_3D
Mode::LINEAR_SQUARE_ROLLOFF_3D
Mode::INVERSE_TAPERED_ROLLOFF_3D
Mode::CUSTOM_ROLLOFF_3D
Mode::IGNORE_GEOMETRY_3D
Mode::VIRTUAL_PLAYFROM_START
When changing the loop mode, sounds created with
System::create_stream
or Mode::CREATE_STREAM
may have already been pre-buffered and executed their loop logic ahead of time before this call was even made.
This is dependent on the size of the sound versus the size of the stream decode buffer (see FMOD_CREATESOUNDEXINFO
).
If this happens, you may need to reflush the stream buffer by calling Channel::set_position
.
Note this will usually only happen if you have sounds or loop points that are smaller than the stream decode buffer size.
When changing the loop mode of sounds created with with System::create_sound
or FMOD_CREATESAMPLE
,
if the sound was set up as Mode::LOOP_OFF
, then set to Mode::LOOP_NORMAL
with this function, the sound may click when playing the end of the sound.
This is because the sound needs to be prepared for looping using Sound::setMode
,
by modifying the content of the PCM data (i.e. data past the end of the actual sample data) to allow the interpolators to read ahead without clicking.
If you use ChannelControl::setMode
it will not do this (because different Channels may have different loop modes for the same sound)
and may click if you try to set it to looping on an unprepared sound.
If you want to change the loop mode at runtime it may be better to load the sound as looping first (or use Sound::setMode
),
to let it prepare the data as if it was looping so that it does not click whenever ChannelControl::setMode
is used to turn looping on.
If Mode::IGNORE_GEOMETRY_3D
or Mode::VIRTUAL_PLAYFROM_START
is not specified, the flag will be cleared if it was specified previously.
Sourcepub fn get_mode(&self) -> Result<Mode>
pub fn get_mode(&self) -> Result<Mode>
Retrieves the playback mode bits that control how this object behaves.
Sourcepub fn set_pitch(&self, pitch: c_float) -> Result<()>
pub fn set_pitch(&self, pitch: c_float) -> Result<()>
Sets the relative pitch / playback rate.
Scales playback frequency of Channel
object or if issued on a ChannelGroup
it scales the frequencies of all Channel
s contained in the ChannelGroup
.
An individual pitch value is kept for each object,
changing the pitch of a parent ChannelGroup
will effectively alter the pitch of this object however when queried the individual pitch value is returned.
Sourcepub fn get_pitch(&self) -> Result<c_float>
pub fn get_pitch(&self) -> Result<c_float>
Retrieves the relative pitch / playback rate.
An individual pitch value is kept for each object, a parent ChannelGroup
pitch will effectively scale the pitch of this object however when queried the individual pitch value is returned.
Sourcepub fn get_dsp_clock(&self) -> Result<(c_ulonglong, c_ulonglong)>
pub fn get_dsp_clock(&self) -> Result<(c_ulonglong, c_ulonglong)>
Retrieves the DSP clock values at this point in time.
To perform sample accurate scheduling in conjunction with ChannelControl::setDelay
and ChannelControl::addFadePoint
query the parentclock value.
Sourcepub fn set_delay(
&self,
start: c_ulonglong,
end: c_ulonglong,
stop_channels: bool,
) -> Result<()>
pub fn set_delay( &self, start: c_ulonglong, end: c_ulonglong, stop_channels: bool, ) -> Result<()>
Sets a sample accurate start (and/or stop) time relative to the parent ChannelGroup
DSP clock.
To perform sample accurate scheduling use ChannelControl::getDSPClock
to query the parent clock value.
If a parent ChannelGroup
changes its pitch, the start and stop times will still be correct as the parent clock rate is adjusted by that pitch.
Sourcepub fn get_delay(&self) -> Result<(c_ulonglong, c_ulonglong, bool)>
pub fn get_delay(&self) -> Result<(c_ulonglong, c_ulonglong, bool)>
Retrieves a sample accurate start (and/or stop) time relative to the parent ChannelGroup
DSP clock.
Sourcepub fn add_fade_point(&self, dsp_clock: c_ulonglong, volume: f32) -> Result<()>
pub fn add_fade_point(&self, dsp_clock: c_ulonglong, volume: f32) -> Result<()>
Adds a sample accurate fade point at a time relative to the parent ChannelGroup
DSP clock.
Fade points are scaled against other volume settings and in-between each fade point the volume will be linearly ramped.
To perform sample accurate fading use ChannelControl::getDSPClock
to query the parent clock value.
If a parent ChannelGroup
changes its pitch, the fade points will still be correct as the parent clock rate is adjusted by that pitch.
// Example. Ramp from full volume to half volume over the next 4096 samples
let (_, parent) = target.get_dsp_clock();
target.add_fade_point(parent, 1.0);
target.add_fade_point(parent + 4096, 0.5);
Sourcepub fn set_fade_point_ramp(
&self,
dsp_clock: c_ulonglong,
volume: f32,
) -> Result<()>
pub fn set_fade_point_ramp( &self, dsp_clock: c_ulonglong, volume: f32, ) -> Result<()>
Adds a volume ramp at the specified time in the future using fade points.
This is a convenience function that creates a scheduled 64 sample fade point ramp from the current volume level to volume arriving at dsp_clock
time.
Can be use in conjunction with ChannelControl::SetDelay
.
All fade points after dsp_clock
will be removed.
Sourcepub fn remove_fade_points(
&self,
dsp_clock_start: c_ulonglong,
dsp_clock_end: c_ulonglong,
) -> Result<()>
pub fn remove_fade_points( &self, dsp_clock_start: c_ulonglong, dsp_clock_end: c_ulonglong, ) -> Result<()>
Removes all fade points between the two specified clock values (inclusive).
Sourcepub fn get_fade_points(&self) -> Result<(Vec<c_ulonglong>, Vec<f32>)>
pub fn get_fade_points(&self) -> Result<(Vec<c_ulonglong>, Vec<f32>)>
Retrieves information about stored fade points.
Sourcepub fn set_3d_attributes(
&self,
position: Option<Vector>,
velocity: Option<Vector>,
) -> Result<()>
pub fn set_3d_attributes( &self, position: Option<Vector>, velocity: Option<Vector>, ) -> Result<()>
Sets the 3D position and velocity used to apply panning, attenuation and doppler.
The Mode::D3
flag must be set on this object otherwise FMOD_RESULT::FMOD_ERR_NEEDS3D
is returned.
Vectors must be provided in the correct handedness.
For a stereo 3D sound, you can set the spread of the left/right parts in speaker space by using ChannelControl::set_3d_spread
.
Sourcepub fn get_3d_attributes(&self) -> Result<(Vector, Vector)>
pub fn get_3d_attributes(&self) -> Result<(Vector, Vector)>
Retrieves the 3D position and velocity used to apply panning, attenuation and doppler.
Sourcepub fn set_3d_cone_orientation(&self, orientation: Vector) -> Result<()>
pub fn set_3d_cone_orientation(&self, orientation: Vector) -> Result<()>
Sets the orientation of a 3D cone shape, used for simulated occlusion.
The Mode::D3
flag must be set on this object otherwise FMOD_RESULT::FMOD_ERR_NEEDS3D
is returned.
This function has no effect unless ChannelControl::set_3d_cone_settings
has been used to change the cone inside/outside angles from the default.
Vectors must be provided in the correct handedness.
Sourcepub fn get_3d_cone_orientation(&self) -> Result<Vector>
pub fn get_3d_cone_orientation(&self) -> Result<Vector>
Retrieves the orientation of a 3D cone shape, used for simulated occlusion.
Sourcepub fn set_3d_cone_settings(
&self,
inside_angle: c_float,
outside_angle: c_float,
outside_volume: c_float,
) -> Result<()>
pub fn set_3d_cone_settings( &self, inside_angle: c_float, outside_angle: c_float, outside_volume: c_float, ) -> Result<()>
Sets the angles and attenuation levels of a 3D cone shape, for simulated occlusion which is based on direction.
The Mode::D3
flag must be set on this object otherwise FMOD_RESULT::FMOD_ERR_NEEDS3D
is returned.
When ChannelControl::set_3d_cone_orientation
is used and a 3D ‘cone’ is set up,
attenuation will automatically occur for a sound based on the relative angle of the direction the cone is facing,
vs the angle between the sound and the listener.
- If the relative angle is within the
inside_angle
, the sound will not have any attenuation applied. - If the relative angle is between the
inside_angle
andoutside_angle
, linear volume attenuation (between 1 andoutside_volume
) is applied between the two angles until it reaches theoutside_angle
. - If the relative angle is outside of the
outside_angle
the volume does not attenuate any further.
Sourcepub fn get_3d_cone_settings(&self) -> Result<(c_float, c_float, c_float)>
pub fn get_3d_cone_settings(&self) -> Result<(c_float, c_float, c_float)>
Retrieves the angles and attenuation levels of a 3D cone shape, for simulated occlusion which is based on direction.
When ChannelControl::set_3d_cone_orientation
is used and a 3D ‘cone’ is set up,
attenuation will automatically occur for a sound based on the relative angle of the direction the cone is facing,
vs the angle between the sound and the listener.
- If the relative angle is within the
inside_angle
, the sound will not have any attenuation applied. - If the relative angle is between the
inside_angle
andoutside_angle
, linear volume attenuation (between 1 andoutside_volume
) is applied between the two angles until it reaches theoutside_angle
. - If the relative angle is outside of the
outside_angle
the volume does not attenuate any further.
Sourcepub unsafe fn set_3d_custom_rolloff(&self, points: &mut [Vector]) -> Result<()>
pub unsafe fn set_3d_custom_rolloff(&self, points: &mut [Vector]) -> Result<()>
Sets a custom roll-off shape for 3D distance attenuation.
Must be used in conjunction with Mode::CUSTOM_ROLLOFF_3D
flag to be activated.
If Mode::CUSTOM_ROLLOFF_3D
is set and the roll-off shape is not set, FMOD will revert to Mode::INVERSE_ROLLOFF_3D
roll-off mode.
When a custom roll-off is specified a Channel
or ChannelGroup
’s 3D ‘minimum’ and ‘maximum’ distances are ignored.
The distance in-between point values is linearly interpolated until the final point where the last value is held.
If the points are not sorted by distance, an error will result.
§Safety
This function does not duplicate the memory for the points internally. The memory you pass to FMOD must remain valid while in use.
Sourcepub fn get_3d_custom_rolloff(&self) -> Result<Vec<Vector>>
pub fn get_3d_custom_rolloff(&self) -> Result<Vec<Vector>>
Retrieves the current custom roll-off shape for 3D distance attenuation.
Sourcepub fn set_3d_distance_filter(
&self,
custom: bool,
custom_level: c_float,
center_freq: c_float,
) -> Result<()>
pub fn set_3d_distance_filter( &self, custom: bool, custom_level: c_float, center_freq: c_float, ) -> Result<()>
Sets an override value for the 3D distance filter.
If distance filtering is enabled, by default the 3D engine will automatically attenuate frequencies using a lowpass and a highpass filter, based on 3D distance. This function allows the distance filter effect to be set manually, or to be set back to ‘automatic’ mode.
The FMOD_3D
flag must be set on this object otherwise FMOD_ERR_NEEDS3D
is returned.
The System must be initialized with FMOD_INIT_CHANNEL_DISTANCEFILTER
for this feature to work.
§NOTE: Currently only supported for Channel
, not ChannelGroup
.
Sourcepub fn get_3d_distance_filter(&self) -> Result<(bool, c_float, c_float)>
pub fn get_3d_distance_filter(&self) -> Result<(bool, c_float, c_float)>
Retrieves the override values for the 3D distance filter.
Sourcepub fn set_3d_doppler_level(&self, level: c_float) -> Result<()>
pub fn set_3d_doppler_level(&self, level: c_float) -> Result<()>
Sets the amount by which doppler is scaled.
The FMOD_3D
flag must be set on this object otherwise FMOD_ERR_NEEDS3D
is returned.
The doppler effect will disabled if System::set3DNumListeners
is given a value greater than 1.
§NOTE: Currently only supported for Channel
, not ChannelGroup
.
Sourcepub fn get_3d_doppler_level(&self) -> Result<c_float>
pub fn get_3d_doppler_level(&self) -> Result<c_float>
Retrieves the amount by which doppler is scaled.
Sourcepub fn set_3d_level(&self, level: c_float) -> Result<()>
pub fn set_3d_level(&self, level: c_float) -> Result<()>
Sets the blend between 3D panning and 2D panning.
The FMOD_3D
flag must be set on this object otherwise FMOD_ERR_NEEDS3D
is returned.
2D functions include:
ChannelControl::set_pan
ChannelControl::set_mix_levels_output
ChannelControl::set_mix_levels_input
ChannelControl::set_mix_matrix
3D functions include:
ChannelControl::set3DAttributes
ChannelControl::set3DConeOrientation
ChannelControl::set3DCustomRolloff
Sourcepub fn get_3d_level(&self) -> Result<c_float>
pub fn get_3d_level(&self) -> Result<c_float>
Retrieves the blend between 3D panning and 2D panning.
The FMOD_3D
flag must be set on this object otherwise FMOD_ERR_NEEDS3D
is returned.
2D functions include:
ChannelControl::set_pan
ChannelControl::set_mix_levels_output
ChannelControl::set_mix_levels_input
ChannelControl::set_mix_matrix
3D functions include:
ChannelControl::set3DAttributes
ChannelControl::set3DConeOrientation
ChannelControl::set3DCustomRolloff
Sourcepub fn set_3d_min_max_distance(&self, min: c_float, max: c_float) -> Result<()>
pub fn set_3d_min_max_distance(&self, min: c_float, max: c_float) -> Result<()>
Sets the minimum and maximum distances used to calculate the 3D roll-off attenuation.
When the listener is within the minimum distance of the sound source the 3D volume will be at its maximum. As the listener moves from the minimum distance to the maximum distance the sound will attenuate following the roll-off curve set. When outside the maximum distance the sound will no longer attenuate.
Attenuation in 3D space is controlled by the roll-off mode, these are FMOD_3D_INVERSEROLLOFF
, FMOD_3D_LINEARROLLOFF
, FMOD_3D_LINEARSQUAREROLLOFF
, FMOD_3D_INVERSETAPEREDROLLOFF
, FMOD_3D_CUSTOMROLLOFF
.
Minimum distance is useful to give the impression that the sound is loud or soft in 3D space. A sound with a small 3D minimum distance in a typical (non custom) roll-off mode will make the sound appear small, and the sound will attenuate quickly. A sound with a large minimum distance will make the sound appear larger.
The FMOD_3D
flag must be set on this object otherwise FMOD_ERR_NEEDS3D
is returned.
To define the min and max distance per Sound instead of Channel or ChannelGroup
use Sound::set3DMinMaxDistance
.
If FMOD_3D_CUSTOMROLLOFF
has been set on this object these values are stored, but ignored in 3D processing.
Sourcepub fn get_3d_min_max_distance(&self) -> Result<(c_float, c_float)>
pub fn get_3d_min_max_distance(&self) -> Result<(c_float, c_float)>
Retrieves the minimum and maximum distances used to calculate the 3D roll-off attenuation.
Sourcepub fn set_3d_occlusion(&self, direct: c_float, reverb: c_float) -> Result<()>
pub fn set_3d_occlusion(&self, direct: c_float, reverb: c_float) -> Result<()>
Sets the 3D attenuation factors for the direct and reverb paths.
There is a reverb path/send when ChannelControl::setReverbProperties
has been used, reverbocclusion controls its attenuation.
If the System has been initialized with FMOD_INIT_CHANNEL_DISTANCEFILTER
or
FMOD_INIT_CHANNEL_LOWPASS
the directocclusion is applied as frequency filtering rather than volume attenuation.
Sourcepub fn get_3d_occlusion(&self) -> Result<(c_float, c_float)>
pub fn get_3d_occlusion(&self) -> Result<(c_float, c_float)>
Retrieves the 3D attenuation factors for the direct and reverb paths.
Sourcepub fn set_3d_spread(&self, angle: c_float) -> Result<()>
pub fn set_3d_spread(&self, angle: c_float) -> Result<()>
Sets the spread of a 3D sound in speaker space.
When the spread angle is 0 (default) a multi-channel signal will collapse to mono and be spatialized to a single point based on ChannelControl::set3DAttributes
calculations.
As the angle is increased, each channel within a multi-channel signal will be rotated away from that point.
For 2, 4, 6, 8, and 12 channel signals, the spread is arranged from leftmost speaker to rightmost speaker intelligently,
for example in 5.1 the leftmost speaker is rear left, followed by front left, center, front right then finally rear right as the rightmost speaker (LFE is not spread).
For other channel counts the individual channels are spread evenly in the order of the signal.
As the signal is spread the power will be preserved.
For a stereo signal given different spread angles:
- 0: Sound is collapsed to mono and spatialized to a single point.
- 90: Left channel is rotated 45 degrees to the left compared with angle=0 and the right channel 45 degrees to the right.
- 180: Left channel is rotated 90 degrees to the left compared with angle=0 and the right channel 90 degrees to the right.
- 360: Left channel is rotated 180 degrees to the left and the right channel 180 degrees to the right. This means the sound is collapsed to mono and spatialized to a single point in the opposite direction compared with (angle=0).
Sourcepub fn get_3d_spread(&self) -> Result<c_float>
pub fn get_3d_spread(&self) -> Result<c_float>
Retrieves the spread of a 3D sound in speaker space.
Sourcepub fn get_audibility(&self) -> Result<c_float>
pub fn get_audibility(&self) -> Result<c_float>
Retrieves an estimation of the output volume.
Estimated volume is calculated based on 3D spatialization, occlusion, API volume levels and DSPs used.
While this does not represent the actual waveform, Channel
s playing FSB files will take into consideration the overall peak level of the file (if available).
This value is used to determine which Channel
s should be audible and which Channel
s to virtualize when resources are limited.
See the Virtual Voice System white paper for more details about how audibility is calculated.
Sourcepub fn set_volume(&self, volume: c_float) -> Result<()>
pub fn set_volume(&self, volume: c_float) -> Result<()>
Sets the volume level.
To define the volume per Sound use Sound::setDefaults
.
Setting volume at a level higher than 1 can lead to distortion/clipping.
Sourcepub fn get_volume(&self) -> Result<c_float>
pub fn get_volume(&self) -> Result<c_float>
Retrieves the volume level.
Sourcepub fn set_volume_ramp(&self, ramp: bool) -> Result<()>
pub fn set_volume_ramp(&self, ramp: bool) -> Result<()>
Sets whether volume changes are ramped or instantaneous.
Volume changes when not paused will be ramped to the target value to avoid a pop sound, this function allows that setting to be overridden and volume changes to be applied immediately.
Sourcepub fn get_volume_ramp(&self) -> Result<bool>
pub fn get_volume_ramp(&self) -> Result<bool>
Retrieves whether volume changes are ramped or instantaneous.
Sourcepub fn set_mute(&self, mute: bool) -> Result<()>
pub fn set_mute(&self, mute: bool) -> Result<()>
Sets the mute state.
Mute is an additional control for volume, the effect of which is equivalent to setting the volume to zero.
An individual mute state is kept for each object,
muting a parent ChannelGroup
will effectively mute this object however when queried the individual mute state is returned.
ChannelControl::getAudibility
can be used to calculate overall audibility for a Channel or ChannelGroup
.
Sourcepub fn get_mute(&self) -> Result<bool>
pub fn get_mute(&self) -> Result<bool>
Retrieves the mute state.
An individual mute state is kept for each object,
muting a parent ChannelGroup
will effectively mute this object however when queried the individual mute state is returned.
ChannelControl::getAudibility
can be used to calculate overall audibility for a Channel or ChannelGroup
.
Trait Implementations§
impl Copy for Channel
impl Eq for Channel
impl Send for Channel
thread-unsafe
only.impl StructuralPartialEq for Channel
impl Sync for Channel
thread-unsafe
only.