src/media/audio/audio_core/mixer/gain.cc
// Populate an array of gain scales. Currently we handle only SCALE_LINEAR ramps
Populate an array of gain scales. Currently we handle only SCALE_LINEAR ramps
Populate an array of gain scales . Currently we handle only SCALE_LINEAR ramps
void Gain::GetScaleArray(AScale* scale_arr, uint32_t num_frames,
                         const TimelineRate& destination_frames_per_reference_tick) {
  TRACE_DURATION("audio", "Gain::GetScaleArray");
  if (num_frames == 0) {
    return;
  }
  FX_CHECK(scale_arr != nullptr);
  AScale scale;
  if (!IsRamping()) {
    scale = GetGainScale();
    for (uint32_t idx = 0; idx < num_frames; ++idx) {
      scale_arr[idx] = scale;
    }
  } else {
    FX_CHECK(destination_frames_per_reference_tick.invertible()) << "Output clock must be running!";
    TimelineRate output_to_local = destination_frames_per_reference_tick.Inverse();
    AScale dest_scale = DbToScale(target_dest_gain_db_);
    AScale start_scale = start_src_scale_ * dest_scale;
    AScale end_scale = end_src_scale_ * dest_scale;
    for (uint32_t idx = 0; idx < num_frames; ++idx) {
      zx::duration frame_time = zx::nsec(output_to_local.Scale(frames_ramped_ + idx));
      if (frame_time >= source_ramp_duration_) {
        scale_arr[idx] = end_scale;
      } else {
        scale_arr[idx] =
            start_scale + (static_cast<double>(end_scale - start_scale) * frame_time.to_nsecs()) /
                              source_ramp_duration_.to_nsecs();
      }
    }
  }
}
void Gain :: GetScaleArray ( AScale * scale_arr , uint32_t num_frames , const TimelineRate & destination_frames_per_reference_tick ) { TRACE_DURATION ( " " , " " ) ; if ( num_frames == 0 ) { return ; } FX_CHECK ( scale_arr != nullptr ) ; AScale scale ; if ( ! IsRamping ( ) ) { scale = GetGainScale ( ) ; for ( uint32_t idx = 0 ; idx < num_frames ; ++ idx ) { scale_arr [ idx ] = scale ; } } else { FX_CHECK ( destination_frames_per_reference_tick . invertible ( ) ) << " " ; TimelineRate output_to_local = destination_frames_per_reference_tick . Inverse ( ) ; AScale dest_scale = DbToScale ( target_dest_gain_db_ ) ; AScale start_scale = start_src_scale_ * dest_scale ; AScale end_scale = end_src_scale_ * dest_scale ; for ( uint32_t idx = 0 ; idx < num_frames ; ++ idx ) { zx :: duration frame_time = zx :: nsec ( output_to_local . Scale ( frames_ramped_ + idx ) ) ; if ( frame_time >= source_ramp_duration_ ) { scale_arr [ idx ] = end_scale ; } else { scale_arr [ idx ] = start_scale + ( static_cast < double > ( end_scale - start_scale ) * frame_time . to_nsecs ( ) ) / source_ramp_duration_ . to_nsecs ( ) ; } } } }
Populate an array of gain scales.
Populate an array of gain scales .
// Gain is flat for this mix job; retrieve gainscale once and set them all. // If the output device's clock is not running, then it isn't possible to // convert from output frames to wallclock (local) time. // Compose the ramp, in pieces