示例#1
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;
}
示例#2
0
TEST (AudioDataTest, SampleInitialisation) {
  KeyFinder::AudioData a;
  a.addToSampleCount(100);
  ASSERT_EQ(100, a.getSampleCount());
  // init values
  for (int i = 0; i < 100; i++) {
    ASSERT_FLOAT_EQ(0.0, a.getSample(i));
  }
}
示例#3
0
TEST(AudioDataTest, SamplesBasic){
  KeyFinder::AudioData a;
  a.addToSampleCount(100);
  ASSERT_EQ(100, a.getSampleCount());
  // init values
  for(int i=0; i<100; i++){
    ASSERT_EQ(0.0, a.getSample(i));
  }
  a.setSample(0, 10.0);
  ASSERT_EQ(10.0, a.getSample(0));
}
示例#4
0
TEST (AudioDataTest, MakeMono) {
  KeyFinder::AudioData a;
  a.setChannels(2);
  a.addToSampleCount(20);
  for (int i = 0; i < 10; i++) {
    a.setSample(i * 2, 100.0);
  }
  a.reduceToMono();
  ASSERT_EQ(10, a.getSampleCount());
  for (int i = 0; i < 10; i++) {
    ASSERT_FLOAT_EQ(50.0, a.getSample(i));
  }
}
示例#5
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));
}
TEST (LowPassFilterTest, DoesntAlterAudioMetadata) {
    KeyFinder::AudioData a;
    a.setChannels(1);
    a.setFrameRate(frameRate);
    a.addToSampleCount(frameRate);

    KeyFinder::LowPassFilter* lpf = new KeyFinder::LowPassFilter(filterOrder, frameRate, cornerFrequency, filterFFT);
    KeyFinder::Workspace w;
    lpf->filter(a, w);
    delete lpf;

    ASSERT_EQ(1, a.getChannels());
    ASSERT_EQ(frameRate, a.getFrameRate());
    ASSERT_EQ(frameRate, a.getSampleCount());
}
示例#7
0
TEST (AudioDataTest, DownsamplerResamplesIntegralRelationship) {
  KeyFinder::AudioData a;
  a.setChannels(1);
  a.setFrameRate(100);
  a.addToSampleCount(10);
  for (unsigned int i = 0; i < 5; i++)
    a.setSample(i, 100.0);
  for (unsigned int i = 5; i < 10; i++)
    a.setSample(i, 500.0);

  a.downsample(5);

  ASSERT_EQ(20, a.getFrameRate());
  ASSERT_EQ(2, a.getSampleCount());
  ASSERT_FLOAT_EQ(100.0, a.getSample(0));
  ASSERT_FLOAT_EQ(500.0, a.getSample(1));
}
示例#8
0
TEST (AudioDataTest, DownsamplerResamplesNonintegralRelationship) {
  KeyFinder::AudioData a;
  a.setChannels(1);
  a.setFrameRate(100);
  a.addToSampleCount(12);
  for (unsigned int i = 0; i < 5; i++)
    a.setSample(i, 100.0);
  for (unsigned int i = 5; i < 10; i++)
    a.setSample(i, 500.0);
  for (unsigned int i = 10; i < 12; i++)
    a.setSample(i, 1000.0);

  a.downsample(5);

  ASSERT_EQ(3, a.getSampleCount());
  ASSERT_FLOAT_EQ(100.0, a.getSample(0));
  ASSERT_FLOAT_EQ(500.0, a.getSample(1));
  // this doesn't make total mathematical sense but I'm taking a shortcut for performance
  ASSERT_FLOAT_EQ(1000.0, a.getSample(2));
}
示例#9
0
TEST (AudioDataTest, DownsamplerResamplesSineWave) {
  unsigned int frameRate = 10000;
  unsigned int frames = frameRate * 4;
  float freq = 20;
  float magnitude = 32768.0;
  unsigned int factor = 5;

  KeyFinder::AudioData a;
  a.setChannels(1);
  a.setFrameRate(frameRate);
  a.addToSampleCount(frames);
  for (unsigned int i = 0; i < frames; i++)
    a.setSample(i, sine_wave(i, freq, frameRate, magnitude));

  a.downsample(factor);

  unsigned int newFrameRate = frameRate / factor;
  unsigned int newFrames = frames / factor;

  ASSERT_EQ(newFrameRate, a.getFrameRate());
  ASSERT_EQ(newFrames, a.getSampleCount());
  for (unsigned int i = 0; i < newFrames; i++)
    ASSERT_NEAR(sine_wave(i, freq, newFrameRate, magnitude), a.getSample(i), magnitude * 0.05);
}
示例#10
0
TEST (AudioDataTest, ConstructorWorks) {
  KeyFinder::AudioData a;
  ASSERT_EQ(0, a.getChannels());
  ASSERT_EQ(0, a.getFrameRate());
  ASSERT_EQ(0, a.getSampleCount());
}