src/media/audio/audio_core/mixer/test/mixer_resampling_tests.cc
// Verify LinearSampler::Reset clears out any cached "previous edge" values.
// Earlier test (Position_Fractional_Linear) already validates that
// LinearSampler correctly caches edge values, so just validate Reset.
Verify LinearSampler::Reset clears out any cached "previous edge" values.
Earlier test (Position_Fractional_Linear) already validates that
LinearSampler correctly caches edge values, so just validate Reset.
Verify LinearSampler :: Reset clears out any cached " previous edge " values . Earlier test ( Position_Fractional_Linear ) already validates that LinearSampler correctly caches edge values so just validate Reset .
TEST(Resampling, Reset_Linear) {
  auto mixer = SelectMixer(fuchsia::media::AudioSampleFormat::SIGNED_16, 1, 48000, 1, 48000,
                           Resampler::LinearInterpolation);
  int32_t frac_src_offset = 1 << (kPtsFractionalBits - 1);  
  int16_t source[] = {0x1B0, 0xEA, 0x28E, 0x4D2, 0x3039};
  uint32_t dest_offset = 2;
  float accum[] = {-0x0006F000, -0x000DE000, -0x0014D000, -0x001BC000, -0x0022B000};
  float expect[] = {-0x0006F000, -0x000DE000, 0, 0, -0x0022B000};
  NormalizeInt28ToPipelineBitwidth(accum, std::size(accum));
  NormalizeInt28ToPipelineBitwidth(expect, std::size(expect));
  EXPECT_TRUE(
      mixer->Mix(accum, 4, &dest_offset, source, 3 << kPtsFractionalBits, &frac_src_offset, true));
  EXPECT_EQ(4u, dest_offset);
  EXPECT_EQ(5 << (kPtsFractionalBits - 1), frac_src_offset);
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect));
  mixer->Reset();
  frac_src_offset = -(1 << (kPtsFractionalBits - 1));
  dest_offset = 0;
  expect[0] = 0x000D8000;  
  NormalizeInt28ToPipelineBitwidth(&expect[0], 1);
  EXPECT_FALSE(
      mixer->Mix(accum, 1, &dest_offset, source, 2 << kPtsFractionalBits, &frac_src_offset, false));
  EXPECT_EQ(1u, dest_offset);
  EXPECT_EQ(1 << (kPtsFractionalBits - 1), frac_src_offset);
  EXPECT_THAT(accum, Pointwise(FloatEq(), expect));
}
TEST ( Resampling , Reset_Linear ) { auto mixer = SelectMixer ( fuchsia :: media :: AudioSampleFormat :: SIGNED_16 , 1 , 48000 , 1 , 48000 , Resampler :: LinearInterpolation ) ; int32_t frac_src_offset = 1 << ( kPtsFractionalBits - 1 ) ; int16_t source [ ] = { 0x1B0 , 0xEA , 0x28E , 0x4D2 , 0x3039 } ; uint32_t dest_offset = 2 ; float accum [ ] = { -0x0006F000 , -0x000DE000 , -0x0014D000 , -0x001BC000 , -0x0022B000 } ; float expect [ ] = { -0x0006F000 , -0x000DE000 , 0 , 0 , -0x0022B000 } ; NormalizeInt28ToPipelineBitwidth ( accum , std :: size ( accum ) ) ; NormalizeInt28ToPipelineBitwidth ( expect , std :: size ( expect ) ) ; EXPECT_TRUE ( mixer -> Mix ( accum , 4 , & dest_offset , source , 3 << kPtsFractionalBits , & frac_src_offset , true ) ) ; EXPECT_EQ ( 4u , dest_offset ) ; EXPECT_EQ ( 5 << ( kPtsFractionalBits - 1 ) , frac_src_offset ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect ) ) ; mixer -> Reset ( ) ; frac_src_offset = - ( 1 << ( kPtsFractionalBits - 1 ) ) ; dest_offset = 0 ; expect [ 0 ] = 0x000D8000 ; NormalizeInt28ToPipelineBitwidth ( & expect [ 0 ] , 1 ) ; EXPECT_FALSE ( mixer -> Mix ( accum , 1 , & dest_offset , source , 2 << kPtsFractionalBits , & frac_src_offset , false ) ) ; EXPECT_EQ ( 1u , dest_offset ) ; EXPECT_EQ ( 1 << ( kPtsFractionalBits - 1 ) , frac_src_offset ) ; EXPECT_THAT ( accum , Pointwise ( FloatEq ( ) , expect ) ) ; }
Verify LinearSampler::Reset clears out any cached "previous edge" values.
Verify LinearSampler :: Reset clears out any cached " previous edge " values .
// When src_offset ends on fractional val, it caches that sample for next mix // 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]. // src_offset ended less than 1 from end: src[2] will be cached for next mix. // Mixes with a frac_src_offset < 0 rely on a cached val. This one, post- // reset, has no cached vals and hence uses 0 for "left" vals during interp. // Start the src at offset -0.5. // Dest wants only one sample, at dest[0]. // Mix(:1B0)=D8 to [0]. W/out Reset, = (28E:1B0)=21F.