barelymusician/dsp/sample_player_test.cpp
// Tests that the sample data is played back as expected at different sampling
// frequencies.
Tests that the sample data is played back as expected at different sampling
frequencies.
Tests that the sample data is played back as expected at different sampling frequencies .
TEST(SamplePlayerTest, DifferentSampleFrequency) {
  const std::vector<int> kFrequencies = {0, kSampleRate / 3, kSampleRate,
                                         2 * kSampleRate, 5 * kSampleRate};
  SamplePlayer sample_player(kSampleRate);
  for (const int frequency : kFrequencies) {
    sample_player.Reset();
    sample_player.SetData(kData, frequency, kDataLength);
    sample_player.SetLoop(true);
    for (int i = 0; i < kDataLength; ++i) {
      const int expected_index =
          static_cast<int>(static_cast<double>(i * frequency) /
                           static_cast<double>(kSampleRate));
      EXPECT_DOUBLE_EQ(sample_player.Next(),
                       kData[expected_index % kDataLength])
          << "at index " << i << ", where sample frequency is: " << frequency;
    }
  }
}
TEST ( SamplePlayerTest , DifferentSampleFrequency ) { const std :: vector < int > kFrequencies = { 0 , kSampleRate / 3 , kSampleRate , 2 * kSampleRate , 5 * kSampleRate } ; SamplePlayer sample_player ( kSampleRate ) ; for ( const int frequency : kFrequencies ) { sample_player . Reset ( ) ; sample_player . SetData ( kData , frequency , kDataLength ) ; sample_player . SetLoop ( true ) ; for ( int i = 0 ; i < kDataLength ; ++ i ) { const int expected_index = static_cast < int > ( static_cast < double > ( i * frequency ) / static_cast < double > ( kSampleRate ) ) ; EXPECT_DOUBLE_EQ ( sample_player . Next ( ) , kData [ expected_index % kDataLength ] ) << " " << i << " " << frequency ; } } }
Tests that the sample data is played back as expected at different sampling
frequencies.
Tests that the sample data is played back as expected at different sampling frequencies .