src/media/audio/audio_core/mixer/test/mixer_bitwise_tests.cc
// Validate that we correctly mix quad->mono, including rounding.
Validate that we correctly mix quad->mono, including rounding.
Validate that we correctly mix quad - > mono including rounding .
TEST(PassThru, QuadToMono) {
  int32_t source[] = {                  
     0x100,         0,              0,              0,               
    -0x100,         0,              0,              0,               
     kMinInt24In32, kMinInt24In32,  kMinInt24In32,  kMinInt24In32,   
     kMaxInt24In32, kMaxInt24In32,  kMaxInt24In32,  kMaxInt24In32,   
     kMaxInt24In32, kMaxInt24In32, -kMaxInt24In32, -kMaxInt24In32};  
  float accum[] = {-0x1234, 0x4321, -0x13579, 0xC0FF, -0xAAAA};
  static_assert(std::size(source) == std::size(accum) * 4, "buf sizes must match");
  float expect[] = {0x0000004, -0x0000004, (kMinInt24In32 >> 4), (kMaxInt24In32) >> 4, 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, 24000, 1, 24000,
                           Resampler::SampleAndHold);
  DoMix(mixer.get(), source, accum, false, std::size(accum));
  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, 8000, 1, 8000,
                      Resampler::LinearInterpolation);
  DoMix(mixer.get(), source, accum, false, std::size(accum));
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect));
}
TEST ( PassThru , QuadToMono ) { int32_t source [ ] = { 0x100 , 0 , 0 , 0 , -0x100 , 0 , 0 , 0 , kMinInt24In32 , kMinInt24In32 , kMinInt24In32 , kMinInt24In32 , kMaxInt24In32 , kMaxInt24In32 , kMaxInt24In32 , kMaxInt24In32 , kMaxInt24In32 , kMaxInt24In32 , - kMaxInt24In32 , - kMaxInt24In32 } ; float accum [ ] = { -0x1234 , 0x4321 , -0x13579 , 0xC0FF , -0xAAAA } ; static_assert ( std :: size ( source ) == std :: size ( accum ) * 4 , " " ) ; float expect [ ] = { 0x0000004 , -0x0000004 , ( kMinInt24In32 >> 4 ) , ( kMaxInt24In32 ) >> 4 , 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 , 24000 , 1 , 24000 , Resampler :: SampleAndHold ) ; DoMix ( mixer . get ( ) , source , accum , false , std :: size ( accum ) ) ; 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 , 8000 , 1 , 8000 , Resampler :: LinearInterpolation ) ; DoMix ( mixer . get ( ) , source , accum , false , std :: size ( accum ) ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect ) ) ; }
Validate that we correctly mix quad->mono, including rounding.
Validate that we correctly mix quad - > mono including rounding .
// combinations: positive even, neg even, pos odd, neg odd, pos limit, neg limit, zero // clang-format off // should become 0.25 // should become -0.25 // should become kMinInt32In32 // should become kMaxInt24In32 // should become 0 // clang-format on // Will be overwritten // Equivalent to 0.25, -0.25, min val (largest neg), max val, 0 // Now try with the other resampler