OpenAL initializing impairs performance of my iPhone game - iphone

I have a bad performance problem with OpenAL in my iPhone game. My game runs smoothly with 60fps but when I initialize OpenAL the game begins to jerk. This is my initialisation code:
ALCdevice* device = alcOpenDevice(NULL);
ALCcontext *context;
if(device) {
context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);
}
I don't create any OpenAL Sources nor load/play any sounds. The jittering (the game jerks all the time) is caused by the initializing of OpenAL.
The XCode instruments are saying that the game runs with stable 60fps yet it's obviously jittering (when I don't run the code above the game runs smoothly).
This also doesn't happen on an old iPod Touch 2G with iOS 3.1.3. On all my other devices with iOS 4 the jittering happens, which is also crazy.
I also tried to put the OpenAL stuff in a separate thread but it doesn't help.
Has anybody noticed a similar behaviour?

Try calling alcGetError() after context set up to ensure it succeeded.
Is this failing on the simulator or on an actual phone?
Are you doing anything with sound after the code you posted? In the code you posted if alcOpenDevice fails then you won't have a context, yet you don't return either.

Related

Flutter audioplayers package: Android vs iOS

I'm quite new into flutter and coding in general. I'm trying to build a meditation app, that plays a bell every 30/60/120... seconds, depends on user input. My code works perfectly fine on Android device, but when running on iOS, it plays bell only once and doesn't play anymore. Any suggestions please? Thank you!
if (((widget.meditation.notification) != 0) &&
((_time % widget.meditation.notification) == 0)) {
print('notification $_time');
audioCache.play('audio/bell.wav');
}
Finally I found solution, simply everytime .release() must be called.
By default, the player will be release once the playback is finished or the stop method is called.
This is because on Android, a MediaPlayer instance can be quite resource-heavy, and keep it unreleased would cause performance issues if you play lots of different audios.
On iOS and macOS this doesn't apply, so release does nothing.

Using Ti.Media.VideoPlayer video does not loop on iPhone 4

Having a weird problem with my app.
Trying to play a video in a loop (see the code below). VideoPlayer repeatMode is set to Ti.Media.VIDEO_REPEAT_MODE_ONE.
Works in simulator, works on iPhone 4s, works on iPad Air... does not work on iPhone 4 (all of them running iOS 7.1.1 apart from simulator - 7.1).
Exact symptoms: after one play, video should restart from beginning, but it stops. If controls are available, I can press play to start playing it again, then after reaching the end it stops again.
I could swear that it worked on iPhone 4 before the 7.1 upgrade, but somehow it stopped.
Anyone could replicate this issue? Or have any idea?
Sys info:
Titanium SDK: Tested with 3.2.3.GA; 3.2.2.GA; 3.2.1.GA; 3.2.0.GA
Platform & version: iOS 7.1.1 (11D201)
Device: works on iPhone 4s, iPad Air, simulator; fails on iPhone 4
Host Operating System: OSX 10.9.2
Titanium Studio: 3.2.3.201404181442
Xcode: 5.1.1 (5B1008)
Alloy: 1.3.1
Code for basic Alloy project to replicate:
index.js
var videoPlayer = Titanium.Media.createVideoPlayer({
autoplay : true,
fullscreen : false,
mediaControlStyle : Titanium.Media.VIDEO_CONTROL_DEFAULT,
repeatMode: Ti.Media.VIDEO_REPEAT_MODE_ONE,
scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT
});
//Video is 12s long so it is easy to notice that it does not loop.
videoPlayer.url = "video/candles.mp4";
$.index.add(videoPlayer);
$.index.open();
index.xml
<Alloy>
<Window class="container">
</Window>
</Alloy>
I would appreciate any suggestions.
I have done some research and played around with the Titanium.Media.VideoPlayer and managed to work around the issue. Below you can find the solution in case anyone else encounter this problem.
First of all, some info on the problem.
I have found some forum boards where developers were having very similar problem with MPMoviePlayerController on iPad 1st gen. Looped video was less or more randomly freezing on loop. So I think there is a problem with the Apple video player on some devices, and not necessary with Titanium implementation.
My first approach was to try replay video on complete event that is fired when video stops playing, instead of using repeatMode.
So far so good. It worked on the first time, yay! But the happiness was rather short. During an hour of test of videoPlayer.play() on event complete, the video sometimes was repeating 10-30 times fine and then suddenly was freezing. What gives? Turns out the video player had some sort of a hiccup.
Normal sequence of events was as follows:
video ends, playbackstate changes to 2,
complete event is fired
I restart video on complete
playbackstate changes to 1, video is playing until the end.
For a mysterious reason once in a while this sequence got additional something happening:
video reaches the end - playbackstate changes to 2,
complete event is fired.
video gets restarted on complete
playbackstate changes to 1, video starts playing
suddenly playbackstate changes to 1, video stops, without firing complete event.
Solution
So, knowing all this, I have set up listeners to listen to playbackstate instead of complete and when I hear playbackstate: 1 then I restart video and tadaaa! Everything works!.
Caveat: not 'everything' unfortunately. I am using custom video controls, so I have lost pause, and stop ability (every time video playback state changes to 'stopped' I restart it forcefully). To make it work I have to remember to remove listener every time I press 'pause/stop' buttons and then reattach it afterwards.
Hope that helps someone.

