Пример #1
0
TEST (AudioDataTest, PrependToInitialised) {
  KeyFinder::AudioData a;
  KeyFinder::AudioData b;

  a.setChannels(1);
  a.setFrameRate(1);
  ASSERT_THROW(a.prepend(b), KeyFinder::Exception);

  b.setChannels(2);
  b.setFrameRate(1);
  ASSERT_THROW(a.prepend(b), KeyFinder::Exception);

  b.setChannels(1);
  b.setFrameRate(2);
  ASSERT_THROW(a.prepend(b), KeyFinder::Exception);

  b.setChannels(1);
  b.setFrameRate(1);
  ASSERT_NO_THROW(a.prepend(b));

  a.addToFrameCount(1);
  b.addToFrameCount(1);
  a.setSampleByFrame(0, 0, 10.0);
  b.setSampleByFrame(0, 0, 20.0);

  a.prepend(b);
  ASSERT_EQ(2, a.getFrameCount());
  ASSERT_FLOAT_EQ(20.0, a.getSampleByFrame(0, 0));
  ASSERT_FLOAT_EQ(10.0, a.getSampleByFrame(1, 0));
}
Пример #2
0
TEST (AudioDataTest, SliceFromBack) {
  KeyFinder::AudioData a;
  a.setChannels(1);
  a.setFrameRate(1);

  KeyFinder::AudioData* b = NULL;
  KeyFinder::AudioData* nullPtr = NULL;

  ASSERT_THROW(b = a.sliceSamplesFromBack(1), KeyFinder::Exception);
  ASSERT_EQ(nullPtr, b);

  a.addToFrameCount(10);
  ASSERT_THROW(b = a.sliceSamplesFromBack(11), KeyFinder::Exception);
  ASSERT_EQ(nullPtr, b);

  a.resetIterators();
  float v = 0;
  while (a.writeIteratorWithinUpperBound()) {
    a.setSampleAtWriteIterator(v);
    a.advanceWriteIterator();
    v += 1.0;
  }

  ASSERT_NO_THROW(b = a.sliceSamplesFromBack(5));
  ASSERT_NE(nullPtr, b);
  ASSERT_EQ(5, a.getSampleCount());
  ASSERT_EQ(5, b->getSampleCount());
  ASSERT_FLOAT_EQ(5.0, b->getSample(0));
  ASSERT_FLOAT_EQ(9.0, b->getSample(4));
  delete b;
}
Пример #3
0
TEST (AudioDataTest, FrameMutatorBounds) {
  KeyFinder::AudioData a;
  a.setChannels(2);
  a.addToFrameCount(10);
  ASSERT_THROW(a.getSampleByFrame(-1, 0), KeyFinder::Exception);
  ASSERT_THROW(a.getSampleByFrame(10, 0), KeyFinder::Exception);
  ASSERT_THROW(a.getSampleByFrame( 0,-1), KeyFinder::Exception);
  ASSERT_THROW(a.getSampleByFrame( 0, 2), KeyFinder::Exception);
}
Пример #4
0
TEST (AudioDataTest, FrameMutator) {
  KeyFinder::AudioData a;
  a.setChannels(4);
  a.addToFrameCount(5);
  ASSERT_EQ(5, a.getFrameCount());
  ASSERT_EQ(20, a.getSampleCount());

  a.setSample(6, 10.0);
  ASSERT_FLOAT_EQ(10.0, a.getSample(6));
  ASSERT_FLOAT_EQ(10.0, a.getSampleByFrame(1, 2));
  a.setSampleByFrame(1, 2, 20.0);
  ASSERT_FLOAT_EQ(20.0, a.getSample(6));
  ASSERT_FLOAT_EQ(20.0, a.getSampleByFrame(1, 2));
}
Пример #5
0
TEST (AudioDataTest, DiscardFromFront) {
  KeyFinder::AudioData a;

  a.setChannels(1);
  a.setFrameRate(1);

  ASSERT_THROW(a.discardFramesFromFront(1), KeyFinder::Exception);
  a.addToFrameCount(10);
  ASSERT_THROW(a.discardFramesFromFront(11), KeyFinder::Exception);
  ASSERT_NO_THROW(a.discardFramesFromFront(0));
  a.setSampleByFrame(5, 0, 10.0);
  ASSERT_NO_THROW(a.discardFramesFromFront(5));
  ASSERT_EQ(5, a.getFrameCount());
  ASSERT_FLOAT_EQ(10.0, a.getSampleByFrame(0, 0));
}
Пример #6
0
TEST (AudioDataTest, PrependToNew) {
  KeyFinder::AudioData a;
  KeyFinder::AudioData b;

  ASSERT_NO_THROW(a.prepend(b));
  ASSERT_EQ(0, a.getChannels());
  ASSERT_EQ(0, a.getFrameRate());

  b.setChannels(1);
  b.setFrameRate(1);
  b.addToFrameCount(1);

  ASSERT_NO_THROW(a.prepend(b));
  ASSERT_EQ(1, a.getChannels());
  ASSERT_EQ(1, a.getFrameRate());
  ASSERT_EQ(1, a.getFrameCount());
}