The Audio Graph. - the Home Page of Allan C. Milne.

advertisement
The Audio
Processing
Graph
© Allan C. Milne
Abertay University
v14.2.14
Agenda.
The audio processing graph.
Submix voices.
Using submix voices.
The audio graph.
• The audio processing graph is the set of
– All voices, with their contained effects; and
– the interconnections between these voices.
• The entry points to this graph are the
client-supplied audio streams;
– As submitted to a source voice.
• Exit from the graph is to the audio
device;
– via the mastering voice.
Graph processing.
• The audio graph is maintained and
processed by the XAudio2 engine.
• All processing is on a separate thread.
• Periodicity of this graph is currently
– 10ms for Windows;
– 5 1/3ms on Xbox.
Graph state changes.
•
•
•
•
•
•
Creating and destroying voices.
Starting or stopping voices.
Changing the destinations of a voice.
Modifying effect chains.
Enabling or disabling effects.
Setting parameters on effects, built-in
SRCs, filters, volumes, and mixers.
Internal representation.
• Audio data is stored and processed in
32-bit floating point PCM form.
• Channel count and sample rate can
vary within the graph.
– Determined by the voice type and
parameters.
• Sample rate and channel conversions
between voices are handled by the
XAudio2 engine as the audio data
travels through the graph.
Voice type parameters.
• IXAudio2SourceVoice:
– Channel count and sample rate of
destination voices.
• IXaudio2SubmixVoice and
IXAudio2MasteringVoice:
– Input channels and sample rate used to
create the voice.
Configuration limitations.
• All destination voices for a voice must
have the same sample rate.
• Effects can change a voice’s channel
count but not its sample rate.
• An effect chain's output channel count
must match that of the voices to which it
sends.
Source voice sample rates.
• Variable sample rate conversion (SRC)
converts data from the input sample
rate to the rate required for the send list.
– NULL send list:
• target will be the mastering voice's input
sample rate.
– Send list with one voice:
• Target is that voice's input sample rate.
• Send list with multiple voices:
– all the output voices must be running at the
same input sample rate.
Submix voices.
• Send their output to 1 or more submix
voices and /or the mastering voice.
• Can have multiple voices feeding them.
• Mix all inputs and operate on the result.
• Can apply volume adjustment, matrix
mix, filters and effect chains.
• Have a fixed SRC to convert from input
to required output sample rate.
Why use a submix voice?
• Performance improvements.
• Applying the same processing to a
collection of sounds.
• Abstracting some or all processing from
a source voice.
• Provide a single voice output for a game
component.
Creating a submix voice.
IXaudio2SubmixVoice *submix;
HRESULT hr;
hr = engine->CreateSubmixVoice (&submix, 2, 48000,
XAUDIO2_VOICE_USEFILTER);
if (FAILED (hr)) { ... … }
• 2 = number of input channels.
• 48000 = input sample rate.
• Flag = enable filtering.
• No send list so destination
will be the mastering voice.
CreateSubmixVoice(…)
• This factory method is
overloaded:
– Processing stage (see next slide).
– Send list;
– default is to send to mastering voice.
– Effect chain.
Submix processing stage.
• The stage parameter specifies when
this submix voice is processed:
– Before submix voices with a larger value;
– After submix voices with a smaller value.
• Submix voices with the same value are
processed in any order.
• A submix voice cannot send to a submix
voice with a lower or equal value.
– Prevents audio being lost due to a submix cycle.
• Implies a hierarchical design strategy when
creating complex audio scenes.
A simple scenario.
• route a source voice (source)
– to a single submix voice (submix);
– Add a filter to the submix voice.
• The source voice is no longer
connected to the mastering voice;
– So cannot be heard directly.
• The submix voice will be connected to
the mastering voice via its send list;
– Only the output from this submix voice will
be heard.
Applying the filter.
XAUDIO2_FILTER_PARAMETERS filterParameters;
filterParameters.Frequency = 0.75f;
filterParameters.OneOverQ = 1.0f;
filterParameters.Type = LowPassFilter;
submix->SetFilterParameters(&filterParameters);
• This is the same as applying a
filter to a source voice.
Routing to a submix voice.
XAUDIO2_SEND_DESCRIPTOR sendDesc = { 0, submix };
XAUDIO2_VOICE_SENDS sendList = { 1, &sendDesc };
source ->SetOutputVoices (&sendList);
• XAUDIO2_SEND_DESCRIPTOR :
– A voice to send to.
• XAUDIO2_VOICE_SENDS :
– List of individual send descriptors.
Notes on routing.
• XAUDIO2_SEND_DESCRIPTOR :
– A voice to send to, defined by
• flag (= 0 or XAUDIO2_SEND_USEFILTER);
• Pointer to XAudio2 voice.
• XAUDIO2_VOICE_SENDS :
– list of individual send descriptors, defined by
• Number of sends;
• Array of send descriptor structs.
• source ->SetOutputVoices (NULL);
– routes to the default mastering
voice.
Some notes.
• This seperates the source voice from
the filtering process.
• Multiple source voices can send to this
submix voice,
– resulting in all of them having the same
filtering applied.
• Switch off filtering by rerouting the
source voice to the mastering voice.
– Source->SetOutputVoices(NULL);
Download