src/media/audio/audio_core/mixer/test/mixer_resampling_tests.cc
// For PointSampler, test sample placement when given fractional position.
// Ensure it doesn't touch other buffer sections, regardless of 'accumulate'
// flag. Check when supply > demand and vice versa (we already know = works).
// This test uses fractional lengths/offsets, still with a step_size of ONE.
// TODO(mpuryear): Change frac_src_frames parameter to be (integer) src_frames,
// as number of frames was never intended to be fractional.
For PointSampler, test sample placement when given fractional position.
Ensure it doesn't touch other buffer sections, regardless of 'accumulate'
flag. Check when supply > demand and vice versa (we already know = works).
This test uses fractional lengths/offsets, still with a step_size of ONE.
TODO(mpuryear): Change frac_src_frames parameter to be (integer) src_frames,
as number of frames was never intended to be fractional.
For PointSampler test sample placement when given fractional position . Ensure it doesn ' t touch other buffer sections regardless of ' accumulate ' flag . Check when supply > demand and vice versa ( we already know = works ) . This test uses fractional lengths / offsets still with a step_size of ONE . TODO ( mpuryear ) : Change frac_src_frames parameter to be ( integer ) src_frames as number of frames was never intended to be fractional .
TEST(Resampling, Position_Fractional_Point) {
  auto mixer = SelectMixer(fuchsia::media::AudioSampleFormat::SIGNED_16, 1, 44100, 1, 44100,
                           Resampler::SampleAndHold);
   Check: source supply exceeds destination demand
   Source (offset 1.5 of 5) has 3.5. Destination (offset 1 of 3) wants 2.
  int32_t frac_src_offset = 3 << (kPtsFractionalBits - 1);
  uint32_t dest_offset = 1;
  int16_t source[] = {1, 0xC, 0x7B, 0x4D2, 0x3039};
   Mix will accumulate source[1:2,2:3] into accum[1,2]
  float accum[] = {-0x00002000, -0x00017000, -0x000EA000, -0x00929000, -0x05BA0000};
  float expect[] = {-0x00002000, 0x00064000, 0x003E8000, -0x00929000, -0x05BA0000};
  NormalizeInt28ToPipelineBitwidth(accum, std::size(accum));
  NormalizeInt28ToPipelineBitwidth(expect, std::size(expect));
  bool mix_result =
      mixer->Mix(accum, 3, &dest_offset, source, 5 << kPtsFractionalBits, &frac_src_offset, true);
  EXPECT_FALSE(mix_result);
  EXPECT_EQ(3u, dest_offset);
  EXPECT_EQ(7 << (kPtsFractionalBits - 1), frac_src_offset);
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect));
   Check: Destination demand exceeds source supply
   Source (offset 2.49 of 4) has 2. Destination (offset 1 of 4) wants 3.
  frac_src_offset = (5 << (kPtsFractionalBits - 1)) - 1;
  dest_offset = 1;
   Mix will move source[2,3] to accum[1,2]
  float expect2[] = {-0x00002000, 0x0007B000, 0x004D2000, -0x00929000, -0x05BA0000};
  NormalizeInt28ToPipelineBitwidth(expect2, std::size(expect2));
  mix_result =
      mixer->Mix(accum, 4, &dest_offset, source, 4 << kPtsFractionalBits, &frac_src_offset, false);
  EXPECT_TRUE(mix_result);
  EXPECT_EQ(3u, dest_offset);
  EXPECT_EQ((9 << (kPtsFractionalBits - 1)) - 1, frac_src_offset);
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect2));
}
TEST ( Resampling , Position_Fractional_Point ) { auto mixer = SelectMixer ( fuchsia :: media :: AudioSampleFormat :: SIGNED_16 , 1 , 44100 , 1 , 44100 , Resampler :: SampleAndHold ) ; int32_t frac_src_offset = 3 << ( kPtsFractionalBits - 1 ) ; 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 , -0x00929000 , -0x05BA0000 } ; NormalizeInt28ToPipelineBitwidth ( accum , std :: size ( accum ) ) ; NormalizeInt28ToPipelineBitwidth ( expect , std :: size ( expect ) ) ; bool mix_result = mixer -> Mix ( accum , 3 , & dest_offset , source , 5 << kPtsFractionalBits , & frac_src_offset , true ) ; EXPECT_FALSE ( mix_result ) ; EXPECT_EQ ( 3u , dest_offset ) ; EXPECT_EQ ( 7 << ( kPtsFractionalBits - 1 ) , frac_src_offset ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect ) ) ; frac_src_offset = ( 5 << ( kPtsFractionalBits - 1 ) ) - 1 ; dest_offset = 1 ; float expect2 [ ] = { -0x00002000 , 0x0007B000 , 0x004D2000 , -0x00929000 , -0x05BA0000 } ; NormalizeInt28ToPipelineBitwidth ( expect2 , std :: size ( expect2 ) ) ; mix_result = mixer -> Mix ( accum , 4 , & dest_offset , source , 4 << kPtsFractionalBits , & frac_src_offset , false ) ; EXPECT_TRUE ( mix_result ) ; EXPECT_EQ ( 3u , dest_offset ) ; EXPECT_EQ ( ( 9 << ( kPtsFractionalBits - 1 ) ) - 1 , frac_src_offset ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect2 ) ) ; }
For PointSampler, test sample placement when given fractional position.
For PointSampler test sample placement when given fractional position .
// // Check: source supply exceeds destination demand // Source (offset 1.5 of 5) has 3.5. Destination (offset 1 of 3) wants 2. // Mix will accumulate source[1:2,2:3] into accum[1,2] // // Check: Destination demand exceeds source supply // Source (offset 2.49 of 4) has 2. Destination (offset 1 of 4) wants 3. // Mix will move source[2,3] to accum[1,2]