src/media/audio/audio_core/mixer/gain.cc
// Calculate a stream's gain-scale multiplier from source and dest gains in
// dB. Optimize to avoid doing the full calculation unless we must.
Calculate a stream's gain-scale multiplier from source and dest gains in
dB. Optimize to avoid doing the full calculation unless we must.
Calculate a stream ' s gain - scale multiplier from source and dest gains in dB . Optimize to avoid doing the full calculation unless we must .
Gain::AScale Gain::GetGainScale(float src_gain_db, float dest_gain_db) {
  TRACE_DURATION("audio", "Gain::GetGainScale");
  if ((current_src_gain_db_ == src_gain_db) && (current_dest_gain_db_ == dest_gain_db)) {
    return combined_gain_scale_;
  }
  current_src_gain_db_ = src_gain_db;
  current_dest_gain_db_ = dest_gain_db;
  if ((current_dest_gain_db_ + current_src_gain_db_) == kUnityGainDb) {
    combined_gain_scale_ = kUnityScale;
  } else if ((current_src_gain_db_ <= kMinGainDb) || (current_dest_gain_db_ <= kMinGainDb)) {
    combined_gain_scale_ = kMuteScale;
  } else {
    float effective_gain_db = current_src_gain_db_ + current_dest_gain_db_;
    if (effective_gain_db <= kMinGainDb) {
      combined_gain_scale_ = kMuteScale;
    } else if (effective_gain_db >= kMaxGainDb) {
      combined_gain_scale_ = kMaxScale;
    } else {
      combined_gain_scale_ = DbToScale(effective_gain_db);
    }
  }
  return combined_gain_scale_;
}
Gain :: AScale Gain :: GetGainScale ( float src_gain_db , float dest_gain_db ) { TRACE_DURATION ( " " , " " ) ; if ( ( current_src_gain_db_ == src_gain_db ) && ( current_dest_gain_db_ == dest_gain_db ) ) { return combined_gain_scale_ ; } current_src_gain_db_ = src_gain_db ; current_dest_gain_db_ = dest_gain_db ; if ( ( current_dest_gain_db_ + current_src_gain_db_ ) == kUnityGainDb ) { combined_gain_scale_ = kUnityScale ; } else if ( ( current_src_gain_db_ <= kMinGainDb ) || ( current_dest_gain_db_ <= kMinGainDb ) ) { combined_gain_scale_ = kMuteScale ; } else { float effective_gain_db = current_src_gain_db_ + current_dest_gain_db_ ; if ( effective_gain_db <= kMinGainDb ) { combined_gain_scale_ = kMuteScale ; } else if ( effective_gain_db >= kMaxGainDb ) { combined_gain_scale_ = kMaxScale ; } else { combined_gain_scale_ = DbToScale ( effective_gain_db ) ; } } return combined_gain_scale_ ; }
Calculate a stream's gain-scale multiplier from source and dest gains in
dB.
Calculate a stream ' s gain - scale multiplier from source and dest gains in dB .
// If nothing changed, return the previously-computed amplitude scale value. // If sum of the src and dest cancel each other, the combined is kUnityScale. // If source or dest are at the mute point, then silence the stream. // Likewise, silence the stream if the combined gain is at the mute point. // Else, we do need to compute the combined gain-scale.