3

I get an Error -50 in AudioUnitRender call. My Audio Unit is simply a RemoteIO unit getting samples from the mic. What is the meaning of error -50?

  let status = AudioUnitRender(controller.audioUnit!, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, listPtr)

if noErr != status {
    print("Error \(status)");
    fatalError("Render status \(status)")
  // return status;
}
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

2 Answers2

3

-50 (kAudio_ParamError) means one of the parameters you passed is wrong.

A common error with AudioUnitRender is to pass an AudioBufferList with the wrong number of mNumberBuffers (you may be recording non-interleaved stereo) or the AudioBuffers themselves may be the wrong size or have the wrong number of channels.

I encounter this problem whenever I forget that the simulator and device remote audio units have different default stream formats and don't explicitly set them via

AudioUnitSetProperty(audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &streamFormatIActuallyWant, UInt32(MemoryLayout<AudioStreamBasicDescription>.size))

I think the simulator defaults to interleaved integer and the device defaults to non interleaved float, although maybe that's just my configuration.

From the AudioUnitRender header file:

The caller must provide a valid ioData AudioBufferList that matches the expected topology for the current audio format for the given bus. The buffer list can be of two variants:
(1) If the mData pointers are non-null then the audio unit will render its output into those buffers. These buffers should be aligned to 16 byte boundaries (which is normally what malloc will return).
(2) If the mData pointers are null, then the audio unit can provide pointers to its own buffers. In this case the audio unit is required to keep those buffers valid for the duration of the calling thread's I/O cycle

By passing null mData (point (2)) can save you an unnecessary copy, but you still need to know the format "topology", which is just mNumberBuffers (probably 1 or 2).

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
  • How do I pass an AudioBufferList with nil mData, I try but it again gives -50 error. – Deepak Sharma Aug 28 '18 at 09:21
  • My configuration is complex. I have AVCaptureSession as well. I reproduce -50 error as follows. Start the app and quit it before AVCaptureSession is initialized. I see everything setup in background. Now the moment I bring the app to foreground, I start getting -50 error. No idea how to debug it. – Deepak Sharma Aug 28 '18 at 09:32
  • Do you have a project on github you can share? – Rhythmic Fistman Aug 28 '18 at 09:41
  • Unfortunately it is only showing in my app which is complex. I am trying to make a sample app which reproduces the issue but it is hard. Will keep you posted as soon as I recreate minimal sample code. – Deepak Sharma Aug 28 '18 at 10:40
  • 1
    I see the problem occurs when inNumberFrames parameter is odd length (1115 instead of 1114). I don't know how inNumberFrames changes from 1024 to 1114 or 1115 after interruption. Any ideas what influences this param? – Deepak Sharma Aug 28 '18 at 12:25
  • I have added a new question with code that is very specific, please have a look and let me know your inputs: https://stackoverflow.com/questions/52061575/audiounitrender-error-50-with-odd-length-buffers – Deepak Sharma Aug 28 '18 at 15:33
  • For the funny buffer sizes, it sounds like the `AVAudioSession` sampling rate was changed. You can try and change it back I guess, but your code should ideally deal with non-preferred settings as you're not guaranteed to get what you ask for. – Rhythmic Fistman Aug 28 '18 at 15:35
  • Yes I change it back to 44100 when my AVCaptureSession resumes, but I find that all buffers are 1115 in length continuously in my Swift app setup. In Objective C project, everything works and I get inNumberBuffers alternating between 1114 and 1115. I have no idea what causes 1115 buffer size continuously in Swift code. Rather than looking code line by line, I am trying to identify the place where things go wrong. – Deepak Sharma Aug 28 '18 at 15:58
  • There's a sample rate converter between you and the hardware - `1024*48000/44100 = 1114.5...` frames, hence the alternating between 1114 and 1115. – Rhythmic Fistman Aug 28 '18 at 16:08
  • But where is this 48000 coming from? The mic defaults to 44100 as far as I know. When there is category change from playback to record, why is number of frames not reset to 1024? – Deepak Sharma Aug 28 '18 at 17:17
  • Ok I have good news. I have reproducible sample code that is minimal. Should I share it with you? – Deepak Sharma Aug 29 '18 at 13:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/179032/discussion-between-rhythmic-fistman-and-deepak-sharma). – Rhythmic Fistman Aug 29 '18 at 14:02
  • sent you a message in chat – Deepak Sharma Sep 03 '18 at 18:22
  • where do you find that error code -50 corresponds to kAudio_ParamError. the documentation of apple is just useless https://developer.apple.com/documentation/audiotoolbox/1440513-audiooutputunitstop (A result code. hahahahaha) – Martin Mlostek Sep 11 '19 at 10:18
  • 1
    You can either use https://www.osstatus.com or grep header files. It's not great. Also I think -50 has been a parameter error on the mac for a loooooooooong time, like 25+ years. – Rhythmic Fistman Sep 11 '19 at 13:14
0

make sure you pass an AudioBufferList with enough mDataByteSize, it should large than the inNumberFrames * channel.

tanrk
  • 1