src/media/audio/audio_core/mixer/test/mixer_resampling_tests.cc
// Verify LinearSampler mixes from/to correct locations, given fractional src
// locations. Ensure it doesn't touch other buffer sections, regardless of
// 'accumulate' flag. Check cases when supply > demand and vice versa. (Cases
// where supply equals demand are well-covered elsewhere.) This test uses
// fractional offsets, still with a step_size of ONE.
Verify LinearSampler mixes from/to correct locations, given fractional src
locations. Ensure it doesn't touch other buffer sections, regardless of
'accumulate' flag. Check cases when supply > demand and vice versa. (Cases
where supply equals demand are well-covered elsewhere.) This test uses
fractional offsets, still with a step_size of ONE.
Verify LinearSampler mixes from / to correct locations given fractional src locations . Ensure it doesn ' t touch other buffer sections regardless of ' accumulate ' flag . Check cases when supply > demand and vice versa . ( Cases where supply equals demand are well - covered elsewhere . ) This test uses fractional offsets still with a step_size of ONE .
TEST(Resampling, Position_Fractional_Linear) {
  auto mixer = SelectMixer(fuchsia::media::AudioSampleFormat::SIGNED_16, 1, 48000, 1, 48000,
                           Resampler::LinearInterpolation);
   Check: Source supply exceeds destination demand
   Source (offset 0.5 of 3) has 2.5. Destination (offset 2 of 4) wants 2.
  int32_t frac_src_offset = 1 << (kPtsFractionalBits - 1);   0.5
  uint32_t dest_offset = 2;
  int16_t source[] = {-1, -0xB, -0x7C, 0x4D2, 0x3039};
   Mix (accumulate) source[0:1,1:2] into accum[2,3].
  float accum[] = {-0x000DEFA0, -0x0014D840, -0x00017920, 0x0007BFF0, -0x0022BB00};
  float expect[] = {-0x000DEFA0, -0x0014D840, -0x0001D920, 0x000387F0, -0x0022BB00};
  NormalizeInt28ToPipelineBitwidth(accum, std::size(accum));
  NormalizeInt28ToPipelineBitwidth(expect, std::size(expect));
   TODO(mpuryear): round correctly if accumulating fractional result with
   previous opposite-polarity result. Ideally round -67.5+123 (55.5) to 56.
  bool mix_result =
      mixer->Mix(accum, 4, &dest_offset, source, 3 << kPtsFractionalBits, &frac_src_offset, true);
   Less than one frame of the source buffer remains, and we cached the final
   sample, so mix_result should be TRUE.
  EXPECT_TRUE(mix_result);
  EXPECT_EQ(4u, dest_offset);
  EXPECT_EQ(5 << (kPtsFractionalBits - 1), frac_src_offset);
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect));
   src_offset ended less than 1 from end: src[2] will be cached for next mix.
   Check: destination demand exceeds source supply
   Source (offset -0.5 of 2) has 2.5. Destination (offset 1 of 4) wants 3.
  frac_src_offset = -(1 << (kPtsFractionalBits - 1));
  dest_offset = 1;
   Mix src[2:0,0:1] into accum[1,2].  [1] = (-124:-1), [2] = (-1:-11)
  float expect2[] = {-0x000DEFA0, -0x0003E800, -0x00006000, 0x000387F0, -0x0022BB00};
  NormalizeInt28ToPipelineBitwidth(expect2, std::size(expect2));
  mix_result =
      mixer->Mix(accum, 4, &dest_offset, source, 2 << kPtsFractionalBits, &frac_src_offset, false);
  EXPECT_TRUE(mix_result);
  EXPECT_EQ(3u, dest_offset);
  EXPECT_EQ(3 << (kPtsFractionalBits - 1), frac_src_offset);
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect2));
}
TEST ( Resampling , Position_Fractional_Linear ) { auto mixer = SelectMixer ( fuchsia :: media :: AudioSampleFormat :: SIGNED_16 , 1 , 48000 , 1 , 48000 , Resampler :: LinearInterpolation ) ; int32_t frac_src_offset = 1 << ( kPtsFractionalBits - 1 ) ; uint32_t dest_offset = 2 ; int16_t source [ ] = { -1 , -0xB , -0x7C , 0x4D2 , 0x3039 } ; float accum [ ] = { -0x000DEFA0 , -0x0014D840 , -0x00017920 , 0x0007BFF0 , -0x0022BB00 } ; float expect [ ] = { -0x000DEFA0 , -0x0014D840 , -0x0001D920 , 0x000387F0 , -0x0022BB00 } ; NormalizeInt28ToPipelineBitwidth ( accum , std :: size ( accum ) ) ; NormalizeInt28ToPipelineBitwidth ( expect , std :: size ( expect ) ) ; bool mix_result = mixer -> Mix ( accum , 4 , & dest_offset , source , 3 << kPtsFractionalBits , & frac_src_offset , true ) ; EXPECT_TRUE ( mix_result ) ; EXPECT_EQ ( 4u , dest_offset ) ; EXPECT_EQ ( 5 << ( kPtsFractionalBits - 1 ) , frac_src_offset ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect ) ) ; frac_src_offset = - ( 1 << ( kPtsFractionalBits - 1 ) ) ; dest_offset = 1 ; float expect2 [ ] = { -0x000DEFA0 , -0x0003E800 , -0x00006000 , 0x000387F0 , -0x0022BB00 } ; NormalizeInt28ToPipelineBitwidth ( expect2 , std :: size ( expect2 ) ) ; mix_result = mixer -> Mix ( accum , 4 , & dest_offset , source , 2 << kPtsFractionalBits , & frac_src_offset , false ) ; EXPECT_TRUE ( mix_result ) ; EXPECT_EQ ( 3u , dest_offset ) ; EXPECT_EQ ( 3 << ( kPtsFractionalBits - 1 ) , frac_src_offset ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect2 ) ) ; }
Verify LinearSampler mixes from/to correct locations, given fractional src
locations.
Verify LinearSampler mixes from / to correct locations given fractional src locations .
// // Check: Source supply exceeds destination demand // Source (offset 0.5 of 3) has 2.5. Destination (offset 2 of 4) wants 2. // 0.5 // Mix (accumulate) source[0:1,1:2] into accum[2,3]. // TODO(mpuryear): round correctly if accumulating fractional result with // previous opposite-polarity result. Ideally round -67.5+123 (55.5) to 56. // Less than one frame of the source buffer remains, and we cached the final // sample, so mix_result should be TRUE. // src_offset ended less than 1 from end: src[2] will be cached for next mix. // // Check: destination demand exceeds source supply // Source (offset -0.5 of 2) has 2.5. Destination (offset 1 of 4) wants 3. // Mix src[2:0,0:1] into accum[1,2].  [1] = (-124:-1), [2] = (-1:-11)