syedhali / EZAudio

An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.
Other
4.94k stars 821 forks source link

PlayFile Demo Crash When Screen Is Locked #311

Open saitjr opened 8 years ago

saitjr commented 8 years ago

In the demo PlayFile, when I set BackgroundMode on and allow audio play in background :

screen shot 2016-05-09 at 17 07 24

environment : iPhone5s iOS 9.3.1

Run on simulator is totally fine. And there is no problem if I set AVAudioSession to PlayAndRecord.

dxclancy commented 8 years ago

I see this as well.

dxclancy commented 8 years ago

Placing a breakpoint in malloc_error_debug hasn't helped me at all, so I turned on Address Sanitizer. (edit schemes).

This causes an immediate break in

- (void)convertDataFromAudioBufferList:(AudioBufferList *)audioBufferList ...

at ..

        [EZAudioUtilities checkResult:AudioConverterFillComplexBuffer(self.info->converterRef,

The issue is that for some reason when the lock screen is activated, the amount of frames goes from 1024 to 4096. And this triggers this offending line:

            audioBufferList->mBuffers[i].mDataByteSize = frames * self.info->inputFormat.mBytesPerFrame;

Essentially, the bufferSize that was allocated was 4096, and the size is set to 16384 even though it is STILL only a buffer of 4096. This causes an overwrite of the buffer in AudioConverterFillComplexBuffer.

I'm not knowledgable enough to know if this is a bug in EZAudio, or a result of incorrect configuration of the properties that lead to the buffer initialization. It definitely seems EZAudio is wrong to blindly change the buffer size despite what it's ACTUAL capacity size it is.

dxclancy commented 8 years ago

I'm not sure what the proper fix for this is. You can work around it by multiplying 4 to the calculated buffer size in

EZAudioUtilities.m : audioBufferListWithNumberOfFrames audioBufferList->mBuffers[i].mData = calloc(bufferSize * 4, 1);

Also see #303 which is unrelated to this, but related to lock screen.

saitjr commented 8 years ago

That's work for me, thank you very much. And #303 is work for me too.

dxclancy commented 8 years ago

Please do not close this. My workaround is not a fix but an awful hack. We need to understand if this is a bug in EZAudio or a problem in setup of the properties that lead to buffer allocation, and this needs to be fixed.

Please reopen.

saitjr commented 8 years ago

👌

matanvr commented 8 years ago

This fix is causing crashes in my app, any idea what the actual fix is?

saitjr commented 8 years ago

Have you ever take a look at #303, It works for me.