当前位置: 首页>>代码示例>>C++>>正文


C++ AudioData::setSample方法代码示例

本文整理汇总了C++中keyfinder::AudioData::setSample方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioData::setSample方法的具体用法?C++ AudioData::setSample怎么用?C++ AudioData::setSample使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keyfinder::AudioData的用法示例。


在下文中一共展示了AudioData::setSample方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

TEST (AudioDataTest, SampleMutatorBounds) {
  KeyFinder::AudioData a;
  a.addToSampleCount(5);
  ASSERT_THROW(a.getSample(-1), KeyFinder::Exception);
  ASSERT_THROW(a.getSample(5), KeyFinder::Exception);

  ASSERT_THROW(a.setSample(-1, 1.0), KeyFinder::Exception);
  ASSERT_THROW(a.setSample(5, 1.0), KeyFinder::Exception);

  ASSERT_THROW(a.setSample(0, INFINITY), KeyFinder::Exception);
  ASSERT_THROW(a.setSample(0, NAN), KeyFinder::Exception);
}
开发者ID:PimpinFou,项目名称:libKeyFinder,代码行数:12,代码来源:audiodatatest.cpp

示例2:

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);
    }
}
开发者ID:Quadrophone,项目名称:libKeyFinder,代码行数:29,代码来源:lowpassfiltertest.cpp

示例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));
}
开发者ID:heyigor,项目名称:libKeyFinder,代码行数:11,代码来源:audiodatatest.cpp

示例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 "";
    }
}
开发者ID:jrosener,项目名称:libKeyFinder,代码行数:77,代码来源:keyfinder_api.cpp


注:本文中的keyfinder::AudioData::setSample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。