0

Whenever I run the following code, it crashes on AudioConverterNew( ). But if I change to a PCM file in the pathForResource line (e.g. Test02.aif), it works well and was able to playback the file. Could somebody suggest something for me to try?

NSString *filePath = [[NSBundle mainBundle] pathForResource: @"Test01" ofType:@"m4a"];
CFURLRef audioURL = (__bridge  CFURLRef) [NSURL fileURLWithPath:filePath];

// open the input audio file
AudioFileOpenURL(audioURL, kAudioFileReadPermission, 0, &gSourceAudioFileID);

AudioConverterRef myConverter;
// get file's asbd
UInt32 size;
AudioStreamBasicDescription fileASBD = {0};
size = sizeof(AudioStreamBasicDescription);
AudioFileGetProperty(gSourceAudioFileID,
                     kAudioFilePropertyDataFormat,
                     &size,
                     &fileASBD);
if (fileASBD.mFormatID == kAudioFormatMPEGLayer3) NSLog(@"its mp3");
NSLog(@"fileASDB formatId: %d", (unsigned int)fileASBD.mBytesPerFrame);
//NSLog(@"file formatId: %d", (unsigned int)fileASBD.mFormatID);

OSStatus error=  AudioConverterNew(&fileASBD,
                  &thruFormat ,
                  &(myConverter));
NSLog(@"error: %d", (int)error);
John
  • 2,672
  • 2
  • 23
  • 29
  • What was the error message? Most likely it is because AudioConverterNew doesnot support mp3 format due to copyright issues. http://stackoverflow.com/questions/3758618/convert-recorded-sound-in-iphone-from-one-format-to-another-say-wav-to-mp3 – user523234 Nov 22 '13 at 11:55
  • @user523234 Hi I didn't see any message. It breaks at that line of code because of the All exception breakpoint that I set. Is there anyway I can see the error message after it breaks? – John Nov 22 '13 at 15:46
  • You need to post more code. What is the value of `thruFormat`? If you simply want to get a file's audio in a different format have a look at `ExtAudioFile`. It wraps an `AudioFileID` and an `AudioConverterRef` and takes care of the drudgery. In reference to @user523234's comment about MP3, you should be able to decode from MP3 but not encode to it. – sbooth Nov 23 '13 at 12:59
  • @sbooth, thanks for your help. I ended up giving up using AudioConverter to fill render buffer (AudioConverterFillComplexBuffer). Instead, I convert the whole compressed file into linear PCM, and then start rendering with the Linear PCM data. I hope I will have time in the future to come back to AudioConverter to find out why it didn't work here. Thanks. – John Nov 25 '13 at 05:23

0 Answers0