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


C++ SoundFile::setNumberOfChannels方法代码示例

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


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

示例1: createSoundFile

SoundFile* AbcFile::createSoundFile() {
    SoundFile * soundFile = new SoundFile();
    soundFile->setBitDepth(bitRate);
    soundFile->setSampleRate(sampleRate);
    soundFile->setNumberOfChannels((int)instruments.size());
    int samplesPerCount = (int)ceil(60.0*sampleRate/tempo);
    for(int i = 0; i < instruments.size(); i++) {
        SoundFile * otherChannels = new SoundFile();
        otherChannels->setBitDepth(bitRate);
        otherChannels->setSampleRate(sampleRate);
        otherChannels->setNumberOfChannels((int)instruments.size());
        SoundGenerator::SoundBuilder builder;
        builder.setAttack(instruments[i]->getAttack()).setDecay(instruments[i]->getDecay()).setRelease(instruments[i]->getRelease()).setDuration((instruments[i]->findTotalCount() * 60 / tempo)).setSampleRate(sampleRate).setSustain(instruments[i]->getSustain());
        int numSamples = 0;
        for(int j = 0; j < instruments[i]->getScore().size(); j++) {
            SoundFile * tempFile = new SoundFile();
            tempFile->setBitDepth(bitRate);
            tempFile->setSampleRate(sampleRate);
            SoundGenerator soundGenerator = builder.setDuration((instruments[i]->getScore()[j]->getCount() * 60 / tempo)).setBitDepth(bitRate).build();
            tempFile->setNumberOfChannels((int)instruments.size());
            int waveForm = instruments[i]->getWaveform();
            if(waveForm == 1) {
                numSamples +=sineWave(instruments[i]->getScore()[j],samplesPerCount,tempFile);
            } else if(waveForm == 2) {
                numSamples +=sawtoothWave(instruments[i]->getScore()[j],samplesPerCount,tempFile);
            } else if (waveForm == 3) {
                numSamples +=triangleWave(instruments[i]->getScore()[j],samplesPerCount,tempFile);
            } else {
                numSamples +=pulseWave(instruments[i]->getScore()[j],samplesPerCount,tempFile);
            }
            soundGenerator.handleEnvelop(tempFile);
            if(i == 0) {
                *soundFile += tempFile;
            } else {
                *otherChannels += tempFile;
            }
        }
        for (int k = numSamples + 1; k < getMaxSamples(instruments); ++k) {
            SampleLine *sampleLine = new SampleLine();
            sampleLine->addNewChannel(0);
            if(i == 0) {
                soundFile->addSample(sampleLine);
            } else {
                otherChannels->addSample(sampleLine);
            }
        }
        if(std::find(mute.begin(),mute.end(),i) != mute.end()) {
            if(i == 0) {
                *soundFile * 0;
            } else {
                *otherChannels * 0;
            }
        }
        if(i != 0) {
            *soundFile | otherChannels;
        }
    }

    return soundFile;
}
开发者ID:JeffHask,项目名称:CS327Project4,代码行数:60,代码来源:AbcFile.cpp


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