本文整理汇总了C++中keyfinder::AudioData::addToSampleCount方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioData::addToSampleCount方法的具体用法?C++ AudioData::addToSampleCount怎么用?C++ AudioData::addToSampleCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keyfinder::AudioData
的用法示例。
在下文中一共展示了AudioData::addToSampleCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST (LowPassFilterTest, WorksOnRepetitiveWaves) {
// make two sine waves, but this time, several seconds long
unsigned int samples = frameRate * 5;
KeyFinder::AudioData a;
a.setChannels(1);
a.setFrameRate(frameRate);
a.addToSampleCount(samples);
for (unsigned int i = 0; i < samples; i++) {
float sample = 0.0;
sample += sine_wave(i, highFrequency, frameRate, magnitude); // high freq
sample += sine_wave(i, lowFrequency, frameRate, magnitude); // low freq
a.setSample(i, sample);
// ensure repetition of sine waves is perfect...
if (i >= frameRate) {
ASSERT_NEAR(a.getSample(i), a.getSample(i - frameRate), tolerance);
}
}
KeyFinder::LowPassFilter* lpf = new KeyFinder::LowPassFilter(filterOrder, frameRate, cornerFrequency, filterFFT);
KeyFinder::Workspace w;
lpf->filter(a, w);
delete lpf;
// test for lower wave only
for (unsigned int i = 0; i < samples; i++) {
float expected = sine_wave(i, lowFrequency, frameRate, magnitude);
ASSERT_NEAR(expected, a.getSample(i), tolerance);
}
}
示例2:
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:
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: kfinder_get_key
const char* kfinder_get_key(short signed int *samples,
unsigned int nb_samples,
short unsigned int frame_rate,
short unsigned int nb_channels)
{
// Check input parameter.
if ((samples == NULL) || (nb_samples == 0) || (frame_rate == 0) || (nb_channels == 0))
{
return "";
}
// Build the main computing object.
KeyFinder::KeyFinder k;
// Build an empty audio object
KeyFinder::AudioData a;
// Prepare the object for your audio stream
a.setFrameRate(frame_rate);
a.setChannels(nb_channels);
a.addToSampleCount(nb_samples);
// Copy your audio into the object (as float).
for (unsigned int i = 0; i < nb_samples; i++)
{
a.setSample(i, (float)samples[i]);
}
// Run the analysis
KeyFinder::key_t r;
try
{
r = k.keyOfAudio(a);
}
catch(const std::exception& e)
{
cerr << "libKeyFinder: exception: " << e.what() << endl;
return "";
}
catch(...)
{
cerr << "libKeyFinder: unknown exception" << endl;
return "";
}
// And do something with the result!
switch(r)
{
case KeyFinder::A_MAJOR: return "AM";
case KeyFinder::A_MINOR: return "Am";
case KeyFinder::B_FLAT_MAJOR: return "BbM";
case KeyFinder::B_FLAT_MINOR: return "Bbm";
case KeyFinder::B_MAJOR: return "BM";
case KeyFinder::B_MINOR: return "Bm";
case KeyFinder::C_MAJOR: return "CM";
case KeyFinder::C_MINOR: return "Cm";
case KeyFinder::D_FLAT_MAJOR: return "DbM";
case KeyFinder::D_FLAT_MINOR: return "Dbm";
case KeyFinder::D_MAJOR: return "DM";
case KeyFinder::D_MINOR: return "Dm";
case KeyFinder::E_FLAT_MAJOR: return "EbM";
case KeyFinder::E_FLAT_MINOR: return "Ebm";
case KeyFinder::E_MAJOR: return "EM";
case KeyFinder::E_MINOR: return "Em";
case KeyFinder::F_MAJOR: return "FM";
case KeyFinder::F_MINOR: return "Fm";
case KeyFinder::G_FLAT_MAJOR: return "GbM";
case KeyFinder::G_FLAT_MINOR: return "Gbm";
case KeyFinder::G_MAJOR: return "GM";
case KeyFinder::G_MINOR: return "Gm";
case KeyFinder::A_FLAT_MAJOR: return "AbM";
case KeyFinder::A_FLAT_MINOR: return "Abm";
case KeyFinder::SILENCE: return "";
default: return "";
}
}