本文整理汇总了C++中CAStreamBasicDescription::BytesToFrames方法的典型用法代码示例。如果您正苦于以下问题:C++ CAStreamBasicDescription::BytesToFrames方法的具体用法?C++ CAStreamBasicDescription::BytesToFrames怎么用?C++ CAStreamBasicDescription::BytesToFrames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAStreamBasicDescription
的用法示例。
在下文中一共展示了CAStreamBasicDescription::BytesToFrames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoConvertFile
//.........这里部分代码省略.........
// we are always going to be able to resume conversion after an interruption
if (kAudioConverterErr_PropertyNotSupported == error) {
printf("kAudioConverterPropertyCanResumeFromInterruption property not supported!\n");
} else {
printf("AudioConverterGetProperty kAudioConverterPropertyCanResumeFromInterruption result %ld\n", error);
}
error = noErr;
}
// set up buffers
UInt32 bufferByteSize = 32768;
char srcBuffer[bufferByteSize];
// keep track of the source file offset so we know where to reset the source for
// reading if interrupted and input was not consumed by the audio converter
SInt64 sourceFrameOffset = 0;
//***** do the read and write - the conversion is done on and by the write call *****//
printf("Converting...\n");
while (1) {
AudioBufferList fillBufList;
fillBufList.mNumberBuffers = 1;
fillBufList.mBuffers[0].mNumberChannels = clientFormat.NumberChannels();
fillBufList.mBuffers[0].mDataByteSize = bufferByteSize;
fillBufList.mBuffers[0].mData = srcBuffer;
// client format is always linear PCM - so here we determine how many frames of lpcm
// we can read/write given our buffer size
UInt32 numFrames;
if (clientFormat.mBytesPerFrame > 0) // rids bogus analyzer div by zero warning mBytesPerFrame can't be 0 and is protected by an Assert
numFrames = clientFormat.BytesToFrames(bufferByteSize); // (bufferByteSize / clientFormat.mBytesPerFrame);
XThrowIfError(ExtAudioFileRead(sourceFile, &numFrames, &fillBufList), "ExtAudioFileRead failed!");
if (!numFrames) {
// this is our termination condition
error = noErr;
break;
}
sourceFrameOffset += numFrames;
// this will block if we're interrupted
Boolean wasInterrupted = ThreadStatePausedCheck();
if ((error || wasInterrupted) && (false == canResumeFromInterruption)) {
// this is our interruption termination condition
// an interruption has occured but the audio converter cannot continue
error = kMyAudioConverterErr_CannotResumeFromInterruptionError;
break;
}
error = ExtAudioFileWrite(destinationFile, numFrames, &fillBufList);
// if interrupted in the process of the write call, we must handle the errors appropriately
if (error) {
if (kExtAudioFileError_CodecUnavailableInputConsumed == error) {
printf("ExtAudioFileWrite kExtAudioFileError_CodecUnavailableInputConsumed error %ld\n", error);
/*
Returned when ExtAudioFileWrite was interrupted. You must stop calling
ExtAudioFileWrite. If the underlying audio converter can resume after an
interruption (see kAudioConverterPropertyCanResumeFromInterruption), you must
wait for an EndInterruption notification from AudioSession, then activate the session
before resuming. In this situation, the buffer you provided to ExtAudioFileWrite was successfully