• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Having trouble with AudioConverterFillComplexBuffer (error -50)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Having trouble with AudioConverterFillComplexBuffer (error -50)


  • Subject: Having trouble with AudioConverterFillComplexBuffer (error -50)
  • From: Samuel Goodwin <email@hidden>
  • Date: Wed, 28 Jul 2010 17:17:19 -0600

Hey guys,


I am writing an iPhone app that needs to be able to convert recorded LPCM audio data into an m4a. My code works fine right up to the point where I make the call to AudioConverterFillComplexBuffer. At this point, I receive  an error code 50 which apparently means bad parameters?

Here is the relevant code, GODebugOnError simply prints out the error code and throws an exception to make it obvious I messed up.:

------
- (void)convertFileAtURL:(NSURL*)inURL{
	NSLog(@"Converting file! at url: %@", inURL);
	if(![[NSFileManager defaultManager] fileExistsAtPath:[inURL path]]){
		NSLog(@"File doesn't exist!");
	}

	AudioFileID audioFile;
	GODebugOnError(AudioFileOpenURL((CFURLRef)inURL, kAudioFileReadPermission , 0, &audioFile), @"Failed to open file at input url");

	_recordState.mInputURL = (CFURLRef)inURL;

	NSLog(@"Opened file for reading.");

	UInt64 audioDataSize = 0;
	UInt32 dataSize = sizeof(audioDataSize);
	GODebugOnError(AudioFileGetProperty(audioFile, kAudioFilePropertyAudioDataPacketCount, &dataSize, &audioDataSize), @"Failed to get audio data size :(");

	NSLog(@"Read datasize! %d packets", (int)dataSize);

    AudioStreamBasicDescription input;
    dataSize = sizeof(input);
	GODebugOnError(AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &dataSize, &input), @"Failed to get stream description of the input");

    NSLog(@"Read input basic stream description, incoming frequency: %f", input.mSampleRate);

    const AudioStreamBasicDescription output = [[self class] outputDescription];
    GODebugOnError(AudioConverterNew(&input , &output, &_converter), @"Failed to setup audio converter");

    AudioBufferList *outputBuffer = create_buffer_list(2);
	UInt32 numPackets = 2;
	AudioStreamPacketDescription odesc = { 0 };
	GODebugOnError(AudioConverterFillComplexBuffer(_converter, MyAudioConverterComplexInputDataProc, &_recordState, &numPackets, outputBuffer, &odesc), @"Failed to fill complex buffer!");

------- // It never gets to this point here. // --------

	NSLog(@"Got myself an output buffer to write!");

	// Once we get the new buffer, write it out to aac...

	NSString *base = [[[inURL path] lastPathComponent] stringByDeletingPathExtension];
	NSString *filename = [base stringByAppendingFormat:@".m4a"];
	NSString *path = [[[inURL path] stringByDeletingLastPathComponent] stringByAppendingPathComponent:filename];
	NSURL *outURL = [NSURL fileURLWithPath:path];
	NSLog(@"Writing output file to url: %@", outURL);
	AudioFileID outputAudioFile;
	AudioFileCreateWithURL((CFURLRef)outURL, kAudioFileM4AType, &output, kAudioFileFlags_EraseFile, &outputAudioFile);

	if (numPackets > 0) {
		// write packets to file
		GODebugOnError(AudioFileWritePackets(outputAudioFile, FALSE, outputBuffer->mBuffers[0].mDataByteSize, &odesc, 0, &numPackets, outputBuffer->mBuffers[0].mData), @"Failed to write resulting data :( ");
	}
}
------

These are the output settings I'm using:

AudioStreamBasicDescription outputSettings;

	outputSettings.mFormatID         = kAudioFormatMPEG4AAC;
	float frequency = [[[NSUserDefaults standardUserDefaults] objectForKey:kSampleRateKey] floatValue];
	if(frequency == 0.0f){
		frequency = (float)[[AVAudioSession sharedInstance] currentHardwareSampleRate];
	}
	NSLog(@"Setting up frequency: %f", frequency);
	outputSettings.mSampleRate       = frequency;
	outputSettings.mFormatID = kAudioFormatMPEG4AAC;
	outputSettings.mFormatFlags = 0;
	outputSettings.mBytesPerPacket = 0;
	outputSettings.mFramesPerPacket = 0;
	outputSettings.mBytesPerFrame = 0;
	outputSettings.mChannelsPerFrame = 1;
	outputSettings.mBitsPerChannel = 0;
	outputSettings.mReserved = 0;

	//outputSettings.mChannelsPerFrame = 2;
	return outputSettings;


If anyone could point out what I'm doing wrong, it would be greatly appreciated!


Thanks for your time,

Samuel Goodwin

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: advice to associate custom signal processing with a device
  • Next by Date: New sample app posted: MixerHost
  • Previous by thread: Re: Feedback between external speaker and microphone on iPhone3G
  • Next by thread: New sample app posted: MixerHost
  • Index(es):
    • Date
    • Thread