src/media/audio/audio_core/mixer/test/mixer_range_tests.cc
// Test our mix level and noise floor, when rechannelizing mono into stereo.
Test our mix level and noise floor, when rechannelizing mono into stereo.
Test our mix level and noise floor when rechannelizing mono into stereo .
TEST(DynamicRange, MonoToStereo) {
  auto mixer = SelectMixer(ASF::FLOAT, 1, 48000, 2, 48000, Resampler::SampleAndHold);
  auto mono_format = Format::Create<ASF::FLOAT>(1, 48000).take_value();
  auto stereo_format = Format::Create<ASF::FLOAT>(2, 48000).take_value();
  auto source = GenerateCosineAudio(mono_format, kFreqTestBufSize, FrequencySet::kReferenceFreq);
  AudioBuffer accum(stereo_format, kFreqTestBufSize);
  AudioBuffer left(mono_format, kFreqTestBufSize);
  uint32_t dest_offset = 0;
  int32_t frac_src_offset = 0;
  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));
  for (uint32_t idx = 0; idx < kFreqTestBufSize; ++idx) {
    EXPECT_FLOAT_EQ(accum.samples()[idx * 2], accum.samples()[(idx * 2) + 1]);
    left.samples()[idx] = accum.samples()[idx * 2];
  }
  auto left_result = MeasureAudioFreq(AudioBufferSlice(&left), FrequencySet::kReferenceFreq);
  auto level_left_db = Gain::DoubleToDb(left_result.total_magn_signal);
  auto sinad_left_db =
      Gain::DoubleToDb(left_result.total_magn_signal / left_result.total_magn_other);
  EXPECT_NEAR(level_left_db, 0.0, AudioResult::kPrevLevelToleranceSourceFloat);
  AudioResult::LevelToleranceSourceFloat =
      fmax(AudioResult::LevelToleranceSourceFloat, abs(level_left_db));
  EXPECT_GE(sinad_left_db, AudioResult::kPrevFloorSourceFloat);
}
TEST ( DynamicRange , MonoToStereo ) { auto mixer = SelectMixer ( ASF :: FLOAT , 1 , 48000 , 2 , 48000 , Resampler :: SampleAndHold ) ; auto mono_format = Format :: Create < ASF :: FLOAT > ( 1 , 48000 ) . take_value ( ) ; auto stereo_format = Format :: Create < ASF :: FLOAT > ( 2 , 48000 ) . take_value ( ) ; auto source = GenerateCosineAudio ( mono_format , kFreqTestBufSize , FrequencySet :: kReferenceFreq ) ; AudioBuffer accum ( stereo_format , kFreqTestBufSize ) ; AudioBuffer left ( mono_format , kFreqTestBufSize ) ; uint32_t dest_offset = 0 ; int32_t frac_src_offset = 0 ; 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 ) ) ; for ( uint32_t idx = 0 ; idx < kFreqTestBufSize ; ++ idx ) { EXPECT_FLOAT_EQ ( accum . samples ( ) [ idx * 2 ] , accum . samples ( ) [ ( idx * 2 ) + 1 ] ) ; left . samples ( ) [ idx ] = accum . samples ( ) [ idx * 2 ] ; } auto left_result = MeasureAudioFreq ( AudioBufferSlice ( & left ) , FrequencySet :: kReferenceFreq ) ; auto level_left_db = Gain :: DoubleToDb ( left_result . total_magn_signal ) ; auto sinad_left_db = Gain :: DoubleToDb ( left_result . total_magn_signal / left_result . total_magn_other ) ; EXPECT_NEAR ( level_left_db , 0.0 , AudioResult :: kPrevLevelToleranceSourceFloat ) ; AudioResult :: LevelToleranceSourceFloat = fmax ( AudioResult :: LevelToleranceSourceFloat , abs ( level_left_db ) ) ; EXPECT_GE ( sinad_left_db , AudioResult :: kPrevFloorSourceFloat ) ; }
Test our mix level and noise floor, when rechannelizing mono into stereo.
Test our mix level and noise floor when rechannelizing mono into stereo .
// Populate mono source buffer; mix it (no SRC/gain) to stereo accumulator // Copy left result to double-float buffer, FFT (freq-analyze) it at high-res // Only need to analyze left side, since we verified that right is identical.