AudioConverter¶
class AudioConverter final
Allow converting audio buffers between different sample rates and channel counts.
Note
This class uses the Resampler
class to perform sample rate conversion.
Note
Only mono to stereo or vice versa conversions are currently supported.
Types¶
Name | Description |
---|---|
Settings | Store conversion settings for an AudioConverter instance. |
Functions¶
Name | Description |
---|---|
AudioConverter | Default constructor. |
~AudioConverter | Destroys the instance and release associated resources. |
Configure | Initializes the audio converter with the given conversion settings. |
Process | Converts the audio buffer from the source sample rate and channel count to the target sample rate and channel count. |
SetSampleRate | Updates the source sample rate and target sample rate. |
GetRequiredInputFrameCount | Returns the required number of frames to have as input for the given amount of output frames. |
GetExpectedOutputFrameCount | Returns the expected number of frames to have as output for the given amount of input frames. |
GetInputLatency | Returns the current input latency in frames. |
GetOutputLatency | Returns the current output latency in frames. |
Reset | Resets the internal state of the converter. |
Function Details¶
AudioConverter¶
AudioConverter()
Default constructor.
Configure¶
bool Configure(const Settings& settings)
Initializes the audio converter with the given conversion settings.
- Parameter
settings
- The conversion settings.
- Return
true
if the initialization was successful,false
otherwise.
GetExpectedOutputFrameCount¶
[[nodiscard]] AmUInt64 GetExpectedOutputFrameCount(AmUInt64 inputFrameCount) const
Returns the expected number of frames to have as output for the given amount of input frames.
- Parameter
inputFrameCount
- The number of input frames.
- Return
- The expected number of output frames for the given input frame count.
GetInputLatency¶
[[nodiscard]] AmUInt64 GetInputLatency() const
Returns the current input latency in frames.
- Return
- The current input latency in frames.
GetOutputLatency¶
[[nodiscard]] AmUInt64 GetOutputLatency() const
Returns the current output latency in frames.
- Return
- The current output latency in frames.
GetRequiredInputFrameCount¶
[[nodiscard]] AmUInt64 GetRequiredInputFrameCount(AmUInt64 outputFrameCount) const
Returns the required number of frames to have as input for the given amount of output frames.
- Parameter
outputFrameCount
- The number of output frames.
- Return
- The input frame count needed to produce the given output frame count.
Process¶
void Process(const AudioBuffer& input, AmUInt64& inputFrames, AudioBuffer& output, AmUInt64& outputFrames)
Converts the audio buffer from the source sample rate and channel count to the target sample rate and channel count.
- Parameter
input
- The source audio buffer.
- Parameter
inputFrames
- The number of frames to process in the input audio buffer.
- Parameter
output
- The target audio buffer to store the converted audio.
- Parameter
outputFrames
- The number of frames to process in the target audio buffer.
Reset¶
void Reset()
Resets the internal state of the converter.
SetSampleRate¶
void SetSampleRate(AmUInt64 sourceSampleRate, AmUInt64 targetSampleRate)
Updates the source sample rate and target sample rate.
- Parameter
sourceSampleRate
- The source sample rate.
- Parameter
targetSampleRate
- The target sample rate.
~AudioConverter¶
~AudioConverter()
Destroys the instance and release associated resources.