Closed little-dandan closed 4 years ago
Hi little-dandan,
I checked the OSStatus, -50
. It's an audio parameter error.
See on OSStatus.com.
Would you like to share your testing conditions when you run this demo code? I am also curious about when this error raises.
Do you mean to check the OSStatus, -50
and log the error in the code ?
Thank you for your answer: as i run your demo, the acquired audio file can not play. its duration is 00:00, you can try it (CH06_AudioConverter). My Xcode version is: Version 11.3.1(11C504) Thank you
The issue came from using the latest API AudioFileReadPacketData
. In the original sample code which was written in C language, it used the old API AudioFileReadPackets
which is fine to use zero value of outNumBytes
. But, int the new API AudioFileReadPacketData
, it is no longer using outNumBytes
and uses ioNumBytes
instead. That means we need to specified the correct size of out buffer in bytes.
New Implementation like below
var outByteCount: UInt32 = ioDataPacketCount.pointee * UInt32(audioConverterSettings.inputFilePacketMaxSize)
audioConverterSettings.sourceBuffer = calloc(1, Int(outByteCount))
var result = AudioFileReadPacketData(audioConverterSettings.inputFile!,
true,
&outByteCount,
audioConverterSettings.inputFilePacketDescriptions,
Int64(audioConverterSettings.inputFilePacketIndex),
ioDataPacketCount,
audioConverterSettings.sourceBuffer)
Please check the commit f5b4591c44a54c726bc53690e20e3e669f62a46c
Thanks for @little-dandan to help correct this error.
Thank you: But there are new problems. output file duration is very short. You can open the compressed audio file, the sound content will play very fast, completely can not hear the content.
use AudioConverterFillComplexBuffer OSStatus: -50 in your demo。