Objective C (iPhone) Strange Behaviour with musicPlayer API

I'm developing a music app for iPhone that uses the built in iPod library. I noticed a strange behaviour that I was able to replicate in Apple's sample code entitled "AddMusic" simply by NSLogging out what was going on.
My question is:
Has anyone else encountered this, or better yet found a solution?
The behaviour is:
With the musicPlayer API, one is able to get notifications on state changes of the iPhone's built in iPod. For example, when a song is played or paused, it can shoot off a notification.
You can also queue up songs to be played by invoking a mediaPicker which accesses the music library.
The problem occurs while the API is switching the song from the currently playing one to the new song, which was cued up.
What I noticed is that, in both Apple's sample code and my code, the player state change notification is fired 5 or 6 times, seemingly at random. A sample NSLog is as follows:
2013-08-27 17:24:14.676 AddMusic[418:60b] Paused
2013-08-27 17:24:14.937 AddMusic[418:60b] Playing
2013-08-27 17:24:14.943 AddMusic[418:60b] Paused
2013-08-27 17:24:14.950 AddMusic[418:60b] Playing
2013-08-27 17:24:15.842 AddMusic[418:60b] Paused
2013-08-27 17:24:15.853 AddMusic[418:60b] Playing
I am using X-Code DP6 and iOS 7 B6, but I don't think this is an NDA issue since these commands are old. Just thought I'd provide this information in case this is a new problem.
Thanks!

iPod mini controls disabled when certain audio session parameters are set

I'm working on a music visualizer for the iPhone/iPad, under iOS 3 you could double-tap the home button and get iPod controls. With the latest version 4.1-4.2, these controls are now grayed out when the home button is pressed. I found a similar complaint at http://openradar.appspot.com/8696944, although there wasn't a solution.
I have the base sound category set to kAudioSessionCategory_PlayAndRecord, with kAudioSessionProperty_OverrideCategoryMixWithOthers set to true. (Just to add more fun to the problem I'm using OpenAL for some sound effects.)
I have tried setting the category back to ambient when the application goes into the background. but either it happens too late or it's not sufficient.
Here's where I've got to so far:
AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
devicetwo = alcOpenDevice(NULL);
contexttwo = alcCreateContext(devicetwo, 0);
//The following two lines are the lines that gray out iPod controls:
alcMakeContextCurrent(contexttwo);
AudioSessionSetActive(YES);
The iPod controls remain grayed out even once the app quits... And removing the two culprit lines of code result in no sound being produced in the app.
Well I've given up.. I'm now coding my own UI based off of the AddMusic example code
http://developer.apple.com/library/ios/#samplecode/AddMusic/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40008845-Intro-DontLinkElementID_2
I'm happy to report that play and stop via the MPMusicPlayerController doesn't seem to conflict with the play and record session settings. And building your own play/pause/FF seems to be fairly straightforward
p.s. I've also discovered that this Music Visualizer app: http://itunes.apple.com/us/app/music-visualizer/id337651694?mt=8 is just this addMusic sample uploaded and this guy is charging 2 bucks for it.. It's got awful reviews.. but it still seems wrong that it's on the app store.
My iPod touch 4G is running iOS 4.2, and it doesn't have this problem. I would attempt to contact Apple.

Audioservices volume issue on 4th gen. iPod touch

I am currently developing a game for iPhone/iPod touch. For short sounds I am using the AudioServicesPlaySystemSound function. I know that I can't control the volume of these sounds programmatically, but on my iPod touch 3rd gen these sounds respect the overall sound volume. On my new iPod touch 4th gen, these sounds are always played at the same volume, no matter to which value the overall volume is set. They even play if the volume is turned down to 0. The AVAudioPlayer on the other hand works as expected. Both devices are upgraded to iOS 4.1.
Has anyone else noticed this? Any suggestions what's happening here?
Just in case someone has the same issue / is interested: If you have an AVAudioPlayer playing at the same time, this problem goes away, that means, the systemsounds behave correctly again. In my case I play an empty mp3 in an infinite loop now. Not the nicest solution but one that works.
Has anyone else noticed this?
Yes, also for AudioServicesPlaySystemSound. It happens on my iPod touch 4G, but not my iPhone 3G. Both also running iOS4.1.
I've no idea what's happening, but I'll offer a bounty try to get some helpful uberguru's attention. If not, 1 infinite loop it is.
Update: apparently the problem also happens with AVAudioPlayer on the iPod 4th Gen - see https://devforums.apple.com/message/333169
It looks like it might be a bug. We'll see...