barelymusician/dsp/sample_player_test.cpp
// Tests that the sample data is played back as expected at different speeds.
Tests that the sample data is played back as expected at different speeds.
Tests that the sample data is played back as expected at different speeds .
TEST(SamplePlayerTest, SetSpeed) {
  SamplePlayer sample_player(kSampleRate);
  sample_player.SetData(kData, kSampleRate, kDataLength);
  sample_player.SetLoop(true);
  const std::vector<double> kSpeeds = {0.0, 0.4, 1.0, 1.25, 2.0, 3.3};
  for (const double speed : kSpeeds) {
    sample_player.Reset();
    sample_player.SetSpeed(speed);
    for (int i = 0; i < kDataLength; ++i) {
      const int expected_index =
          static_cast<int>(static_cast<double>(i) * speed);
      EXPECT_DOUBLE_EQ(sample_player.Next(),
                       kData[expected_index % kDataLength])
          << "at index " << i << ", where speed is: " << speed;
    }
  }
}
TEST ( SamplePlayerTest , SetSpeed ) { SamplePlayer sample_player ( kSampleRate ) ; sample_player . SetData ( kData , kSampleRate , kDataLength ) ; sample_player . SetLoop ( true ) ; const std :: vector < double > kSpeeds = { 0.0 , 0.4 , 1.0 , 1.25 , 2.0 , 3.3 } ; for ( const double speed : kSpeeds ) { sample_player . Reset ( ) ; sample_player . SetSpeed ( speed ) ; for ( int i = 0 ; i < kDataLength ; ++ i ) { const int expected_index = static_cast < int > ( static_cast < double > ( i ) * speed ) ; EXPECT_DOUBLE_EQ ( sample_player . Next ( ) , kData [ expected_index % kDataLength ] ) << " " << i << " " << speed ; } } }
Tests that the sample data is played back as expected at different speeds.
Tests that the sample data is played back as expected at different speeds .