barelymusician/dsp/polyphonic_voice_test.cpp
// Tests that the voice update callback updates all the voices as expected.
Tests that the voice update callback updates all the voices as expected.
Tests that the voice update callback updates all the voices as expected .
TEST(PolyphonicVoiceTest, Update) {
  const double kUpdatedOutput = 4.0 * kOutput;
  FakeVoice base_voice;
  base_voice.SetOutput(kOutput);
  PolyphonicVoice<FakeVoice> polyphonic_voice(std::move(base_voice));
  polyphonic_voice.Resize(kNumVoices);
  EXPECT_DOUBLE_EQ(polyphonic_voice.Next(kChannel), 0.0);
  for (int i = 0; i < kNumVoices; ++i) {
    const double pitch = static_cast<double>(i);
    polyphonic_voice.Start(pitch);
    EXPECT_DOUBLE_EQ(polyphonic_voice.Next(kChannel), kOutput);
    polyphonic_voice.Stop(pitch);
  }
  polyphonic_voice.Update(
      [kUpdatedOutput](FakeVoice* voice) { voice->SetOutput(kUpdatedOutput); });
  for (int i = 0; i < kNumVoices; ++i) {
    const double pitch = static_cast<double>(i);
    polyphonic_voice.Start(pitch);
    EXPECT_DOUBLE_EQ(polyphonic_voice.Next(kChannel), kUpdatedOutput);
    polyphonic_voice.Stop(pitch);
  }
}
TEST ( PolyphonicVoiceTest , Update ) { const double kUpdatedOutput = 4.0 * kOutput ; FakeVoice base_voice ; base_voice . SetOutput ( kOutput ) ; PolyphonicVoice < FakeVoice > polyphonic_voice ( std :: move ( base_voice ) ) ; polyphonic_voice . Resize ( kNumVoices ) ; EXPECT_DOUBLE_EQ ( polyphonic_voice . Next ( kChannel ) , 0.0 ) ; for ( int i = 0 ; i < kNumVoices ; ++ i ) { const double pitch = static_cast < double > ( i ) ; polyphonic_voice . Start ( pitch ) ; EXPECT_DOUBLE_EQ ( polyphonic_voice . Next ( kChannel ) , kOutput ) ; polyphonic_voice . Stop ( pitch ) ; } polyphonic_voice . Update ( [ kUpdatedOutput ] ( FakeVoice * voice ) { voice -> SetOutput ( kUpdatedOutput ) ; } ) ; for ( int i = 0 ; i < kNumVoices ; ++ i ) { const double pitch = static_cast < double > ( i ) ; polyphonic_voice . Start ( pitch ) ; EXPECT_DOUBLE_EQ ( polyphonic_voice . Next ( kChannel ) , kUpdatedOutput ) ; polyphonic_voice . Stop ( pitch ) ; } }
Tests that the voice update callback updates all the voices as expected.
Tests that the voice update callback updates all the voices as expected .