📄 audiochain.cc
字号:
int input_channels = input1->getInputConfig().getChannels(); if(input_channels == 2) { if(output_channels == 2) { /* left to left - right to right */ mix->addMix(id,0,0, 100); mix->addMix(id,1,1, 100); aflib_info("Mixing Stereo file %s to Stereo",in_file1.c_str()); } else { /* left to mono - right to mono */ mix->addMix(id,1,0, 100); mix->addMix(id,0,0, 100); aflib_info("Mixing Stereo file %s to Mono",in_file1.c_str()); } } else if(input_channels == 1) { if(output_channels == 2) { /* mono to left - mono to right */ mix->addMix(id,0,0, 100); mix->addMix(id,0,1, 100); aflib_info("Mixing Mono file %s to Stereo",in_file1.c_str()); } else { /* mono to mono */ mix->addMix(id,0,0, 100); aflib_info("Mixing Mono file %s to Mono",in_file1.c_str()); } } else { aflib_fatal("Mix function only currently supports one or two input channels: input file %s", in_file1.c_str()); } input_channels = input2->getInputConfig().getChannels(); id = mix->addParent(*input2); if(input_channels == 2) { if(output_channels == 2) { /* left to left - right to right */ mix->addMix(id,0,0, 100); mix->addMix(id,1,1, 100); aflib_info("Mixing Stereo file %s to Stereo",in_file2.c_str()); } else { /* left to mono - right to mono */ mix->addMix(id,1,0, 100); mix->addMix(id,0,0, 100); aflib_info("Mixing Mono file %s to Mono",in_file2.c_str()); } } else if(input_channels == 1) { if(output_channels == 2) { /* mono to left - mono to right */ mix->addMix(id,0,0, 100); mix->addMix(id,0,1, 100); aflib_info("Mixing Mono file %s to Stereo",in_file2.c_str()); } else { /* mono to mono */ mix->addMix(id,0,0, 100); aflib_info("Mixing Mono file %s to Mono",in_file2.c_str()); } } else { aflib_fatal("Mix function only currently supports one or two input channels: input file %s", in_file2.c_str()); } /* get output aflibAudioFile object */ output = new aflibAudioFile(*mix,out_format, out_file, &out_config, &status); if(status != AFLIB_SUCCESS) { aflib_fatal("Error opening output file %s", out_file.c_str()); } else if(_verbose) { aflib_info("%s type: %s", out_file.c_str(), output->getFormat().c_str()); aflib_info("rate: %d, channels: %d, samples: %d", out_config.getSamplesPerSecond(), out_config.getChannels(), out_config.getTotalSamples() ); } /* process it */ process(output); delete output; delete input1; delete input2; delete mix;}voidaudioChain::testall_formats( int argc, char* argv[] ) { list<aflibFileItem*> modules_list; list<aflibFileItem*>::iterator it; modules_list = aflibFile::returnSupportedFormats(); string cmdname = argv[0]; cmdname += " "; string in_args; for(int i = 1; i < argc ; i++){ if(string(argv[i]) != "-t"){ in_args += argv[i]; in_args += " "; } } for ( it = modules_list.begin(); it != modules_list.end(); it++) { if((*it)->getFormat() == "nul") continue; if((*it)->getFormat() == "ossdsp") continue; if((*it)->getFormat() == "DEVICE") continue; if((*it)->getFormat() == "auto") continue; if((*it)->getFormat() == "MPEG") continue; if((*it)->getFormat() == "raw") continue; if((*it)->getFormat() == "hcom") continue; string out_args, cmdline; char tempfile[] = "osalp-testfile.XXXXXX"; if(!mktemp(tempfile)) aflib_fatal("%s", strerror(errno)); out_args += "-f "; out_args += (*it)->getFormat(); out_args += " "; out_args += tempfile; cmdline = cmdname; cmdline += in_args; cmdline += out_args; aflib_info("Testing %s",(*it)->getFormat().c_str() );// aflib_info("Converting to %s",(*it)->getFormat().c_str() ); if(system(cmdline.c_str())==0){ cmdline = cmdname; cmdline += out_args; cmdline += " -f ossdsp"; system(cmdline.c_str()); } else { aflib_info("Error converting to %s",(*it)->getFormat().c_str() ); } unlink(tempfile); }}voidaudioChain::id( int argc, char* argv[] ) {static char* data_size_strs[] = { "UNDEFINED", "8 bit signed", "8 bit unsigned", "16 bit signed", "16 bit unsigned", "32 bit signed", "32 bit unsigned", 0};static char* data_endian_strs[] ={ "UNDEFINED", "little endian", "big endian", 0}; aflibStatus status = AFLIB_SUCCESS; aflibConfig config; string format, file; aflibAudioFile* input; format = "AUTO"; parseConfigArgs(argc,argv,config,format); if(optind >= argc) { aflib_fatal("No input file!"); } file = argv[optind]; /* Get input aflibAudioFile object * which will give us the configuration info of the file */ input = new aflibAudioFile(format,file,&config,&status); if(status != AFLIB_SUCCESS) { aflib_fatal("Error opening input file %s", file.c_str()); } aflib_info("%s type: %s", file.c_str(), input->getFormat().c_str()); aflib_info("rate: %d, channels: %d, samples: %d", config.getSamplesPerSecond(), config.getChannels(), config.getTotalSamples() ); aflib_info("data: %s %s", data_size_strs[config.getSampleSize()], data_endian_strs[config.getDataEndian()] ); delete input;}voidaudioChain::formats( int argc, char* argv[] ) { list<aflibFileItem*> modules_list; list<aflibFileItem*>::iterator it; modules_list = aflibFile::returnSupportedFormats(); aflib_info("Supported file formats\n"); aflib_info("format\t\tdescription"); for ( it = modules_list.begin(); it != modules_list.end(); it++) { aflib_info("%-10s\t%s", (*it)->getFormat().c_str(), (*it)->getDescription().c_str() ); }}voidaudioChain::help(int argc, char* argv[]){ aflib_info("osalp [mode [mode options]] [format options] infile [ [format options] outfile ]"); aflib_info("\nmode:"); aflib_info( "-a Print availible formats "); aflib_info( "-h Print this help message "); aflib_info( "-p <factor> Pitch"); aflib_info( "-i <filename> Print info about file "); aflib_info("\npitch options:"); aflib_info( "--linear Linear interpolation"); aflib_info( "--high High quality"); aflib_info( "--filter Filter interpolation"); aflib_info( "\nformat options:"); aflib_info( "-f File format"); aflib_info( "-c Number of channels"); aflib_info( "-r Sampling Rate"); aflib_info( "-b Data is signed byte"); aflib_info( "-B Data is unsigned byte"); aflib_info( "-w Data is signed word"); aflib_info( "-W Data is unsigned word"); list<aflibFileItem*> modules_list; list<aflibFileItem*>::iterator it; modules_list = aflibFile::returnSupportedFormats(); aflib_info("\nfile formats:"); string formats; for ( it = modules_list.begin(); it != modules_list.end(); it++) { formats += (*it)->getFormat().c_str(); formats += " "; } aflib_info("%s",formats.c_str());}voidaudioChain::date( int argc, char* argv[] ) { aflibDateTime datetime; datetime.setCurrentTime(); cout << datetime << endl;}#define PLAY_DELTA 4096 intaudioChain::process(aflibAudio* output){ // This function continues to process PLAY_DELTA until // AFLIB_END_OF_FILE is reached or another error is // encountered. aflibStatus status; int num_samples; long position = 0; // IF audio chain is not setup correctly then we are done if (output == NULL) return (false); do { num_samples = PLAY_DELTA; output->process(status, position, num_samples); position += num_samples; } while(num_samples); return (true); }voidaudioChain::parseConfigArgs( int argc, char **argv, aflibConfig& config, string& format) { int optchar; int findmore = 1; while (findmore) { optchar = getopt(argc, argv, "+f:r:c:bBwW"); switch(optchar) { case 'b': config.setSampleSize(AFLIB_DATA_8S); break; case 'B': config.setSampleSize(AFLIB_DATA_8U); break; case 'w': config.setSampleSize(AFLIB_DATA_16S); break; case 'W': config.setSampleSize(AFLIB_DATA_16U); break; case 'f': if(optind > argc){ aflib_fatal("Must specify a file format from %s -a",argv[0]); } else { format = optarg; } break; case 'r': if (optind > argc){ aflib_fatal("Must specify a sample rate with -r option"); } else { config.setSamplesPerSecond(atoi(optarg)); } break; case 'c': if (optind > argc){ aflib_fatal("Must specify channels with -c option"); } else { config.setChannels(atoi(optarg)); } break; case '?': optind--; findmore = 0; break; case EOF: findmore = 0; break; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -