本文整理汇总了C++中CAStreamBasicDescription::ChangeNumberChannels方法的典型用法代码示例。如果您正苦于以下问题:C++ CAStreamBasicDescription::ChangeNumberChannels方法的具体用法?C++ CAStreamBasicDescription::ChangeNumberChannels怎么用?C++ CAStreamBasicDescription::ChangeNumberChannels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAStreamBasicDescription
的用法示例。
在下文中一共展示了CAStreamBasicDescription::ChangeNumberChannels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char *argv[])
{
const char *recordFileName = NULL;
// set up defaults
AudioFileTypeID filetype = kAudioFileAIFFType;
bool gotOutDataFormat = false;
CAStreamBasicDescription dataFormat;
dataFormat.mSampleRate = 44100.; // later get this from the hardware
dataFormat.mFormatID = kAudioFormatLinearPCM;
dataFormat.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
dataFormat.mFramesPerPacket = 1;
dataFormat.mChannelsPerFrame = 2;
dataFormat.mBitsPerChannel = 16;
dataFormat.mBytesPerPacket = dataFormat.mBytesPerFrame = 4;
SInt32 bitrate = -1, quality = -1;
// parse arguments
for (int i = 1; i < argc; ++i) {
const char *arg = argv[i];
if (arg[0] != '-') {
if (recordFileName != NULL) {
fprintf(stderr, "may only specify one record file\n");
usage();
}
recordFileName = arg;
} else {
arg += 1;
if (arg[0] == 'f' || !strcmp(arg, "-file")) {
if (++i == argc) MissingArgument();
filetype = Parse4CharCode(argv[i], "-f | --file");
} else if (arg[0] == 'd' || !strcmp(arg, "-data")) {
if (++i == argc) MissingArgument();
if (!ParseStreamDescription(argv[i], dataFormat))
usage();
gotOutDataFormat = true;
} else if (arg[0] == 'b' || !strcmp(arg, "-bitrate")) {
if (++i == argc) MissingArgument();
bitrate = ParseInt(argv[i], "-b | --bitrate");
} else if (arg[0] == 'q' || !strcmp(arg, "-quality")) {
if (++i == argc) MissingArgument();
quality = ParseInt(argv[i], "-q | --quality");
} else {
fprintf(stderr, "unknown argument: %s\n\n", arg - 1);
usage();
}
}
}
if (recordFileName == NULL)
usage();
if (!gotOutDataFormat) {
if (filetype == 0) {
fprintf(stderr, "no output file or data format specified\n\n");
usage();
}
if (!CAAudioFileFormats::Instance()->InferDataFormatFromFileFormat(filetype, dataFormat)) {
fprintf(stderr, "Couldn't infer data format from file format\n\n");
usage();
}
} else if (filetype == 0) {
if (!CAAudioFileFormats::Instance()->InferFileFormatFromDataFormat(dataFormat, filetype)) {
dataFormat.PrintFormat(stderr, "", "Couldn't infer file format from data format");
usage();
}
}
unlink(recordFileName);
if (dataFormat.IsPCM())
dataFormat.ChangeNumberChannels(2, true);
else
dataFormat.mChannelsPerFrame = 2;
try {
const int kNumberBuffers = 3;
const unsigned kBufferSize = 0x8000;
CAAudioFileRecorder recorder(kNumberBuffers, kBufferSize);
FSRef parentDir;
CFStringRef filename;
XThrowIfError(PosixPathToParentFSRefAndName(recordFileName, parentDir, filename), "couldn't find output directory");
recorder.SetFile(parentDir, filename, filetype, dataFormat, NULL);
CAAudioFile &recfile = recorder.GetFile();
if (bitrate >= 0)
recfile.SetConverterProperty(kAudioConverterEncodeBitRate, sizeof(UInt32), &bitrate);
if (quality >= 0)
recfile.SetConverterProperty(kAudioConverterCodecQuality, sizeof(UInt32), &quality);
Record(recorder);
}
catch (CAXException &e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, CAXException::FormatError(buf, e.mError));
return 1;
}
catch (...) {
//.........这里部分代码省略.........