src/media/audio/audio_core/mixer/test/mixer_resampling_tests.cc
// Verify that the samplers mix to/from correct buffer locations. Also ensure
// that they don't touch other buffer sections, regardless of 'accumulate'.
// This first test uses integer lengths/offsets, and a step_size of ONE.
Verify that the samplers mix to/from correct buffer locations. Also ensure
that they don't touch other buffer sections, regardless of 'accumulate'.
This first test uses integer lengths/offsets, and a step_size of ONE.
Verify that the samplers mix to / from correct buffer locations . Also ensure that they don ' t touch other buffer sections regardless of ' accumulate ' . This first test uses integer lengths / offsets and a step_size of ONE .
void TestBasicPosition(Resampler samplerType) {
  bool mix_result;
  auto mixer =
      SelectMixer(fuchsia::media::AudioSampleFormat::SIGNED_16, 1, 48000, 1, 48000, samplerType);
   Check: source supply equals destination demand.
   Source (offset 2 of 5) has 3. Destination (offset 1 of 4) wants 3.
  int32_t frac_src_offset = 2 << kPtsFractionalBits;
  uint32_t dest_offset = 1;
  int16_t source[] = {1, 0xC, 0x7B, 0x4D2, 0x3039};
   Mix will add source[2,3,4] to accum[1,2,3]
  float accum[] = {-0x00002000, -0x00017000, -0x000EA000, -0x00929000, -0x05BA0000};
  float expect[] = {-0x00002000, 0x00064000, 0x003E8000, 0x02710000, -0x05BA0000};
  NormalizeInt28ToPipelineBitwidth(accum, std::size(accum));
  NormalizeInt28ToPipelineBitwidth(expect, std::size(expect));
  mix_result =
      mixer->Mix(accum, 4, &dest_offset, source, 5 << kPtsFractionalBits, &frac_src_offset, true);
  EXPECT_TRUE(mix_result);
  EXPECT_EQ(4u, dest_offset);
  EXPECT_EQ(5 << kPtsFractionalBits, frac_src_offset);
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect));
   Check: source supply exceeds destination demand.
   Source (offset 0 of 4) has 4. Destination (offset 2 of 4) wants 2.
  frac_src_offset = 0;
  dest_offset = 2;
   Mix will add source[0,1] to accum2[2,3]
  float accum2[] = {-0x00002000, -0x00017000, -0x000EA000, -0x00929000, -0x05BA0000};
  float expect2[] = {-0x00002000, -0x00017000, -0x000E9000, -0x0091D000, -0x05BA0000};
  NormalizeInt28ToPipelineBitwidth(accum2, std::size(accum2));
  NormalizeInt28ToPipelineBitwidth(expect2, std::size(expect2));
  mix_result =
      mixer->Mix(accum2, 4, &dest_offset, source, 4 << kPtsFractionalBits, &frac_src_offset, true);
  EXPECT_FALSE(mix_result);
  EXPECT_EQ(4u, dest_offset);
  EXPECT_EQ(2 << kPtsFractionalBits, frac_src_offset);
  EXPECT_THAT(accum2, Pointwise(FloatEq(), expect2));
   Check: destination demand exceeds source supply.
   Source (offset 2 of 3) has 1. Destination (offset 0 of 4) wants 4.
  frac_src_offset = 2 << kPtsFractionalBits;
  dest_offset = 0;
   Mix will move source[2] to accum[0]
  float expect3[] = {0x0007B000, -0x00017000, -0x000E9000, -0x0091D000, -0x05BA0000};
  NormalizeInt28ToPipelineBitwidth(expect3, std::size(expect3));
  mix_result =
      mixer->Mix(accum2, 4, &dest_offset, source, 3 << kPtsFractionalBits, &frac_src_offset, false);
  EXPECT_TRUE(mix_result);
  EXPECT_EQ(1u, dest_offset);
  EXPECT_EQ(3 << kPtsFractionalBits, frac_src_offset);
  EXPECT_THAT(accum2, Pointwise(FloatEq(), expect3));
}
void TestBasicPosition ( Resampler samplerType ) { bool mix_result ; auto mixer = SelectMixer ( fuchsia :: media :: AudioSampleFormat :: SIGNED_16 , 1 , 48000 , 1 , 48000 , samplerType ) ; int32_t frac_src_offset = 2 << kPtsFractionalBits ; uint32_t dest_offset = 1 ; int16_t source [ ] = { 1 , 0xC , 0x7B , 0x4D2 , 0x3039 } ; float accum [ ] = { -0x00002000 , -0x00017000 , -0x000EA000 , -0x00929000 , -0x05BA0000 } ; float expect [ ] = { -0x00002000 , 0x00064000 , 0x003E8000 , 0x02710000 , -0x05BA0000 } ; NormalizeInt28ToPipelineBitwidth ( accum , std :: size ( accum ) ) ; NormalizeInt28ToPipelineBitwidth ( expect , std :: size ( expect ) ) ; mix_result = mixer -> Mix ( accum , 4 , & dest_offset , source , 5 << kPtsFractionalBits , & frac_src_offset , true ) ; EXPECT_TRUE ( mix_result ) ; EXPECT_EQ ( 4u , dest_offset ) ; EXPECT_EQ ( 5 << kPtsFractionalBits , frac_src_offset ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect ) ) ; frac_src_offset = 0 ; dest_offset = 2 ; float accum2 [ ] = { -0x00002000 , -0x00017000 , -0x000EA000 , -0x00929000 , -0x05BA0000 } ; float expect2 [ ] = { -0x00002000 , -0x00017000 , -0x000E9000 , -0x0091D000 , -0x05BA0000 } ; NormalizeInt28ToPipelineBitwidth ( accum2 , std :: size ( accum2 ) ) ; NormalizeInt28ToPipelineBitwidth ( expect2 , std :: size ( expect2 ) ) ; mix_result = mixer -> Mix ( accum2 , 4 , & dest_offset , source , 4 << kPtsFractionalBits , & frac_src_offset , true ) ; EXPECT_FALSE ( mix_result ) ; EXPECT_EQ ( 4u , dest_offset ) ; EXPECT_EQ ( 2 << kPtsFractionalBits , frac_src_offset ) ; EXPECT_THAT ( accum2 , Pointwise ( FloatEq ( ) , expect2 ) ) ; frac_src_offset = 2 << kPtsFractionalBits ; dest_offset = 0 ; float expect3 [ ] = { 0x0007B000 , -0x00017000 , -0x000E9000 , -0x0091D000 , -0x05BA0000 } ; NormalizeInt28ToPipelineBitwidth ( expect3 , std :: size ( expect3 ) ) ; mix_result = mixer -> Mix ( accum2 , 4 , & dest_offset , source , 3 << kPtsFractionalBits , & frac_src_offset , false ) ; EXPECT_TRUE ( mix_result ) ; EXPECT_EQ ( 1u , dest_offset ) ; EXPECT_EQ ( 3 << kPtsFractionalBits , frac_src_offset ) ; EXPECT_THAT ( accum2 , Pointwise ( FloatEq ( ) , expect3 ) ) ; }
Verify that the samplers mix to/from correct buffer locations.
Verify that the samplers mix to / from correct buffer locations .
// // Check: source supply equals destination demand. // Source (offset 2 of 5) has 3. Destination (offset 1 of 4) wants 3. // Mix will add source[2,3,4] to accum[1,2,3] // // Check: source supply exceeds destination demand. // Source (offset 0 of 4) has 4. Destination (offset 2 of 4) wants 2. // Mix will add source[0,1] to accum2[2,3] // // Check: destination demand exceeds source supply. // Source (offset 2 of 3) has 1. Destination (offset 0 of 4) wants 4. // Mix will move source[2] to accum[0]