Media recording slow down

Sent through email as well - posted here for everyone.

SDK version: 2010.243 - current

Brief:

The media recording feature is now extremely slow, presumably after OpenAL was introduced.
The average time on the device to startup Tuner and Recording was below 1 second. As of now it takes 3 to 4 seconds (blocking everything else) in order to start it up. Also, when recording is started, music stops automatically.

The bug isn’t present in Simulator, nor music stops automatically when recording is started.

Workarounds:
None currently.
Tried unreserving channels, stopping any channels playing, freeing audio resources etc.

Tested on: iPhone 3GS
[import]uid: 5750 topic_id: 5109 reply_id: 305109[/import]

So there are actually multiple pieces here, each worth addressing.

First, playback stopping when recording starts was a conscious decision we made on iOS. On iOS, there is something called an Audio Session which applications are required to setup. There are different modes Apple allows developers to pick from, each with different repercussions. We tried to hide these details in Corona and pick the most useful ones. In iOS, you must consciously specify you want to record something. And if you want to playback and record, there is a different mode for that. However, the combo playback and record may come at a performance price. Since usually for recording from a microphone, you don’t want feedback from the speaker, we shut off playback on iOS which should also give you the most performance to actually handle the recording aspect.

The Mac Simulator implementation doesn’t have a notion of Audio Sessions so that is why you see a difference there.

Out of curiosity, would you describe the simultaneous playback and recording case you need? It’s probably legitimate, but we expected most users won’t need this. But maybe you have a case that is more common than we think.

Unfortunately, I think there are only two solutions to this, both of which require us to make changes. We need to either always use playback and record modes for recording which could negatively impact performance for people that don’t need it or we need to expose Audio Sessions which adds complexity to the API. (And Audio Sessions have no meaning on Android.)
Second, the reason that this worked before our new audio engine introduction was actually an implementation fluke depending on undefined behavior by Apple. In reality, it probably should have never worked.
Third, I don’t know why you are seeing a performance slow down. We do have some minor optimizations in the next release, but I don’t think it will affect this. Would you please send us a reproducible test case?

[import]uid: 7563 topic_id: 5109 reply_id: 16862[/import]

Hi ewing and thanks for replying.

My case involves using the microphone for a piece of gameplay - common to what you see on some Nintendo DS games.

As for the Audio Session mode, would it be possible to have a function that switches modes ? That way one could call it at startup or whenever, knowing the penalties you described.

But I’m most concerned with the current recording “setup” time on the device.

Currently I have a system that manages OpenAL functions. Since I’m also able to disable the whole system - by means of dummy functions - I was able to test the recording performance drop independently.

I’m going to dig deeper into this today and possibly send you a repro case… or find a bug in my code, whichever comes first. :))

Out of curiosity, are you now switching Audio Session modes on the fly when starting recording while you weren’t before OpenAL introduction ?

Thank you. [import]uid: 5750 topic_id: 5109 reply_id: 16888[/import]

@ewing

I sent a repro case to support@ansca.net.
Please let me know if you got it.

Thanks.

P.S.: there’s also a weird, very noticeable Y offset on a text object, between Simulator and the actual device. I left it as is… as I suppose Simulator should be faithful when dealing with GL-related stuff and coordinates system. [import]uid: 5750 topic_id: 5109 reply_id: 16901[/import]

Yes, the switching behavior is new. When you start recording, we dynamically change the Audio Session mode. And when you stop recording, we change the Audio Session back.
[import]uid: 7563 topic_id: 5109 reply_id: 16923[/import]

It looks like the switching is a slow operation on the device.
Including the audio session mode selection in the next API could be a solution, so anyone can pick and test the one that fits for his app at startup.

It might be an iOS 3.x issue only, in that case, since most older devices (3G to 3GS) can upgrade to 4.x, it could be ok…although 3.x “nice” support could still be desirable.

Otherwise I’d have to drop the microphone feature, since 3 to 4 seconds wait on iPhone 3GS is way too much.

Thanks.
[import]uid: 5750 topic_id: 5109 reply_id: 17032[/import]

SDK 2011.268
1st Gen iPhone with 3.1.3

I am also experiencing the 3-4 slow start with the media recording. You can duplicate this with your SimpleAudioRecorder. A similar delay occurs after pressing stop.

Are there plans to fix this? Is there a work-around? I am almost finished with this App, and would like to submit soon. Other Apps work on my phone, like Audio Memos SE (free), or the included Voice Memos. [import]uid: 47723 topic_id: 5109 reply_id: 32902[/import]

Sorry, we still don’t have a fix for this. This looks more and more like an Apple bug which we may not be able to fix, particularly since this doesn’t seem to be a problem with 4.x. With Apple, the answer is usually ‘upgrade’ (to 4.x), despite whether you can actually do so. The research we see about percentages of 3.1 users is less than 10% now.

[import]uid: 7563 topic_id: 5109 reply_id: 32979[/import]

Thanks for your feedback ewing. Less than 10%, so only less than 10 million users that can’t download my app. That means 90+ million that can if I stick with the easy route, meaning Corona. Plus the continued attrition rate on pre 4 devices will only continue.

I also have an iPod Touch 2nd Gen with 3. If I upgrade that to iOS4, will the audio run correctly on it?

Just so I know, are you contiuing to look in to a fix or not? [import]uid: 47723 topic_id: 5109 reply_id: 32985[/import]

I haven’t closed the bug, but we haven’t had much time to focus on it. (Android problems are sucking up all the air.)

The reports and internal testing we’ve done don’t reproduce the problem on 4.x, though we haven’t retested since the initial report.

I don’t think we are going to fix this directly, but indirectly we are considering a few things. Most notably, we are thinking about exposing the AudioSession APIs on iOS. This might indirectly allow you to work around the problem. However, we have not scheduled this and have not committed to this idea (partly since AudioSessions have no meaning on non-iOS platforms).

[import]uid: 7563 topic_id: 5109 reply_id: 32988[/import]

Thank you for your clear answer, and keeping the issue open. I tested on an iPad with iOS 4.3 and the issue is not there. I will see what happens when I upgrade the iPod Touch 2nd Gen to 4.x. [import]uid: 47723 topic_id: 5109 reply_id: 33020[/import]

Results from upgrading my 2 Gen iPod Touch from 3.1.3 to 4.2.1:
The 3-4 second slow start up and stop are not present. It works as expected now. I will continue with 4.x development for now, and revisit a 3.x solution later. [import]uid: 47723 topic_id: 5109 reply_id: 33570[/import]