IPhone AudioUnitRender Error -50 in the device

I am working on one project in which I used AudioUnitRender, it works fine in the simulator, but gives a -50 error on the device.

If someone has encountered a similar problem, please give me some solution.

RIOInterface* THIS = (RIOInterface *)inRefCon; COMPLEX_SPLIT A = THIS->A; void *dataBuffer = THIS->dataBuffer; float *outputBuffer = THIS->outputBuffer; FFTSetup fftSetup = THIS->fftSetup; uint32_t log2n = THIS->log2n; uint32_t n = THIS->n; uint32_t nOver2 = THIS->nOver2; uint32_t stride = 1; int bufferCapacity = THIS->bufferCapacity; SInt16 index = THIS->index; AudioUnit rioUnit = THIS->ioUnit; OSStatus renderErr; UInt32 bus1 = 1; renderErr = AudioUnitRender(rioUnit, ioActionFlags, inTimeStamp, bus1, inNumberFrames, THIS->bufferList); NSLog(@"%d",renderErr); if (renderErr < 0) { return renderErr; } 

size and frame data ...

 bytesPerSample = sizeof(SInt16); asbd.mFormatID = kAudioFormatLinearPCM; asbd.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; asbd.mBitsPerChannel = 8 * bytesPerSample; asbd.mFramesPerPacket = 1; asbd.mChannelsPerFrame = 1; //asbd.mBytesPerPacket = asbd.mBytesPerFrame * asbd.mFramesPerPacket; asbd.mBytesPerPacket = bytesPerSample * asbd.mFramesPerPacket; //asbd.mBytesPerFrame = bytesPerSample * asbd.mChannelsPerFrame; asbd.mBytesPerFrame = bytesPerSample * asbd.mChannelsPerFrame; asbd.mSampleRate = sampleRate; 

thanks in advance.

+6
source share
3 answers

The length of the buffer (inNumberFrames) may vary on device and simulator. In my experience, it is often more on the device. When you use your own AudioBufferList, this is what you should consider. I would suggest allocating more memory for the buffer in the AudioBufferList.

+3
source

I know this thread is outdated, but I found a solution to this problem.

The duration of the buffer for the device is different from the time on the simulator. Thus, you should change the buffer duration:

 Float32 bufferDuration = ((Float32) <INSERT YOUR BUFFER DURATION HERE>) / sampleRate; // buffer duration in seconds AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(bufferDuration), &bufferDuration); 
+3
source

Try adding kAudioFormatFlagsNativeEndian to the list of flags of the stream description format. Not sure if this will make a difference, but it won’t hurt.

In addition, I am suspicious of using THIS for the userData member, which by default does not populate this element with any meaningful data. Try running the code in the debugger and see if it is correctly extracted and this instance is running. Suppose, just for fun, try putting the AudioUnit object in a global variable (yes, I know ..) to see if it works.

Finally, why use THIS->bufferList instead of the one passed to your render callback? This is probably not very good.

0
source

Source: https://habr.com/ru/post/887404/


All Articles