nvgt_phonon
The nvgt_phonon plugin brings Steam Audio's world simulation to NVGT. Its main feature is the sound_environment class, which makes sounds in a physics_world sound like they are really there, muffled and quieter behind walls, sometimes heard through them, and with reverb that fits the size and materials of the room. It also provides Steam Audio's HRTF as an alternative to NVGT's built in one, and a phonon_binaural_node for applying it manually.
NVGT's own HRTF, used by set_sound_global_hrtf(), is derived from the Synthizer library by Austin Hicks (camlorn) and needs no plugin. You only need this plugin if you want sound_environment or Steam Audio's HRTF specifically.
To activate it, add the following line to your script:
#pragma plugin nvgt_phonon
A compiled game that uses the plugin will ship with the plugin's library (nvgt_phonon) and, where Steam Audio is built as a shared library (rare these days), with phonon too. See the section about shared libraries in the documentation on compiling your project for distribution if in doubt of what might get distributed with a game. If you are an advanced user who does not want to ship nvgt_phonon.dll or libnvgt_phonon.so with your games, you can compile the plugin statically instead.
The plugin adds these to the script engine:
- the
sound_environmentandsound_environment_sourceclasses, with thesound_environment_reflection_typeandsound_environment_occlusion_typeenums, - the
audio_panner_phonon_hrtfandaudio_attenuator_phononvalues for selecting Steam Audio's panner and attenuator, - the
phonon_binaural_nodeclass.
classes
phonon_binaural_node
An audio node that positions its input sound in a direction around the listener using Steam Audio's HRTF. Unlike the HRTF panner used automatically for positioned sounds, the direction is not worked out from the positions of a sound and the listener, you set it yourself, which allows an HRTF to be applied to something that isn't positioned in the world, such as a sound being mixed with other nodes, or a one-off cinematic effect or navigation beacon etc.
phonon_binaural_node@ phonon_binaural_node(audio_engine@ engine, int channels, int sample_rate, int frame_size = 0);
Arguments:
- audio_engine@ engine: the engine the node belongs to.
- int channels: the number of channels of input, either 1 or 2. Stereo input is downmixed in the same way a mono input is positioned.
- int sample_rate: the sample rate of the audio passing through the node, normally that of the engine.
- int frame_size = 0: the number of frames Steam Audio processes at once, or 0 for the default.
Remarks:
An exception is thrown if channels is not 1 or 2, or if Steam Audio could not be initialized.
The node has 1 input bus and 1 output bus, accessible with the node property (or by passing the object where an audio_node is expected), and should be connected between a sound and the engine's endpoint with the attach_output_bus method of audio nodes. Its output is always stereo, with the left and right channels in the engine's first 2 channels.
Example:
void main() {
phonon_binaural_node binaural(sound_default_engine, 2, 44100);
sound s;
s.load("music.ogg");
s.set_mixer(null);
s.attach_output_bus(0, binaural, 0);
binaural.node.attach_output_bus(0, sound_default_engine.endpoint, 0);
binaural.set_direction(1, 0, 0, 10); // To the right.
s.play_looped();
wait(5000);
}
Methods
set_direction
Set the direction the node positions its sound in.
- void phonon_binaural_node::set_direction(float x, float y, float z, float distance);
- void phonon_binaural_node::set_direction(const vector&in direction, float distance);
Arguments:
- float x: the right component of the direction (1).
- float y: the up component of the direction (1).
- float z: the backward component of the direction (1).
- const vector&in direction: the direction as a vector (2).
- float distance: how far away the sound is, which with
set_spatial_blend_max_distance()determines how strongly it is positioned.
Remarks:
The direction is relative to the listener's head, with x to the right, y up and z behind, as used by Steam Audio. It does not need to be normalized.
The sound is fully positioned when distance is at least the node's spatial blend max distance, and is increasingly unpositioned as distance approaches 0, so that a sound at the listener's own position isn't snapped to one direction.
set_spatial_blend_max_distance
Set the distance at which the node's sound becomes fully positioned.
void phonon_binaural_node::set_spatial_blend_max_distance(float max_distance);
Arguments:
- float max_distance: the distance, in the same units passed to
set_direction(), at which positioning is complete. The default is 4. If 0 or less, the sound is always fully positioned.
Properties
node
The audio_node of this binaural node, whose buses can be attached to other nodes.
const audio_node@ node;
Remarks:
A phonon_binaural_node can also be used directly where an audio_node is expected, as it casts to it implicitly.
sound_environment
A sound_environment simulates how sound travels through a physical world, using Steam Audio, and applies the result to the sounds that are attached to it. For each attached sound it works out how much the direct sound is blocked by walls (occlusion), how much of it gets through them anyway and in which frequencies (transmission), and what the room sounds like, including echoes and reverb that depend on the shape and materials of the surroundings (reflections). It can also optionally let sound be heard bending around obstacles such as doorways (pathing), using paths baked ahead of time.
The world the sound travels through is provided by a raycaster, currently a physics_world, and the acoustic properties of its surfaces come from the physics_material of the bodies in it. This class is part of the nvgt_phonon plugin, so your script needs the line #pragma plugin nvgt_phonon.
sound_environment@ sound_environment(audio_engine@ engine = sound_default_engine);
Arguments:
- audio_engine@ engine = sound_default_engine: the audio engine whose sounds the environment will process.
Remarks:
An exception is thrown if Steam Audio could not be initialized.
The typical way to use an environment is:
- Create it and give it a raycaster with
set_raycaster()- usually that's a physics_world. - Create a mixer for each object in your world that makes sound with
new_mixer()(or useattach()for existing sounds and mixers), and move each mixer with its object usingset_position_3d(). - Play the object's sounds through its mixer.
- Every frame, position the listener of the engine and call
update().
Sounds are positioned with the engine's usual 3D functions, and other than attenuation where the curve is less dramatic to acomidate audio games, the environment treats one unit of distance as one meter. Occlusion and transmission are simulated on every call to update(), while reflections are simulated on a background thread and therefore could get a little behind in a full scene. Reflections are not simulated for every sound separately but for a limited number of groups that nearby sounds share, see max_sources and reflection_group_size.
Each attached sound or mixer is given a sound_environment_source, retrievable with get_source(), with settings and simulation results for just that sound.
Example:
void main() {
physics_world world;
// A concrete floor and a brick wall splitting the room in two.
world.create_and_add_body(physics_box_shape_create(vector(10, 10, 0.25), 0.05, physics_material_get("concrete")), vector(0, 0, -0.25), IDENTITY_QUATERNION, PHYSICS_BODY_STATIC, PHYSICS_LAYER_NON_MOVING);
world.create_and_add_body(physics_box_shape_create(vector(0.1, 10, 2), 0.05, physics_material_get("brick")), vector(0, 0, 2), IDENTITY_QUATERNION, PHYSICS_BODY_STATIC, PHYSICS_LAYER_NON_MOVING);
sound_environment env;
env.set_raycaster(world);
sound_default_engine.set_listener_position(0, -3, 0, 1.5);
mixer@ source = env.new_mixer();
source.set_position_3d(3, 0, 1.5); // On the other side of the wall.
sound@ s = sound();
s.load("music.ogg");
s.set_mixer(source);
s.play_looped();
sound_environment_source@ info = env.get_source(source);
while (!key_pressed(KEY_ESCAPE)) {
wait(5);
env.update();
if (key_pressed(KEY_SPACE)) screen_reader_speak("Occlusion: " + info.occlusion, true);
}
}
Methods
add_probe
Add a single probe at a position.
void sound_environment::add_probe(const vector&in position, float radius = 2);
Arguments:
- const vector&in position: the center of the probe.
- float radius = 2: the influence radius of the probe in meters, within which the listener is considered to be at the probe.
Remarks:
Any baked data is discarded.
attach
Attach an existing sound or mixer to this environment.
bool sound_environment::attach(mixer@ sound_or_mixer);
Arguments:
- mixer@ sound_or_mixer: the sound or mixer to attach.
Returns:
bool: true if the object is now attached to this environment, false otherwise.
Remarks:
An object can only belong to one environment (or reverb3d) at a time, attaching it to this one removes it from the previous one. The environment is applied before the sound is panned, so that what it simulates is the sound itself.
Everything that plays through an attached mixer is covered by the mixer's simulation, including sounds that are added to it later.
bake
Simulate reverb at every probe and the paths between them ahead of time.
bool sound_environment::bake(sound_environment_bake_callback@ progress = null, int rays = 16384, int bounces = 64);
Arguments:
sound_environment_bake_callback@ progress = null: an optional function with the signature
void callback(float progress)that is called with a number from 0 to 1 as baking proceeds.int rays = 16384: the number of rays traced per probe, clamped between 1 and 1048576.
int bounces = 64: the number of bounces per ray, clamped between 1 and 1024.
Returns:
bool: true if baking completed, false if there is no raycaster or no probes.
Remarks:
This blocks until baking is finished, so it should be done while loading or in a separate tool, and the result stored with save_baked_data(). Baking traces many more rays and bounces than real time simulation can afford.
Baked reverb is used for the listener's reverb when use_baked_reverb is enabled and the listener is within a probe, and baked paths are used when pathing is enabled. Baked data is created with the environment's current reflection_duration, reflection_order, diffuse_samples and irradiance_min_distance, and should be used with the same values.
Example:
void progress(float amount) {
screen_reader_speak(round(amount * 100, 0) + " percent", true);
}
void main() {
physics_world world;
// ... create level ...
sound_environment env;
env.set_raycaster(world);
env.generate_probes(vector(0, 0, 0), vector(50, 50, 5));
if (env.bake(progress)) alert("Baked", "Baked " + env.probe_count + " probes.");
}
clear_probes
Remove every probe.
void sound_environment::clear_probes();
Remarks:
Any baked data is discarded.
detach
Remove a sound or mixer from this environment.
void sound_environment::detach(mixer@ sound_or_mixer);
Arguments:
- mixer@ sound_or_mixer: the sound or mixer to detach.
Remarks:
Nothing happens if the object is not attached to this environment.
generate_probes
Automatically place probes above every floor within a box.
uint sound_environment::generate_probes(const vector&in minimum, const vector&in maximum, float spacing = 2, float height = 1.5);
Arguments:
const vector&in minimum: the lowest corner of the box to place probes in.
const vector&in maximum: the highest corner of the box.
float spacing = 2: the distance in meters between probes.
float height = 1.5: how many meters above the floor the probes are placed, which should be about the height of the listener's ears.
Returns:
uint: the number of probes placed, or 0 if there is no raycaster or spacing is not positive.
Remarks:
Probes mark the places the listener can be. Once baked with bake(), reverb at every probe and the paths that sound takes between them are looked up rather than simulated. Floors are found by tracing rays down through the box from the raycaster, so a raycaster must be set first.
The probes are added to any that already exist, and any baked data is discarded.
The reasoning for this is that replaying precalculated reflections from probes is exceedingly less CPU intensive than generating them in realtime. They can be downloaded over the network or extracted from a pack, so a map builder in a game could generate these once while building their map then distribute the probes to players who will then have a much less CPU intensive experience hearing good reflections.
Example:
void main() {
physics_world world;
// ... create level ...
sound_environment env;
env.set_raycaster(world);
uint count = env.generate_probes(vector(0, 0, 0), vector(50, 50, 5));
alert("Probes", "Placed " + count + " probes.");
}
get_source
Retrieve the sound_environment_source of a sound or mixer attached to this environment, which holds its settings and simulation results.
sound_environment_source@ sound_environment::get_source(mixer@ sound_or_mixer) const;
Arguments:
- mixer@ sound_or_mixer: the sound or mixer to look up.
Returns:
sound_environment_source@: the source, or null if the object isn't attached to this environment.
Example:
void main() {
sound_environment env;
mixer@ m = env.new_mixer();
sound_environment_source@ src = env.get_source(m);
src.apply_reflections = false; // This mixer's sounds are heard without reverb.
}
load_baked_data
Replace the environment's probes and baked data with data saved by save_baked_data().
bool sound_environment::load_baked_data(const string&in data);
Arguments:
- const string&in data: the data to load.
Returns:
bool: true if the data was valid and has been loaded, false otherwise, in which case nothing changes.
Example:
void main() {
sound_environment env;
if (!env.load_baked_data(file_get_contents("level1.baked"))) alert("Error", "The baked data could not be loaded.");
}
new_mixer
Create a new mixer that is already attached to this environment.
mixer@ sound_environment::new_mixer();
Returns:
mixer@: the new mixer, or null if it could not be created.
Remarks:
The recommended way to use an environment is to create one mixer per object that makes sound, such as the player, an enemy or a machine, position that mixer with set_position_3d() wherever the object is, and play all of the object's sounds through the mixer. The object is then simulated once however many sounds it is making.
Example:
void main() {
sound_environment env;
mixer@ player = env.new_mixer();
player.set_position_3d(10, 5, 1);
sound@ footstep = sound();
footstep.load("footstep.ogg");
footstep.set_mixer(player); // The sound is heard at the mixer's position, with the environment's occlusion and reflections.
footstep.play();
}
new_sound
Create a new sound that is already attached to this environment.
sound@ sound_environment::new_sound();
Returns:
sound@: the new sound, or null if it could not be created.
Remarks:
This is equivalent to creating a sound from the environment's engine and passing it to attach(). Every attached sound or mixer is simulated separately though nvgt does try to reduce processing when many sounds near each other play even without a mixer, so for an object that makes several sounds it is cheaper to create one mixer with new_mixer() and play the sounds through that.
save_baked_data
Serialize the environment's probes and baked data.
string sound_environment::save_baked_data() const;
Returns:
string: the data, which can be written to a file and given to load_baked_data() later.
Remarks:
The data contains the probes and everything baked at them, which is about 5 kilobytes per probe at the default reflection settings. It does not contain the scene, so it is only meaningful for the same level.
Example:
void main() {
physics_world world;
// ... create level ...
sound_environment env;
env.set_raycaster(world);
env.generate_probes(vector(0, 0, 0), vector(50, 50, 5));
env.bake();
file_put_contents("level1.baked", env.save_baked_data());
}
set_raycaster
Set the object this environment traces rays through to determine occlusion, transmission and reflections.
bool sound_environment::set_raycaster(ref@ raycaster);
Arguments:
- ref@ raycaster: the object to trace rays through, currently a physics_world, or null to remove the current one.
Returns:
bool: true if the raycaster was accepted, false if the object cannot be used as a raycaster.
Remarks:
With no raycaster, nothing blocks sound, so sounds are never occluded and no reflections are produced. A failed call leaves the previous raycaster in place.
The acoustic properties of what a ray hits come from the physics_material of the body that was hit, and bodies and materials marked as acoustically transparent are ignored. The new scene is used from the first update() call after any reflection simulation in progress has finished.
Example:
void main() {
physics_world world;
// ... create the bodies of your level here ...
sound_environment env;
if (!env.set_raycaster(world)) alert("Error", "The physics world can't be used as a raycaster.");
}
update
Run the environment's simulations and publish their results to the audio thread.
void sound_environment::update();
Remarks:
Call this once per frame from your main loop, after positioning the listener and the environment's sounds. The listener's position and orientation are read from the first listener of the environment's engine.
Each call runs the direct simulation (occlusion and transmission) of every source on the calling thread. The much more expensive reflection simulation is handed to a worker thread at most once per simulation_interval, and its results are picked up by later calls. Changes to settings that rebuild the simulator are also applied here, once the worker thread is idle.
Example:
void main() {
physics_world world;
// ... create level ...
sound_environment env;
env.set_raycaster(world);
while (!key_pressed(KEY_ESCAPE)) {
wait(5);
sound_default_engine.set_listener_position(0, 0, 0, 1.6);
env.update();
}
}
Properties
active_reflection_groups
The number of reflection groups that currently have sounds assigned to them.
const uint active_reflection_groups;
Remarks:
Reflections are simulated and convolved per group rather than per sound, see the max_sources and reflection_group_size properties.
binaural
Whether reflections (and pathed sound) are decoded binaurally with an HRTF when the engine outputs stereo.
bool binaural;
Remarks:
The default is true. When false, or when the engine does not have 2 channels, they are decoded to plain speaker channels, which sounds less spacious on headphones.
diffuse_samples
The number of rays traced for each diffuse (scattered) reflection at every bounce.
int diffuse_samples;
Remarks:
The default is 32 and values are clamped between 1 and 4096. Higher values give smoother diffuse reverb at the cost of simulation time.
Changing this rebuilds the environment's simulator and audio effects the next time the simulation is idle and update() is called, which cuts off reverb tails, so reflections briefly drop out. Avoid changing it every frame.
direct_simulation_time
How long the most recent direct simulation (occlusion and transmission) took, in milliseconds.
const float direct_simulation_time;
Remarks:
This simulation runs on the thread that calls update() every time it is called, so it is part of your frame time.
engine
The audio_engine this environment was created for.
const audio_engine@ engine;
has_baked_paths
Whether the paths sound can take between the environment's probes have been baked.
const bool has_baked_paths;
Remarks:
This becomes true after a successful call to bake() or load_baked_data() that had path data, and false again when the probes change. Paths are only used when the pathing property is enabled.
has_baked_reverb
Whether reverb has been baked at the environment's probes.
const bool has_baked_reverb;
Remarks:
This becomes true after a successful call to bake() or load_baked_data() that had reverb data, and false again when the probes change.
hybrid_overlap
For hybrid reflections, how much the convolved and parametric parts overlap around the transition, as a fraction between 0 and 1.
float hybrid_overlap;
Remarks:
The default is 0.25 and values are clamped between 0 and 1. This is only used when reflection_type is SOUND_ENVIRONMENT_REFLECTIONS_HYBRID.
hybrid_transition_time
For hybrid reflections, the time in seconds after which the convolved early reflections give way to the parametric reverb tail.
float hybrid_transition_time;
Remarks:
The default is 1 and the minimum is 0. This is only used when reflection_type is SOUND_ENVIRONMENT_REFLECTIONS_HYBRID.
irradiance_min_distance
The smallest distance in meters at which a reflection is considered to be arriving from a surface, which limits how loud reflections from surfaces very close to the listener can become.
float irradiance_min_distance;
Remarks:
The default is 0.25 and the minimum is 0.01. Raise it if you hear harsh or overly loud reflections when standing close to a wall. This takes effect at the next reflection simulation, and baked reverb is only valid for the value it was baked with.
max_sources
The number of reflection groups, which is the maximum number of separate places reflections are simulated for at once.
int max_sources;
Remarks:
The default is 16 and values are clamped between 0 and 1024. Rather than simulating and convolving reflections for every sound, the environment keeps this many groups, and each attached sound adds its signal to the group nearest to it, hearing the reflections simulated at that position. A sound that cannot get a group of its own shares the nearest group it can, or otherwise hears the listener's reverb. Setting this to 0 leaves only the listener's reverb.
The cost of reflections is proportional to this number rather than to the number of sounds, so it is the main control over performance. See also reflection_group_size.
Changing this rebuilds the environment's simulator and audio effects the next time the simulation is idle and update() is called, which cuts off reverb tails, so reflections briefly drop out. Avoid changing it every frame.
output_mixer
The mixer that the environment's reflections and pathed sound are sent to.
mixer@ output_mixer;
Remarks:
Sounds and mixers attached to the environment keep playing into their own mixers, only the reverberation the environment adds is routed here. Set it to a mixer of your own to apply effects or volume to all of an environment's reflections together.
pathing
Whether sound is heard travelling around obstacles between the probes of the environment.
bool pathing;
Remarks:
The default is false. Pathing needs paths to be baked, see bake(), and then lets a sound that is occluded by a wall still be heard coming from where it actually reaches the listener, such as through a doorway. It is heard in proportion to how occluded the direct sound is, and uses each source's apply_occlusion and apply_pathing properties.
Changing this rebuilds the environment's simulator and audio effects the next time the simulation is idle and update() is called, which cuts off reverb tails, so reflections briefly drop out. Avoid changing it every frame.
pathing_level
The volume multiplier of pathed sound.
float pathing_level;
Remarks:
The default is 1 and the minimum is 0.
pathing_simulation_time
How long the most recent pathing simulation took, in milliseconds.
const float pathing_simulation_time;
Remarks:
This is 0 while pathing is disabled or no paths have been baked.
probe_count
The number of probes placed with generate_probes() and add_probe().
const uint probe_count;
raycaster
The object this environment traces rays through, as last set with set_raycaster().
const ref@ raycaster;
Remarks:
This is null until a raycaster has been set, and is not cleared by a call to set_raycaster() that fails.
reflection_bounces
The number of times each ray may bounce around the scene.
int reflection_bounces;
Remarks:
The default is 32 and values are clamped between 1 and 64. The length of reverb that can be heard depends on this, as a ray that has reached its bounce limit stops contributing, so few bounces produce short reverb tails even if reflection_duration is long. This takes effect at the next reflection simulation.
reflection_duration
The length in seconds of the reverb tail that is simulated, and thus the longest reverb the environment can produce.
float reflection_duration;
Remarks:
The default is 1 and values are clamped between 0.1 and 10. Convolution cost grows with this value, and reflection_bounces must be high enough to fill it.
Changing this rebuilds the environment's simulator and audio effects the next time the simulation is idle and update() is called, which cuts off reverb tails, so reflections briefly drop out. Avoid changing it every frame.
reflection_group_size
How many meters apart sounds can be and still share a reflection group.
float reflection_group_size;
Remarks:
The default is 3 and values are clamped between 0 and 1000. A sound joins an existing group if it is within this distance of the group and nothing blocks the view between them, otherwise it takes a group of its own while any are free. Larger values let more sounds share reflections and save groups, at the cost of those sounds hearing slightly less accurate reverb. This takes effect at the next update.
reflection_order
The ambisonic order that reflections are simulated and decoded at.
int reflection_order;
Remarks:
The default is 1 and values are clamped between 0 and 3. Higher orders resolve the direction of reflections more precisely but the cost grows with the square of (order + 1). Order 0 has no directional information at all.
Changing this rebuilds the environment's simulator and audio effects the next time the simulation is idle and update() is called, which cuts off reverb tails, so reflections briefly drop out. Avoid changing it every frame.
reflection_rays
The number of rays traced from each reflection group per reflection simulation.
int reflection_rays;
Remarks:
The default is 2048 and values are clamped between 1 and 65536. More rays give smoother, more accurate reflections at the cost of simulation time. Because Steam Audio averages the results of consecutive simulations, a modest number of rays works well.
Changing this rebuilds the environment's simulator and audio effects the next time the simulation is idle and update() is called, which cuts off reverb tails, so reflections briefly drop out. Avoid changing it every frame.
reflection_simulation_time
How long the most recent reflection simulation took, in milliseconds.
const float reflection_simulation_time;
Remarks:
Compare this to simulation_interval. If simulations take much longer than the interval, reflections will update less often than you asked, and lowering reflection_rays, max_sources or reflection_order will help.
reflection_simulations
The number of reflection simulations that have completed since the environment was created.
const uint reflection_simulations;
Remarks:
This is mostly useful for waiting until the first reflections of a new environment or scene are ready if you find that some initial sounds in your environment don't sound fully reflected, for example while (env.reflection_simulations < 2) { env.update(); wait(10); }.
reflection_type
The kind of reflection effect the environment uses.
sound_environment_reflection_type reflection_type;
Remarks:
The default is SOUND_ENVIRONMENT_REFLECTIONS_HYBRID. See the sound_environment_reflection_type enum for what each type does.
Parametric and hybrid reflections cannot use Steam Audio's reflection mixer, so for them use_reflection_mixer has no effect.
Changing this rebuilds the environment's simulator and audio effects the next time the simulation is idle and update() is called, which cuts off reverb tails, so reflections briefly drop out. Avoid changing it every frame.
reflections_highpass
The cutoff in hertz of a high pass filter applied to the environment's reflections.
float reflections_highpass;
Remarks:
The default is 160 and values are clamped between 0 and 45 percent of the engine's sample rate. Simulated reflections tend to sound boomy in the low end, and filtering it out makes them cleaner. 0 disables the filter.
reflections_level
The volume multiplier of all reflections in the environment.
float reflections_level;
Remarks:
The default is 0.5 and the minimum is 0. Simulated reflections are quite loud when taken at face value, so the default is toned down. This is multiplied by each source's own reflections_level, and 0 effectively turns reflections off.
reflections_width
How wide the stereo image of reflections is.
float reflections_width;
Remarks:
The default is 4 and values are clamped between 0 and 8. Binaurally decoded reverb is highly correlated between the ears and sounds narrow, so the difference between the channels is multiplied by this value. 1 leaves the decoded reflections untouched and 0 makes them mono. This only has an effect on stereo output.
reverb3d
The reverb3d object that routes sounds through this environment.
const reverb3d@ reverb3d;
Remarks:
Every sound and mixer attached to the environment is attached to this reverb3d, and its output mixer is the one returned by output_mixer. You rarely need to touch it directly, attach() and detach() are the intended way to move sounds in and out of the environment if sound_environment::new_sound is not enough.
simulating_reflections
Whether a reflection simulation is running on the environment's worker thread right now.
const bool simulating_reflections;
simulation_interval
The minimum time in seconds between the starts of two reflection simulations.
float simulation_interval;
Remarks:
The default is 0.1 and the minimum is 0. A reflection simulation only starts when the previous one has finished, so the real interval is the greater of this value and reflection_simulation_time. Lower values make reflections follow movement more closely but use more processor time.
simulation_threads
The number of threads Steam Audio uses to trace reflection rays.
int simulation_threads;
Remarks:
The default is half of the machine's processor threads, and values are clamped between 1 and 64. These threads compete with the audio thread, so more is not always better.
Changing this rebuilds the environment's simulator and audio effects the next time the simulation is idle and update() is called, which cuts off reverb tails, so reflections briefly drop out. Avoid changing it every frame.
source_count
The number of sounds and mixers currently attached to the environment.
const uint source_count;
use_baked_reverb
Whether the listener's reverb is looked up from baked data when the listener is within one of the environment's probes.
bool use_baked_reverb;
Remarks:
The default is true. This only does anything once reverb has been baked, see bake(). Looking the reverb up is much cheaper than simulating it and allows for higher quality than can be afforded in real time, but it is only used for the listener's own reverb, groups elsewhere are still simulated.
use_listener_reverb
Whether sounds that have no reflection group of their own hear reflections simulated at the listener's position.
bool use_listener_reverb;
Remarks:
The default is true. This is what lets a brand new sound, such as a footstep, reverberate immediately before its own group has been simulated, and also what sounds hear when every group is taken. The reverb is attenuated by the sound's distance from the listener. When false, such sounds have no reflections.
use_reflection_mixer
Whether convolved reflections of all groups are combined by Steam Audio's reflection mixer before being decoded.
bool use_reflection_mixer;
Remarks:
The default is true. The mixer decodes the sound field once for the whole environment rather than once per group, which is cheaper, and it is only used when reflection_type is SOUND_ENVIRONMENT_REFLECTIONS_CONVOLUTION. Parametric and hybrid reflections are summed without it whatever this is set to.
sound_environment_source
A sound_environment_source holds the settings and simulation results that a sound_environment keeps for one attached sound or mixer. It is created by the environment when a sound or mixer is attached, and cannot be created directly. Retrieve one with sound_environment::get_source().
The settings (the properties beginning with apply_ and the occlusion and transmission settings) can be changed at any time and are used by the next simulation. The remaining read only properties show the results of the most recent simulation run, which is useful for debugging or for driving gameplay, for example making an enemy notice a sound that isn't blocked by walls.
A source stays valid for as long as you hold a handle to it, but once its sound or mixer is detached or destroyed it no longer updates.
Properties
apply_occlusion
Whether the simulated occlusion is applied to this sound, so that it is muffled and quieter when something is between it and the listener.
bool apply_occlusion;
Remarks:
The default is true. When false, the sound is also not affected by transmission or pathing.
apply_pathing
Whether this sound is heard around obstacles through baked paths.
bool apply_pathing;
Remarks:
The default is true, but nothing happens unless the environment's pathing property is enabled and paths have been baked. This has no effect if apply_occlusion is false.
apply_reflections
Whether this sound contributes to and hears the environment's reflections.
bool apply_reflections;
Remarks:
The default is true. When false, the sound is heard without reverb.
apply_transmission
Whether sound that passes through obstacles is heard.
bool apply_transmission;
Remarks:
The default is true. When an obstacle occludes the sound, transmission decides how much gets through the material of the obstacle, separately in the low, mid and high frequency bands. When false, an occluded sound is fully silent unless it is heard through pathing. This has no effect if apply_occlusion is false.
occlusion
How much of the direct sound reaches the listener unobstructed, from 0 (completely occluded) to 1 (in plain view).
const float occlusion;
Remarks:
With volumetric occlusion this can be anywhere in between when the sound is partially visible.
occlusion_radius
The radius in meters of the sphere that this sound is treated as coming from when its occlusion type is volumetric.
float occlusion_radius;
Remarks:
The default is 1 and the minimum is 0. A larger radius means the sound is partially heard as it moves past the edge of an obstacle over a larger distance. This is ignored for raycast occlusion.
occlusion_samples
The number of points on the sound's sphere that are tested when its occlusion type is volumetric.
int occlusion_samples;
Remarks:
The default is 16 and values are clamped between 1 and 16, the most that the environment's simulator supports. More samples give smoother changes in occlusion but cost more simulation time. This is ignored for raycast occlusion.
occlusion_type
How occlusion of this sound is determined.
sound_environment_occlusion_type occlusion_type;
Remarks:
The default is SOUND_ENVIRONMENT_OCCLUSION_RAYCAST. See the sound_environment_occlusion_type enum for the difference.
reflection_group
The index of the reflection group this sound is currently assigned to, or -1 if it has none.
const int reflection_group;
Remarks:
A sound without a group of its own is heard with the listener's reverb attenuated if the environment's use_listener_reverb is enabled. Groups are numbered from 0 up to the environment's max_sources and sounds near each other are likely to be in the same group. You will probably rarely have to touch this property on your own unless you are trying to debug performance bottlenecks.
reflections_level
The volume multiplier of this sound's reflections.
float reflections_level;
Remarks:
The default is 1 and the minimum is 0. This is multiplied by the environment's reflections_level, so a value of 2 makes this sound's reflections twice as loud as those of a sound with the default.
reflections_simulated
Whether the reflections of the group this sound belongs to have been simulated at the group's current position.
const bool reflections_simulated;
Remarks:
While this is false, the sound is heard with the listener's reverb attenuated to the sources distance or the reflections of the group it last belonged to.
reverb_time_high
The time in seconds the high frequencies of the reverb heard by this sound take to decay by 60 decibels.
const float reverb_time_high;
Remarks:
See reverb_time_low.
reverb_time_low
The time in seconds the low frequencies of the reverb heard by this sound take to decay by 60 decibels.
const float reverb_time_low;
Remarks:
This is estimated from the reflections of the sound's group, and is 0 until they have been simulated. A small furnished room has a short reverb time, while a large hard room has a long one.
reverb_time_mid
The time in seconds the middle frequencies of the reverb heard by this sound take to decay by 60 decibels.
const float reverb_time_mid;
Remarks:
See reverb_time_low.
simulated
Whether the direct simulation of this sound has completed at least once.
const bool simulated;
Remarks:
Until then the occlusion and transmission values below hold their defaults. Before it has been simulated, the sound is treated as fully occluded, so that a brand new sound doesn't briefly play at full volume through a wall.
transmission_high
How much of the high frequencies (above about 8000 hertz) of the sound passes through the obstacles between it and the listener, from 0 to 1.
const float transmission_high;
Remarks:
See transmission_low.
transmission_low
How much of the low frequencies (below about 800 hertz) of the sound passes through the obstacles between it and the listener, from 0 to 1.
const float transmission_low;
Remarks:
The transmission values describe what remains of an occluded sound, and are 1 when nothing is in the way. A brick wall, for example, lets through only about 1.5 percent of the sound at every frequency, while thin materials let through more of the low end than the high end.
transmission_mid
How much of the middle frequencies (about 800 to 8000 hertz) of the sound passes through the obstacles between it and the listener, from 0 to 1.
const float transmission_mid;
Remarks:
See transmission_low.
transmission_rays
The number of rays traced from the listener to this sound to find the materials that sound passes through.
int transmission_rays;
Remarks:
The default is 3 and values are clamped between 1 and 64. More rays give a better result when the sound is behind several obstacles of different materials.
enums
sound_environment_occlusion_type
This is a list of the ways a sound_environment_source can determine how occluded it is, set with sound_environment_source::occlusion_type.
- SOUND_ENVIRONMENT_OCCLUSION_RAYCAST: a single ray is traced between the sound and the listener, so a sound is either occluded or not. This is the cheapest type, and ignores
occlusion_radiusandocclusion_samples. - SOUND_ENVIRONMENT_OCCLUSION_VOLUMETRIC: the sound is treated as a sphere with the source's
occlusion_radius, and the fraction ofocclusion_samplespoints on it that the listener can see gives the occlusion. Sounds fade in and out gradually as they pass the edge of an obstacle, which is smoother and more realistic.
sound_environment_reflection_type
This is a list of the kinds of reflection effects a sound_environment can use, set with sound_environment::reflection_type.
- SOUND_ENVIRONMENT_REFLECTIONS_CONVOLUTION: the most accurate type, which convolves each reflection group's sound with the full simulated impulse response of the room, including the direction each reflection comes from. This is the most expensive on the audio thread, and the only type that can use the environment's reflection mixer.
- SOUND_ENVIRONMENT_REFLECTIONS_PARAMETRIC: the cheapest type, which instead of convolving the room's response applies a simple reverb whose decay times in each frequency band come from the simulation. It captures the character of a room but not the individual echoes or their directions, and tends to sound rather mono - best used in limited resource sanarios if wanted.
- SOUND_ENVIRONMENT_REFLECTIONS_HYBRID: convolves the early part of the response, which has the most perceptible detail, and replaces the long tail with a parametric reverb. This is the default, and approaches the quality of convolution at a much lower cost for long reverbs. See
sound_environment::hybrid_transition_timeandsound_environment::hybrid_overlap.
global properties
audio_attenuator_phonon
A value for the audio_attenuator enum's place that selects Steam Audio's attenuator, which makes sounds quieter with distance and dulls them with air absorption.
const int audio_attenuator_phonon;
Remarks:
Though it's internally registered as a standard integer, this is in all practicality an extension of the audio_attenuator enum. It can be used anywhere an audio_attenuator is accepted, such as set_sound_default_3d_attenuator() and sound::set_3d_attenuator().
The volume follows NVGT's usual distance curve, so a sound's min_distance, max_distance and rolloff behave as they do with audio_attenuator_basic. On top of this, Steam Audio's air absorption muffles high frequencies with distance, taking one unit of distance to be about 0.3 meters by default. NVGT's built in audio_attenuator_hrtf does something very similar.
audio_panner_phonon_hrtf
A value for the audio_panner enum's place that selects Steam Audio's HRTF panner, which makes sounds seem to come from a direction around the listener and works best with headphones.
const int audio_panner_phonon_hrtf;
Remarks:
This is an integer rather than a member of the audio_panner enum because plugins cannot add values to builtin enums. It can be used anywhere an audio_panner is accepted, such as set_sound_default_3d_panner() and sound::set_3d_panner().
Within 5 units of the listener, sounds are increasingly unpositioned, so that sounds situated at the same position as the listener are not snapped to one direction. NVGT also has its own built in HRTF, audio_panner_hrtf, which is derived from the Synthizer library and is used by set_sound_global_hrtf(). The two sound slightly different, so this one exists for choosing Steam Audio's if you prefer it.
Example:
#pragma plugin nvgt_phonon
void main() {
set_sound_default_3d_panner(audio_panner_phonon_hrtf);
set_sound_default_3d_attenuator(audio_attenuator_phonon);
sound s;
s.load("music.ogg");
s.set_position_3d(5, 0, 0);
s.play_looped();
alert("HRTF", "A sound should be playing to your right.");
}