src/media/audio/audio_core/mixer/test/mixer_range_tests.cc
// Ideal dynamic range measurement is exactly equal to the reduction in gain.
// Ideal accompanying noise is ideal noise floor, minus the reduction in gain.
Ideal dynamic range measurement is exactly equal to the reduction in gain.
Ideal accompanying noise is ideal noise floor, minus the reduction in gain.
Ideal dynamic range measurement is exactly equal to the reduction in gain . Ideal accompanying noise is ideal noise floor minus the reduction in gain .
void MeasureSummaryDynamicRange(float gain_db, double* level_db, double* sinad_db) {
  auto mixer = SelectMixer(ASF::FLOAT, 1, 48000, 1, 48000, Resampler::SampleAndHold);
  auto format = Format::Create<ASF::FLOAT>(1, 48000).take_value();
  auto source = GenerateCosineAudio(format, kFreqTestBufSize, FrequencySet::kReferenceFreq);
  AudioBuffer accum(format, kFreqTestBufSize);
  uint32_t dest_offset = 0;
  int32_t frac_src_offset = 0;
  auto& info = mixer->bookkeeping();
  info.gain.SetSourceGain(gain_db);
  mixer->Mix(&accum.samples()[0], kFreqTestBufSize, &dest_offset, &source.samples()[0],
             kFreqTestBufSize << kPtsFractionalBits, &frac_src_offset, false);
  EXPECT_EQ(dest_offset, kFreqTestBufSize);
  EXPECT_EQ(frac_src_offset, static_cast<int32_t>(kFreqTestBufSize << kPtsFractionalBits));
  auto result = MeasureAudioFreq(AudioBufferSlice(&accum), FrequencySet::kReferenceFreq);
  *level_db = Gain::DoubleToDb(result.total_magn_signal);
  *sinad_db = Gain::DoubleToDb(result.total_magn_signal / result.total_magn_other);
}
void MeasureSummaryDynamicRange ( float gain_db , double * level_db , double * sinad_db ) { auto mixer = SelectMixer ( ASF :: FLOAT , 1 , 48000 , 1 , 48000 , Resampler :: SampleAndHold ) ; auto format = Format :: Create < ASF :: FLOAT > ( 1 , 48000 ) . take_value ( ) ; auto source = GenerateCosineAudio ( format , kFreqTestBufSize , FrequencySet :: kReferenceFreq ) ; AudioBuffer accum ( format , kFreqTestBufSize ) ; uint32_t dest_offset = 0 ; int32_t frac_src_offset = 0 ; auto & info = mixer -> bookkeeping ( ) ; info . gain . SetSourceGain ( gain_db ) ; mixer -> Mix ( & accum . samples ( ) [ 0 ] , kFreqTestBufSize , & dest_offset , & source . samples ( ) [ 0 ] , kFreqTestBufSize << kPtsFractionalBits , & frac_src_offset , false ) ; EXPECT_EQ ( dest_offset , kFreqTestBufSize ) ; EXPECT_EQ ( frac_src_offset , static_cast < int32_t > ( kFreqTestBufSize << kPtsFractionalBits ) ) ; auto result = MeasureAudioFreq ( AudioBufferSlice ( & accum ) , FrequencySet :: kReferenceFreq ) ; * level_db = Gain :: DoubleToDb ( result . total_magn_signal ) ; * sinad_db = Gain :: DoubleToDb ( result . total_magn_signal / result . total_magn_other ) ; }
Ideal dynamic range measurement is exactly equal to the reduction in gain.
Ideal dynamic range measurement is exactly equal to the reduction in gain .
// Populate source buffer; mix it (pass-thru) to accumulation buffer // Copy result to double-float buffer, FFT (freq-analyze) it at high-res