barelymusician/engine/instrument_test.cpp
// Tests that instrument plays multiple notes as expected.
Tests that instrument plays multiple notes as expected.
Tests that instrument plays multiple notes as expected .
TEST(InstrumentTest, PlayMultipleNotes) {
  const double kIntensity = 1.0;
  Instrument instrument(GetTestDefinition(), 1);
  std::vector<double> buffer(kNumChannels * kNumFrames);
  std::fill(buffer.begin(), buffer.end(), 0.0);
  instrument.Process(buffer.data(), kNumChannels, kNumFrames, 0.0);
  for (int frame = 0; frame < kNumFrames; ++frame) {
    for (int channel = 0; channel < kNumChannels; ++channel) {
      EXPECT_DOUBLE_EQ(buffer[kNumChannels * frame + channel], 15.0);
    }
  }
  for (int i = 0; i < kNumFrames; ++i) {
    instrument.StartNote(static_cast<double>(i), kIntensity,
                         static_cast<double>(i));
    instrument.StopNote(static_cast<double>(i), static_cast<double>(i + 1));
  }
  std::fill(buffer.begin(), buffer.end(), 0.0);
  instrument.Process(buffer.data(), kNumChannels, kNumFrames, 0.0);
  for (int frame = 0; frame < kNumFrames; ++frame) {
    const double expected = static_cast<double>(frame) * kIntensity;
    for (int channel = 0; channel < kNumChannels; ++channel) {
      EXPECT_DOUBLE_EQ(buffer[kNumChannels * frame + channel], expected);
    }
  }
  std::fill(buffer.begin(), buffer.end(), 0.0);
  instrument.Process(buffer.data(), kNumChannels, kNumFrames,
                     static_cast<double>(kNumFrames));
  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 , PlayMultipleNotes ) { const double kIntensity = 1.0 ; Instrument instrument ( GetTestDefinition ( ) , 1 ) ; std :: vector < double > buffer ( kNumChannels * kNumFrames ) ; std :: fill ( buffer . begin ( ) , buffer . end ( ) , 0.0 ) ; instrument . Process ( buffer . data ( ) , kNumChannels , kNumFrames , 0.0 ) ; for ( int frame = 0 ; frame < kNumFrames ; ++ frame ) { for ( int channel = 0 ; channel < kNumChannels ; ++ channel ) { EXPECT_DOUBLE_EQ ( buffer [ kNumChannels * frame + channel ] , 15.0 ) ; } } for ( int i = 0 ; i < kNumFrames ; ++ i ) { instrument . StartNote ( static_cast < double > ( i ) , kIntensity , static_cast < double > ( i ) ) ; instrument . StopNote ( static_cast < double > ( i ) , static_cast < double > ( i + 1 ) ) ; } std :: fill ( buffer . begin ( ) , buffer . end ( ) , 0.0 ) ; instrument . Process ( buffer . data ( ) , kNumChannels , kNumFrames , 0.0 ) ; for ( int frame = 0 ; frame < kNumFrames ; ++ frame ) { const double expected = static_cast < double > ( frame ) * kIntensity ; for ( int channel = 0 ; channel < kNumChannels ; ++ channel ) { EXPECT_DOUBLE_EQ ( buffer [ kNumChannels * frame + channel ] , expected ) ; } } std :: fill ( buffer . begin ( ) , buffer . end ( ) , 0.0 ) ; instrument . Process ( buffer . data ( ) , kNumChannels , kNumFrames , static_cast < double > ( kNumFrames ) ) ; 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 multiple notes as expected.
Tests that instrument plays multiple notes as expected .
// Parameter is set to default value. // Start new note per each frame in the buffer.