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


C++ Audio::save方法代码示例

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


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

示例1: parseOptions

//templated function to parse the command line options. We need this to avoid
//duplicating code where the only difference in the type of the audio objects.
//This function in called from inside the main function.
template <typename T> int parseOptions(int sampleRate, int bitCount, int noChannels, int argc, char* argv[], std::string outFilename){
    using namespace ptlmuh006;    
    
    //where the options start changes based on whether or not a filename was 
    //specified.
    int pos = (std::string(argv[7]) == "-o")? 9 : 7;
    
    //check which option is being requested and handle it appropriately
    if(std::string(argv[pos]) == "-add"){
        //check for invalid number of args for this option
        if(argc < (pos+2)+1) return 1;
        
        Audio<T> aud1(argv[pos+1], sampleRate, bitCount, noChannels);
        Audio<T> aud2(argv[pos+2], sampleRate, bitCount, noChannels);
        Audio<T> sum = aud1 + aud2;
        sum.save(outFilename);
        
        std::cout << "Files successfully added and saved." << std::endl;
        
        return 0;
    }else if(std::string(argv[pos]) == "-cut"){
        if(argc < (pos+3)+1) return 1;
        
        Audio<T> original(argv[pos+3], sampleRate, bitCount, noChannels);
        int r1 = std::stoi(argv[pos+1]); //cut from this sample
        int r2 = std::stoi(argv[pos+2]); //stop cutting at this sample
        Audio<T> cut = original ^ std::pair<int, int>(r1, r2);
        cut.save(outFilename);
        
        std::cout << "File successfully cut and saved." << std::endl;
        
        return 0;
    }else if(std::string(argv[pos]) == "-radd"){
        if(argc < (pos+6)+1) return 1;
        
        //open the 2 audio files being range added
        Audio<T> aud1(argv[pos+5], sampleRate, bitCount, noChannels);
        Audio<T> aud2(argv[pos+6], sampleRate, bitCount, noChannels);
        
        //construct the ranges over which they will be added
        int r1Start = (int)(std::stof(argv[pos+1]) * sampleRate);
        int r1End = (int)(std::stof(argv[pos+2]) * sampleRate);
        int r2Start = (int)(std::stof(argv[pos+3]) * sampleRate);
        int r2End = (int)(std::stof(argv[pos+4]) * sampleRate);
        std::pair<int, int> r1(r1Start, r1End);
        std::pair<int, int> r2(r2Start, r2End);
        
        //invoke the ranged add function and save the result
        Audio<T> radd = Audio<T>::rangedAdd(aud1, r1, aud2, r2);
        radd.save(outFilename);
        
        std::cout << "File successfully added over range and saved." << std::endl;
        
        return 0;
    }else if(std::string(argv[pos]) == "-cat"){
        if(argc < (pos+2)+1) return 1;
        
        //open the 2 audio files
        Audio<T> aud1(argv[pos+1], sampleRate, bitCount, noChannels);
        Audio<T> aud2(argv[pos+2], sampleRate, bitCount, noChannels);
        
        //concatenate the files and save the result
        Audio<T> cat = aud1 | aud2;
        cat.save(outFilename);
        
        std::cout << "Files successfully concatenated and saved." << std::endl;
        
        return 0;
    }else if(std::string(argv[pos]) == "-v"){
        if(argc < (pos+3)+1) return 1;
        
        //open the audio file being volume factored
        Audio<T> aud(argv[pos+3], sampleRate, bitCount, noChannels);
        
        //construct the factor pair
        std::pair<float, float> fact(std::stof(argv[pos+1]), std::stof(argv[pos+2]));
        
        //volume factor the audio clip and save the result
        Audio<T> factored = aud * fact;
        factored.save(outFilename);
        
        std::cout << "File successfully volume factored and saved." << std::endl;
        
        return 0;
    }else if(std::string(argv[pos]) == "-rev"){
        if(argc < (pos+1)+1) return 1;
        
        Audio<T> aud(argv[pos+1], sampleRate, bitCount, noChannels);
        Audio<T> rev = aud.reverse();
        rev.save(outFilename);
        
        std::cout << "File successfully reversed and stored." << std::endl;
        
        return 0;
    }else if(std::string(argv[pos]) == "-rms"){ 
        if(argc < (pos+1)+1) return 1;
        
//.........这里部分代码省略.........
开发者ID:muhummadPatel,项目名称:cs3022a5,代码行数:101,代码来源:main.cpp


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