作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将mp3文件加载到ios的OpenAL缓冲区中,并且已经从示例中复制了一些代码。
因此,使用此代码:
CFURLRef fileURL = nil;
NSString* nsPath = [CDUtilities fullPathFromRelativePath:[NSString stringWithUTF8String:FilePath.c_str()]];
if (nsPath) {
fileURL = (CFURLRef)[[NSURL fileURLWithPath:nsPath] retain];
}
#if 0
status = AudioFileOpenURL (fileURL, kAudioFileReadPermission, kAudioFileMP3Type, &AudioFileHandle );
ExtAudioFileWrapAudioFileID ( AudioFileHandle, false, &ExtAudioFileHandle );
// Close the AudioFile handle. It's no longer needed
AudioFileClose ( AudioFileHandle );
AudioFileHandle = nullptr;
#else
status = ExtAudioFileOpenURL ( fileURL, &ExtAudioFileHandle );
#endif
// Get the audio data format
UInt32 PropertySize = sizeof ( InputDataFormat );
status = ExtAudioFileGetProperty ( ExtAudioFileHandle, kExtAudioFileProperty_FileDataFormat, &PropertySize, &InputDataFormat);
if (status != noErr)
{
DecodeResult = false;
goto function_exit;
}
if ( InputDataFormat.mChannelsPerFrame > 2 )
{
DecodeResult = false;
goto function_exit;
}
// Set the client format to 16 bit signed integer (native-endian) data
// Maintain the channel count and sample rate of the original source format
OutputDataFormat.mSampleRate = InputDataFormat.mSampleRate;
OutputDataFormat.mChannelsPerFrame = InputDataFormat.mChannelsPerFrame;
OutputDataFormat.mFormatID = kAudioFormatLinearPCM;
OutputDataFormat.mBytesPerPacket = 2 * InputDataFormat.mChannelsPerFrame;
OutputDataFormat.mFramesPerPacket = 1;
OutputDataFormat.mBytesPerFrame = 2 * InputDataFormat.mChannelsPerFrame;
OutputDataFormat.mBitsPerChannel = 16;
OutputDataFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;
// Set the desired client (output) data format
status = ExtAudioFileSetProperty ( ExtAudioFileHandle, kExtAudioFileProperty_ClientDataFormat, sizeof ( OutputDataFormat ), &OutputDataFormat );
if (status != noErr)
{
DecodeResult = false;
goto function_exit;
}
// Get the total frame count
PropertySize = sizeof ( FrameCount );
status = ExtAudioFileGetProperty ( ExtAudioFileHandle, kExtAudioFileProperty_FileLengthFrames, &PropertySize, &FrameCount );
if (status != noErr)
{
DecodeResult = false;
goto function_exit;
}
最佳答案
好的,所以我找到了答案。显然完全与我在某些示例中看到的相反,您无法在将原始句柄转换为ExtAudioFile后释放它。我将那个AudioFileClose代码移到了函数的末尾,突然一切正常。我只是想知道为什么其他所有东西都继续使用封闭的句柄,但不是那个特定的属性得到了,而是……苹果的奥秘:)
关于c++ - 从音频文件转换ExtAudioFile时,ExtAudioFileGetProperty失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40789366/
我想按如下方式从音频文件中读取AudioStreamBasicDescription AudioStreamBasicDescription asdb; UInt32 propSize = sizeo
我是一名优秀的程序员,十分优秀!