class Mixer

Defined at line 31 of file ../../src/media/audio/audio_core/mixer/mixer.h

The Mixer class provides format-conversion, rechannelization, rate-connversion, and gain/mute

scaling. Each source in a multi-stream mix has its own Mixer instance. When Mixer::Mix() is

called, it adds that source's contribution, by reading audio from its source, generating the

appropriately processed result, and summing this output into a common destination buffer.

Public Members

Gain gain
TimelineFunction source_ref_clock_to_frac_source_frames
uint32_t source_ref_clock_to_frac_source_frames_generation
TimelineFunction clock_mono_to_frac_source_frames
TimelineFunction dest_frames_to_frac_source_frames
unique_ptr scale_arr
static const int64_t kScaleArrLen

Public Methods

void Mixer (std::shared_ptr<media_audio::Sampler> sampler, Gain::Limits gain_limits)

Defined at line 49 of file ../../src/media/audio/audio_core/mixer/mixer.cc

std::unique_ptr<Mixer> NoOp ()

Returns a no-op mixer.

Defined at line 57 of file ../../src/media/audio/audio_core/mixer/mixer.cc

std::unique_ptr<Mixer> Select (const fuchsia::media::AudioStreamType & source_format, const fuchsia::media::AudioStreamType & dest_format, Resampler resampler_type, Gain::Limits gain_limits)

Select

Select an appropriate mixer instance, based on an optionally-specified resampler type, or else

by the properties of source/destination formats.

When calling Mixer::Select, resampler_type is optional. If a caller specifies a particular

resampler, Mixer::Select will either instantiate what was requested or return nullptr, even if

it otherwise could have successfully instantiated a different one. Setting this to non-Default

says "I know exactly what I need: I want you to fail rather than give me anything else."

If resampler_type is absent or Default, this is determined by algorithm. For optimum system

performance across changing conditions, callers should use Default whenever possible.

Defined at line 68 of file ../../src/media/audio/audio_core/mixer/mixer.cc

void Mix (float * dest_ptr, int64_t dest_frames, int64_t * dest_offset_ptr, const void * source_void_ptr, int64_t source_frames, Fixed * source_offset_ptr, bool accumulate)

Mix

Perform a mixing operation from source buffer into destination buffer.

Within Mix(), the following source/dest/rate constraints are enforced:

* source_frames must be at least 1

* source_offset must be at least -pos_filter_width

cannot exceed source_frames

* dest_offset cannot exceed dest_frames

* step_size must exceed zero

* step_size_modulo must be either zero or less than denominator

* source_position_modulo must be either zero or less than denominator

Parameters

dest_ptr The pointer to the destination buffer, into which frames will be mixed.
dest_frames The total number of frames of audio which comprise the destination buffer.
dest_offset_ptr The pointer to the offset (in output frames) from start of dest buffer, at which we should mix destination frames. Essentially this tells Mix how many 'dest' frames to skip over, when determining where to place the first mixed output frame. When Mix has finished, dest_offset is updated to indicate the destination buffer offset of the next frame to be mixed.
source_void_ptr Pointer to source buffer, containing frames to be mixed to the dest buffer.
source_frames Total number of incoming frames in the source buffer.
source_offset_ptr A pointer to the offset from start of source buffer, at which the first source frame should be sampled. When Mix has finished, source_offset will be updated to indicate the offset of the sampling position of the next frame to be sampled. When Mix has finished, frames before source_offset are no longer needed and can be discarded.
accumulate When true, Mix will accumulate into the destination buffer (sum the mix results with existing values in the dest buffer). When false, Mix will overwrite any existing destination buffer values with its mix output.

Defined at line 131 of file ../../src/media/audio/audio_core/mixer/mixer.cc

Fixed pos_filter_width ()

Filter widths

The positive and negative widths of the filter for this mixer, expressed in fixed-point

fractional source subframe units. These widths convey which source frames will be referenced by

the filter, when producing output for a specific instant in time. Positive filter width refers

to how far forward (positively) the filter looks, from the PTS in question; negative filter

width refers to how far backward (negatively) the filter looks, from that same PTS.

For example, a pure "sample and hold" resampler might have a negative filter width of almost

one frame and a positive filter width of zero.

Note that filter widths do NOT include the center PTS in question, so in that regard they are

not equivalent to the filter's length.

Let:

P = pos_filter_width()

N = neg_filter_width()

S = An arbitrary point in time at which the source stream will be sampled.

X = The PTS of an source frame.

If (X >= (S - N))

&

&

(X

<

= (S + P))

Then source frame X is within the filter and contributes to mix operation.

Conversely, source frame X contributes to the output samples S where

(S >= X - P) and (S

<

= X + N)

Defined at line 141 of file ../../src/media/audio/audio_core/mixer/mixer.h

Fixed neg_filter_width ()

Defined at line 142 of file ../../src/media/audio/audio_core/mixer/mixer.h

media_audio::Sampler::State & state ()

Defined at line 144 of file ../../src/media/audio/audio_core/mixer/mixer.h

const media_audio::Sampler::State & state ()

Defined at line 145 of file ../../src/media/audio/audio_core/mixer/mixer.h

void EagerlyPrepare ()

Eagerly precompute any needed data. If not called, that data should be lazily computed on the

first call to Mix().

TODO(https://fxbug.dev/42121558): This is for tests only and can be removed once filter

creation is eager.

Defined at line 151 of file ../../src/media/audio/audio_core/mixer/mixer.h

Enumerations

enum Resampler
Name Value
Default 0
SampleAndHold 1
WindowedSinc 2

Resampler enum

This enum lists Fuchsia's available resamplers. Callers of Mixer::Select optionally use this

to specify a resampler type. Default allows an algorithm to select a resampler based on the

ratio of incoming-to-outgoing rates (currently we use WindowedSinc for all ratios except 1:1).

Defined at line 40 of file ../../src/media/audio/audio_core/mixer/mixer.h

Records