class State
Defined at line 67 of file ../../src/media/audio/lib/processing/sampler.h
Class that wraps all the state that is needed by the `Process` function.
The primary state is the source "stride", which describes how many fractional source frames we
should advance for each destination frame. Specifically, each destination frame is equivalent
to `step_size + step_size_modulo / step_size_denominator` source frames, where
`step_size_modulo / step_size_denominator` is a fractional subframe.
If `step_size_modulo == 0`, the source stride divides evenly into a destination frame and
`step_size_modulo / step_size_denominator` can be ignored.
By using the source stride, all the position related information that are needed between the
`Process` calls are maintained as part of this state, which include the long-running source and
destination positions that are used for clock error detection/tuning.
Public Methods
void AdvanceAllPositionsTo (int64_t dest_target_frame)
Advances all long-running positions to `dest_target_frame`. This is useful when resolving
discontinuities until an absolute target frame, without having to refer back to
`next_dest_frame`.
Defined at line 23 of file ../../src/media/audio/lib/processing/sampler.cc
void AdvanceAllPositionsBy (int64_t dest_frames)
Advances all long-running positions by `dest_frames`. This is useful when resolving
discontinuities resulting from a gap in the source stream.
Defined at line 27 of file ../../src/media/audio/lib/processing/sampler.cc
void UpdateRunningPositionsBy (int64_t dest_frames)
Updates long-running positions by `dest_frames`.
Defined at line 31 of file ../../src/media/audio/lib/processing/sampler.cc
void ResetPositions (int64_t target_dest_frame, const media::TimelineFunction & dest_frames_to_frac_source_frames)
Resets long-running positions. This should be called when a destination discontinuity occurs
to set `next_dest_frame` to the specified value and calculate `next_source_frame` based on
the `dest_frames_to_frac_source_frames` transform.
Defined at line 167 of file ../../src/media/audio/lib/processing/sampler.cc
void ResetSourceStride (const media::TimelineRate & source_frac_frame_per_dest_frame)
Resets source stride with a given `source_frac_frame_per_dest_frame` rate.
Defined at line 35 of file ../../src/media/audio/lib/processing/sampler.cc
zx::time MonoTimeFromRunningSource (const media::TimelineFunction & clock_mono_to_frac_source_frames)
Translates the long-running source position into monotonic nsecs, using the nsec-to-Fixed
`clock_mono_to_frac_source_frames` transform.
To scale from reference units to subject units, `TimelineFunction::Apply` does this:
`(in_param - reference_offset) * subject_delta / reference_delta + subject_offset`
`clock_mono_to_frac_source_frames` contains the correspondence we need (but inversed; subject
is `frac_source`, reference is monotonic nsecs). To more accurately calculate monotonic nsecs
from `frac_source` (including modulo), we scale the function by `step_size_denominator`, then
we can include `source_pos_modulo` at full resolution and round when reducing to nsecs. So in
the `TimelineFunction::Apply` equation above, we will use:
```
in_param:
next_source_frame().raw_value() * step_size_denominator() + source_pos_modulo()
reference_offset:
clock_mono_to_frac_source_frames.subject_time() * step_size_denominator()
subject_delta and reference_delta:
used as-is while remembering that the step size is inverted
subject_offset:
clock_mono_to_frac_source_frames.reference_time() * step_size_denominator()
```
Because all the initial factors are 64-bit, our denominator-scaled version must use 128-bit.
Even then, we might overflow depending on parameters, so we scale back denominator if needed.
TODO(https://fxbug.dev/42167787): Generalize this (remove the scale-down denominator
optimization) and extract the functionality into a 128-bit template specialization of
`TimelineRate` and `TimelineFunction`.
Defined at line 178 of file ../../src/media/audio/lib/processing/sampler.cc
int64_t DestFromSourceLength (Fixed source_length)
Returns corresponding destination length in frames for a given `source_length` in frames.
Defined at line 101 of file ../../src/media/audio/lib/processing/sampler.cc
Fixed step_size ()
Returns fractional step size for the source, i.e., "stride" for how much to increment the
sampling position in the source stream, for each destination frame produced.
Defined at line 131 of file ../../src/media/audio/lib/processing/sampler.h
uint64_t step_size_modulo ()
Expresses (along with `step_size_denominator`) leftover rate precision that `step_size`
cannot express, which is a fractional value of the `step_size` unit that source position
should advance, for each destination frame.
Defined at line 136 of file ../../src/media/audio/lib/processing/sampler.h
uint64_t step_size_denominator ()
Expresses (along with `step_size_modulo` and `source_pos_modulo`) leftover rate and position
precision that `step_size` and `Source::frame_offset_ptr` (respectively) cannot express.
Defined at line 140 of file ../../src/media/audio/lib/processing/sampler.h
Fixed SourceFromDestLength (int64_t dest_length)
Returns corresponding source length in frames for a given `dest_length` in frames.
Defined at line 141 of file ../../src/media/audio/lib/processing/sampler.cc
uint64_t source_pos_modulo ()
Expresses (along with `step_size_denominator`) leftover position precision that `Source` and
`Dest` parameters cannot express. When present, `source_pos_modulo` and
`step_size_denominator` express a fractional value of the `Source::frame_offset_ptr` unit,
for additional precision on current position.
Defined at line 146 of file ../../src/media/audio/lib/processing/sampler.h
void set_source_pos_modulo (uint64_t source_pos_modulo)
Defined at line 147 of file ../../src/media/audio/lib/processing/sampler.h
int64_t next_dest_frame ()
Represents the next destination frame to process.
Defined at line 152 of file ../../src/media/audio/lib/processing/sampler.h
void set_next_dest_frame (int64_t next_dest_frame)
Defined at line 153 of file ../../src/media/audio/lib/processing/sampler.h
Fixed next_source_frame ()
Represents the next source frame to process.
Defined at line 156 of file ../../src/media/audio/lib/processing/sampler.h
void set_next_source_frame (Fixed next_source_frame)
Defined at line 157 of file ../../src/media/audio/lib/processing/sampler.h
zx::duration source_pos_error ()
Represents the difference between `next_source_frame` (maintained on a relative basis after
each `Process` call), and the clock-derived absolute source position. Upon a destination
frame discontinuity, `next_source_frame` is reset to that clock-derived value, and this field
is set to zero. This field sets the direction and magnitude of any steps taken for clock
reconciliation.
Defined at line 164 of file ../../src/media/audio/lib/processing/sampler.h
void set_source_pos_error (zx::duration source_pos_error)
Defined at line 165 of file ../../src/media/audio/lib/processing/sampler.h