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


C++ AudioStream::reduceToMono方法代码示例

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


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

示例1: run

void KeyFinderWorkerThread::run(){
    if(!haveParams){
        emit failed("No parameters.");
        return;
    }
    // initialise stream and decode file into it
    AudioStream* astrm = NULL;
  AudioFileDecoder* dec = AudioFileDecoder::getDecoder(filePath.toUtf8().data());
    try{
    astrm = dec->decodeFile(filePath.toUtf8().data());
    }catch(Exception){
        delete astrm;
        delete dec;
        emit failed("Could not decode file.");
        return;
    }
    delete dec;
    emit decoded();

    // make audio stream monaural
    astrm->reduceToMono();
    emit madeMono();

    // downsample if necessary
    if(prefs.getDFactor() > 1){
        Downsampler* ds = Downsampler::getDownsampler(prefs.getDFactor(),astrm->getFrameRate(),prefs.getLastFreq());
        try{
            astrm = ds->downsample(astrm,prefs.getDFactor());
        }catch(Exception){
            delete astrm;
            delete ds;
            emit failed("Downsampler failed.");
            return;
        }
        delete ds;
        emit downsampled();
    }

    // start spectrum analysis
    SpectrumAnalyser* sa = NULL;
  Chromagram* ch = NULL;
  sa = SpectrumAnalyserFactory::getInstance()->getSpectrumAnalyser(astrm->getFrameRate(),prefs);
  ch = sa->chromagram(astrm);
  delete astrm; // note we don't delete the spectrum analyser; it stays in the centralised factory for reuse.
  ch->reduceTuningBins(prefs);
    emit producedFullChromagram(*ch);

    // reduce chromagram
    ch->reduceToOneOctave(prefs);
    emit producedOneOctaveChromagram(*ch);

    // get energy level across track to weight segments
    std::vector<float> loudness(ch->getHops());
    for(int h=0; h<ch->getHops(); h++)
        for(int b=0; b<ch->getBins(); b++)
            loudness[h] += ch->getMagnitude(h,b);

    // get harmonic change signal
    Segmentation* hcdf = Segmentation::getSegmentation(prefs);
    std::vector<double> harmonicChangeSignal = hcdf->getRateOfChange(ch,prefs);
    emit producedHarmonicChangeSignal(harmonicChangeSignal);

    // get track segmentation
  std::vector<int> changes = hcdf->getSegments(harmonicChangeSignal,prefs);
  changes.push_back(ch->getHops()); // It used to be getHops()-1. But this doesn't crash. So we like it.

    // batch output of keychange locations for Beatles experiment
    //for(int i=1; i<changes.size(); i++) // don't want the leading zero
    //	std::cout << filePath.substr(53) << "\t" << std::fixed << std::setprecision(2) << changes[i]*(prefs.getHopSize()/(44100.0/prefs.getDFactor())) << std::endl;
    // end experiment output

    // get key estimates for segments
    KeyClassifier hc(prefs);
    std::vector<int> keys(0);
    std::vector<float> keyWeights(24);
  for(int i=0; i<(signed)changes.size()-1; i++){
    std::vector<double> chroma(ch->getBins());
        for(int j=changes[i]; j<changes[i+1]; j++)
            for(int k=0; k<ch->getBins(); k++)
        chroma[k] += ch->getMagnitude(j,k);
    int key = hc.classify(chroma);
    for(int j=changes[i]; j<changes[i+1]; j++){
            keys.push_back(key);
            if(key < 24) // ignore parts that were classified as silent
                keyWeights[key] += loudness[j];
    }
    }
    keys.push_back(keys[keys.size()-1]); // put last key on again to match length of track
    delete ch;
    emit producedKeyEstimates(keys);

    // get global key
    int mostCommonKey = 24;
    float mostCommonKeyWeight = 0.0;
    for(int i=0; i<(signed)keyWeights.size(); i++){
        if(keyWeights[i] > mostCommonKeyWeight){
            mostCommonKeyWeight = keyWeights[i];
            mostCommonKey = i;
        }
    }
//.........这里部分代码省略.........
开发者ID:GoBijan,项目名称:is_KeyFinder,代码行数:101,代码来源:keyfinderworkerthread.cpp


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