src/media/audio/audio_core/mixer/test/mixer_range_tests.cc
// Test our mix level and noise floor, when rechannelizing stereo into mono.
Test our mix level and noise floor, when rechannelizing stereo into mono.
Test our mix level and noise floor when rechannelizing stereo into mono .
TEST(DynamicRange, StereoToMono) {
  auto mixer = SelectMixer(ASF::FLOAT, 2, 48000, 1, 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 mono = GenerateCosineAudio(mono_format, kFreqTestBufSize, FrequencySet::kReferenceFreq,
                                  kFullScaleFloatInputAmplitude, 0.0);
  AudioBuffer source(stereo_format, kFreqTestBufSize);
  AudioBuffer accum(mono_format, kFreqTestBufSize);
  for (uint32_t idx = 0; idx < kFreqTestBufSize; ++idx) {
    source.samples()[idx * 2] = mono.samples()[idx];
  }
  mono = GenerateCosineAudio(mono_format, kFreqTestBufSize, FrequencySet::kReferenceFreq,
                             kFullScaleFloatInputAmplitude, M_PI / 2);
  for (uint32_t idx = 0; idx < kFreqTestBufSize; ++idx) {
    source.samples()[(idx * 2) + 1] = mono.samples()[idx];
  }
  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));
  auto result = MeasureAudioFreq(AudioBufferSlice(&accum), FrequencySet::kReferenceFreq);
  AudioResult::LevelStereoMono = Gain::DoubleToDb(result.total_magn_signal);
  AudioResult::FloorStereoMono =
      Gain::DoubleToDb(kFullScaleFloatAccumAmplitude / result.total_magn_other);
  EXPECT_NEAR(AudioResult::LevelStereoMono, AudioResult::kPrevLevelStereoMono,
              AudioResult::kPrevLevelToleranceStereoMono);
  AudioResult::LevelToleranceStereoMono =
      fmax(AudioResult::LevelToleranceStereoMono,
           abs(AudioResult::LevelStereoMono - AudioResult::kPrevLevelStereoMono));
  EXPECT_GE(AudioResult::FloorStereoMono, AudioResult::kPrevFloorStereoMono);
}
TEST ( DynamicRange , StereoToMono ) { auto mixer = SelectMixer ( ASF :: FLOAT , 2 , 48000 , 1 , 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 mono = GenerateCosineAudio ( mono_format , kFreqTestBufSize , FrequencySet :: kReferenceFreq , kFullScaleFloatInputAmplitude , 0.0 ) ; AudioBuffer source ( stereo_format , kFreqTestBufSize ) ; AudioBuffer accum ( mono_format , kFreqTestBufSize ) ; for ( uint32_t idx = 0 ; idx < kFreqTestBufSize ; ++ idx ) { source . samples ( ) [ idx * 2 ] = mono . samples ( ) [ idx ] ; } mono = GenerateCosineAudio ( mono_format , kFreqTestBufSize , FrequencySet :: kReferenceFreq , kFullScaleFloatInputAmplitude , M_PI / 2 ) ; for ( uint32_t idx = 0 ; idx < kFreqTestBufSize ; ++ idx ) { source . samples ( ) [ ( idx * 2 ) + 1 ] = mono . samples ( ) [ idx ] ; } 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 ) ) ; auto result = MeasureAudioFreq ( AudioBufferSlice ( & accum ) , FrequencySet :: kReferenceFreq ) ; AudioResult :: LevelStereoMono = Gain :: DoubleToDb ( result . total_magn_signal ) ; AudioResult :: FloorStereoMono = Gain :: DoubleToDb ( kFullScaleFloatAccumAmplitude / result . total_magn_other ) ; EXPECT_NEAR ( AudioResult :: LevelStereoMono , AudioResult :: kPrevLevelStereoMono , AudioResult :: kPrevLevelToleranceStereoMono ) ; AudioResult :: LevelToleranceStereoMono = fmax ( AudioResult :: LevelToleranceStereoMono , abs ( AudioResult :: LevelStereoMono - AudioResult :: kPrevLevelStereoMono ) ) ; EXPECT_GE ( AudioResult :: FloorStereoMono , AudioResult :: kPrevFloorStereoMono ) ; }
Test our mix level and noise floor, when rechannelizing stereo into mono.
Test our mix level and noise floor when rechannelizing stereo into mono .
// Populate a mono source buffer; copy it into left side of stereo buffer. // Populate a mono source buffer with same frequency and amplitude, phase- // shifted by PI/2 (1/4 of a cycle); copy it into right side of stereo buffer. // Copy result to double-float buffer, FFT (freq-analyze) it at high-res // We added identical signals, so accuracy should be high. However, noise // floor is doubled as well, so we expect 6dB reduction in sinad.