barelymusician/engine/instrument_test.cpp
// Tests that instrument plays a single note as expected.
Tests that instrument plays a single note as expected.
Tests that instrument plays a single note as expected .
TEST(InstrumentTest, PlaySingleNote) {
  const double kPitch = 32.0;
  const double kIntensity = 0.5;
  const double kTimestamp = 20.0;
  Instrument instrument(GetTestDefinition(), kFrameRate);
  std::vector<double> buffer(kNumChannels * kNumFrames);
  EXPECT_FALSE(instrument.IsNoteOn(kPitch));
  std::fill(buffer.begin(), buffer.end(), 0.0);
  instrument.Process(buffer.data(), kNumChannels, kNumFrames, kTimestamp);
  for (int frame = 0; frame < kNumFrames; ++frame) {
    for (int channel = 0; channel < kNumChannels; ++channel) {
      EXPECT_DOUBLE_EQ(buffer[kNumChannels * frame + channel], 15.0);
    }
  }
  instrument.StartNote(kPitch, kIntensity, kTimestamp);
  EXPECT_TRUE(instrument.IsNoteOn(kPitch));
  std::fill(buffer.begin(), buffer.end(), 0.0);
  instrument.Process(buffer.data(), kNumChannels, kNumFrames, kTimestamp);
  for (int frame = 0; frame < kNumFrames; ++frame) {
    for (int channel = 0; channel < kNumChannels; ++channel) {
      EXPECT_DOUBLE_EQ(buffer[kNumChannels * frame + channel],
                       kPitch * kIntensity);
    }
  }
  instrument.StopNote(kPitch, kTimestamp);
  EXPECT_FALSE(instrument.IsNoteOn(kPitch));
  std::fill(buffer.begin(), buffer.end(), 0.0);
  instrument.Process(buffer.data(), kNumChannels, kNumFrames, kTimestamp);
  for (int frame = 0; frame < kNumFrames; ++frame) {
    for (int channel = 0; channel < kNumChannels; ++channel) {
      EXPECT_DOUBLE_EQ(buffer[kNumChannels * frame + channel], 0.0);
    }
  }
}
TEST ( InstrumentTest , PlaySingleNote ) { const double kPitch = 32.0 ; const double kIntensity = 0.5 ; const double kTimestamp = 20.0 ; Instrument instrument ( GetTestDefinition ( ) , kFrameRate ) ; std :: vector < double > buffer ( kNumChannels * kNumFrames ) ; EXPECT_FALSE ( instrument . IsNoteOn ( kPitch ) ) ; std :: fill ( buffer . begin ( ) , buffer . end ( ) , 0.0 ) ; instrument . Process ( buffer . data ( ) , kNumChannels , kNumFrames , kTimestamp ) ; for ( int frame = 0 ; frame < kNumFrames ; ++ frame ) { for ( int channel = 0 ; channel < kNumChannels ; ++ channel ) { EXPECT_DOUBLE_EQ ( buffer [ kNumChannels * frame + channel ] , 15.0 ) ; } } instrument . StartNote ( kPitch , kIntensity , kTimestamp ) ; EXPECT_TRUE ( instrument . IsNoteOn ( kPitch ) ) ; std :: fill ( buffer . begin ( ) , buffer . end ( ) , 0.0 ) ; instrument . Process ( buffer . data ( ) , kNumChannels , kNumFrames , kTimestamp ) ; for ( int frame = 0 ; frame < kNumFrames ; ++ frame ) { for ( int channel = 0 ; channel < kNumChannels ; ++ channel ) { EXPECT_DOUBLE_EQ ( buffer [ kNumChannels * frame + channel ] , kPitch * kIntensity ) ; } } instrument . StopNote ( kPitch , kTimestamp ) ; EXPECT_FALSE ( instrument . IsNoteOn ( kPitch ) ) ; std :: fill ( buffer . begin ( ) , buffer . end ( ) , 0.0 ) ; instrument . Process ( buffer . data ( ) , kNumChannels , kNumFrames , kTimestamp ) ; for ( int frame = 0 ; frame < kNumFrames ; ++ frame ) { for ( int channel = 0 ; channel < kNumChannels ; ++ channel ) { EXPECT_DOUBLE_EQ ( buffer [ kNumChannels * frame + channel ] , 0.0 ) ; } } }
Tests that instrument plays a single note as expected.
Tests that instrument plays a single note as expected .
// Parameter is set to default value. // Start note. // Stop note.