src/media/audio/audio_core/mixer/test/mixer_bitwise_tests.cc
// Validate that we correctly mix quad->stereo, including rounding. Note: 0|1|2|3 becomes 0+2 | 1+3
Validate that we correctly mix quad->stereo, including rounding.
Validate that we correctly mix quad - > stereo including rounding .
TEST(PassThru, QuadToStereo_Round) {
  int32_t source[] = {
                       0x100,        -0x100,
                       0,             0,
                       kMinInt24In32, kMaxInt24In32,
                       kMinInt24In32, kMaxInt24In32,
                       kMaxInt24In32, 0,
                      -kMaxInt24In32, 0 };
  float accum[] = {-0x1234, 0x4321, -0x13579, 0xC0FF, -0xAAAA, 0x555};
  static_assert(std::size(source) == std::size(accum) * 2, "buf sizes must match");
  float expect[] = {0x0000008, -0x0000008, (kMinInt24In32 >> 4), (kMaxInt24In32) >> 4, 0, 0};
  static_assert(std::size(accum) == std::size(expect), "buf sizes must match");
  NormalizeInt28ToPipelineBitwidth(expect, std::size(expect));
  auto mixer = SelectMixer(fuchsia::media::AudioSampleFormat::SIGNED_24_IN_32, 4, 22050, 2, 22050,
                           Resampler::SampleAndHold);
  DoMix(mixer.get(), source, accum, false, std::size(accum) / 2);  
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect));
  std::memset(accum, 0, std::size(accum) * sizeof(float));
  mixer = SelectMixer(fuchsia::media::AudioSampleFormat::SIGNED_24_IN_32, 4, 44100, 2, 44100,
                      Resampler::LinearInterpolation);
  DoMix(mixer.get(), source, accum, false, std::size(accum) / 2);  
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect));
}
TEST ( PassThru , QuadToStereo_Round ) { int32_t source [ ] = { 0x100 , -0x100 , 0 , 0 , kMinInt24In32 , kMaxInt24In32 , kMinInt24In32 , kMaxInt24In32 , kMaxInt24In32 , 0 , - kMaxInt24In32 , 0 } ; float accum [ ] = { -0x1234 , 0x4321 , -0x13579 , 0xC0FF , -0xAAAA , 0x555 } ; static_assert ( std :: size ( source ) == std :: size ( accum ) * 2 , " " ) ; float expect [ ] = { 0x0000008 , -0x0000008 , ( kMinInt24In32 >> 4 ) , ( kMaxInt24In32 ) >> 4 , 0 , 0 } ; static_assert ( std :: size ( accum ) == std :: size ( expect ) , " " ) ; NormalizeInt28ToPipelineBitwidth ( expect , std :: size ( expect ) ) ; auto mixer = SelectMixer ( fuchsia :: media :: AudioSampleFormat :: SIGNED_24_IN_32 , 4 , 22050 , 2 , 22050 , Resampler :: SampleAndHold ) ; DoMix ( mixer . get ( ) , source , accum , false , std :: size ( accum ) / 2 ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect ) ) ; std :: memset ( accum , 0 , std :: size ( accum ) * sizeof ( float ) ) ; mixer = SelectMixer ( fuchsia :: media :: AudioSampleFormat :: SIGNED_24_IN_32 , 4 , 44100 , 2 , 44100 , Resampler :: LinearInterpolation ) ; DoMix ( mixer . get ( ) , source , accum , false , std :: size ( accum ) / 2 ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect ) ) ; }
Validate that we correctly mix quad->stereo, including rounding.
Validate that we correctly mix quad - > stereo including rounding .
// combinations: positive even, neg even, pos odd, neg odd, pos limit, neg limit, zero // clang-format off // clang-format on // Will be overwritten // Equivalent to 0.5, -0.5, min val (largest neg), max val, 0 // dest frames have 2 samples // Now try with the other resampler // dest frames have 2 samples