src/media/audio/audio_core/mixer/sinc_sampler_unittest.cc
// Validate the "seam" between buffers, while up-sampling
Validate the "seam" between buffers, while up-sampling
Validate the " seam " between buffers while up - sampling
TEST(SincSamplerTest, SamplingValues_DC_UpSample) {
  constexpr uint32_t kSourceRate = 12000;
  constexpr uint32_t kDestRate = 48000;
  auto mixer =
      SelectSincSampler(1, kSourceRate, fuchsia::media::AudioSampleFormat::FLOAT, 1, kDestRate);
  bool should_not_accum = false;
  bool source_is_consumed;
  constexpr uint32_t kDestLen = 1024;
  uint32_t dest_offset = 0;
  auto dest = std::make_unique<float[]>(kDestLen);
  constexpr uint32_t kSourceLen = kDestLen / 8;
  uint32_t frac_src_frames = kSourceLen << kPtsFractionalBits;
  int32_t frac_src_offset = 0;
  auto source = std::make_unique<float[]>(kSourceLen);
  for (auto idx = 0u; idx < kSourceLen; ++idx) {
    source[idx] = 1.0f;
  }
  auto& info = mixer->bookkeeping();
  info.step_size = (Mixer::FRAC_ONE * kSourceRate) / kDestRate;
  info.rate_modulo = Mixer::FRAC_ONE * kSourceRate - info.step_size * kDestRate;
  info.denominator = kDestRate;
  info.src_pos_modulo = 0;
  source_is_consumed = mixer->Mix(dest.get(), kDestLen / 2, &dest_offset, source.get(),
                                  frac_src_frames, &frac_src_offset, should_not_accum);
  EXPECT_TRUE(source_is_consumed) << std::hex << frac_src_offset;
  EXPECT_TRUE(frac_src_offset + mixer->pos_filter_width().raw_value() >= frac_src_frames);
  EXPECT_EQ(static_cast<uint64_t>(frac_src_offset) >> (kPtsFractionalBits - 2), dest_offset);
  auto first_half_dest = dest_offset;
  frac_src_offset -= frac_src_frames;
  source_is_consumed = mixer->Mix(dest.get(), kDestLen, &dest_offset, source.get(), frac_src_frames,
                                  &frac_src_offset, should_not_accum);
  EXPECT_TRUE(source_is_consumed) << std::hex << frac_src_offset;
  EXPECT_TRUE(frac_src_offset + mixer->pos_filter_width().raw_value() >= frac_src_frames);
  for (auto idx = first_half_dest - 2; idx < first_half_dest + 2; ++idx) {
    EXPECT_NEAR(dest[idx], 1.0f, 0.001f);
  }
}
TEST ( SincSamplerTest , SamplingValues_DC_UpSample ) { constexpr uint32_t kSourceRate = 12000 ; constexpr uint32_t kDestRate = 48000 ; auto mixer = SelectSincSampler ( 1 , kSourceRate , fuchsia :: media :: AudioSampleFormat :: FLOAT , 1 , kDestRate ) ; bool should_not_accum = false ; bool source_is_consumed ; constexpr uint32_t kDestLen = 1024 ; uint32_t dest_offset = 0 ; auto dest = std :: make_unique < float [ ] > ( kDestLen ) ; constexpr uint32_t kSourceLen = kDestLen / 8 ; uint32_t frac_src_frames = kSourceLen << kPtsFractionalBits ; int32_t frac_src_offset = 0 ; auto source = std :: make_unique < float [ ] > ( kSourceLen ) ; for ( auto idx = 0u ; idx < kSourceLen ; ++ idx ) { source [ idx ] = 1.0f ; } auto & info = mixer -> bookkeeping ( ) ; info . step_size = ( Mixer :: FRAC_ONE * kSourceRate ) / kDestRate ; info . rate_modulo = Mixer :: FRAC_ONE * kSourceRate - info . step_size * kDestRate ; info . denominator = kDestRate ; info . src_pos_modulo = 0 ; source_is_consumed = mixer -> Mix ( dest . get ( ) , kDestLen / 2 , & dest_offset , source . get ( ) , frac_src_frames , & frac_src_offset , should_not_accum ) ; EXPECT_TRUE ( source_is_consumed ) << std :: hex << frac_src_offset ; EXPECT_TRUE ( frac_src_offset + mixer -> pos_filter_width ( ) . raw_value ( ) >= frac_src_frames ) ; EXPECT_EQ ( static_cast < uint64_t > ( frac_src_offset ) >> ( kPtsFractionalBits - 2 ) , dest_offset ) ; auto first_half_dest = dest_offset ; frac_src_offset -= frac_src_frames ; source_is_consumed = mixer -> Mix ( dest . get ( ) , kDestLen , & dest_offset , source . get ( ) , frac_src_frames , & frac_src_offset , should_not_accum ) ; EXPECT_TRUE ( source_is_consumed ) << std :: hex << frac_src_offset ; EXPECT_TRUE ( frac_src_offset + mixer -> pos_filter_width ( ) . raw_value ( ) >= frac_src_frames ) ; for ( auto idx = first_half_dest - 2 ; idx < first_half_dest + 2 ; ++ idx ) { EXPECT_NEAR ( dest [ idx ] , 1.0f , 0.001f ) ; } }
Validate the "seam" between buffers, while up-sampling
Validate the " seam " between buffers while up - sampling
// Mix the first half of the destination // Now mix the rest // The two samples before and after the "seam" between buffers should be invisible