ObjectAL sounds sometimes stop playing

1,333 views
Skip to first unread message

Wayne

unread,
Jan 1, 2013, 10:10:07 PM1/1/13
to objectal-...@googlegroups.com

Hi All,

I'm using ObjectAL to play sounds using both OALSimpleAudio for some files, and some using OALAudioFile with a source and buffer. This all works great , but once in a rare occasion both OALSimpleAudio and OALAudioFile files will not play any sounds. It seems to happen if I minimize the app, and then open it. I haven't seen it happen when the app is first loaded.

This happens while testing on an actual iPad2 device with iOS 6.0, without being connected to the Mac/Xcode.

It seems similar to an issue I've seen a number of posts for about CocosDension. I'm not using CocosDension in the app at all, and no references to it.

I did manage to narrow down where the issue is, and a reliable way to repeat the problem.

1) Run my app, even using the debugger with an actual iPad, and then minimize the app. All works fine.
2) With my app minimized, open another audio app such as "AudioMemos" ( random free audio app I downloaded )
3) Now minimize "AudioMemos" and open my app again. All looks OK and no errors. But if I try to play one sound even just using OALSimpleAudio, I get no sound and the following errors from ALSource.m:

OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)
MyApp[9515:907] OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.


I get the above errors 7 times in a row for each time I try to play one sound.

If I use the purgesharedinstance I can get the audio to come back when the app enters foreground, but I get a lot of error messages during the process, and it sometimes breaks the recorder I have in my app. So it's not a solution, but maybe a clue.

When I trace it down, it seems to be something with the code in ALSource.m as below.

- (bool) interrupted
{
	return NO;        // comes here when app back from minimized
}

- (void) setInterrupted:(bool) value
{
#pragma unused(value)
    // Suspending on interrupt fails in iOS 6+ and doesn't seem to be needed anyway

}

- (bool) suspended
{
	return suspendHandler.suspended;
}

- (void) setSuspended:(bool) value
{
	if(value)
	{
		shadowState = self.state;
		if(AL_PLAYING == shadowState)
		{
			[ALWrapper sourcePause:sourceId];
		}
	}
	else
	{
		// The shadow state holds the state we had when suspending.
		if(AL_PLAYING == shadowState)
		{
			// Because Apple's OpenAL implementation can't stack commands (it defers processing
			// to a later sequence point), we have to delay resuming playback.
			abortPlaybackResume = NO;
			[self performSelector:@selector(delayedResumePlayback) withObject:nil afterDelay:0.03];
		}
	}
}

- (void) delayedResumePlayback
{
	if(!abortPlaybackResume)
	{
		[ALWrapper sourcePlay:sourceId];
	}
}







Karl Stenerud

unread,
Jan 1, 2013, 11:44:24 PM1/1/13
to objectal-...@googlegroups.com
Hi Wayne,

Can you try setting the logger to log debug messages? You can do so either by setting OBJECTAL_CFG_LOG_LEVEL=LEVEL_DEBUG in the preprocessor macros or just change it at the bottom of ObjectALConfig.h.

My first guess would be that the app isn't getting an end interrupt notification from the OS, so you'll probably see something like:

DEBUG: -[OALAudioSession setSuspended:]: setSuspended 0

but no corresponding setSuspended 1.

If that's what's happening, you can add the following call to your app delegate's applicationDidBecomeActive and applicationWillEnterForeground methods:

[[OALAudioSession sharedSession] forceEndInterruption];


But regardless, please post the log.


Cheers!

Karl

Wayne

unread,
Jan 2, 2013, 5:47:39 PM1/2/13
to objectal-...@googlegroups.com
Hi Karl,

Happy New Year ! , and thanks for your help. I added "[[OALAudioSession sharedInstance] forceEndInterruption];" to the AppDelegate as you mentioned and it works great now ! Thanks!

I also made a copy of the log as below that you asked for. I edited out the date and app name to make it smaller. I started my app, then minimized it, no errors, then switched to that "AudioMemos" app ( not my app, just a random app I tried to test with ). The errors at the bottom are from when I pressed a key once after opening my app again ( should have played one sound, but didn't play ).

17:28:25.189  -[CCDirector init] : cocos2d: cocos2d v1.1.0-RC0

17:28:25.195  -[CCDirector init] : cocos2d: Using Director Type:CCDirectorDisplayLink

17:28:26.503  -[CCConfiguration init] : cocos2d: OS version: 6.0 (0x0x6000000)

17:28:26.514  -[CCConfiguration init] : cocos2d: GL_VENDOR:   Imagination Technologies

17:28:26.516  -[CCConfiguration init] : cocos2d: GL_RENDERER: PowerVR SGX 543

17:28:26.518  -[CCConfiguration init] : cocos2d: GL_VERSION:  OpenGL ES-CM 1.1 IMGSGX543-73.16

17:28:26.520  -[CCConfiguration init] : cocos2d: GL_MAX_TEXTURE_SIZE: 4096

17:28:26.522  -[CCConfiguration init] : cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16

17:28:26.523  -[CCConfiguration init] : cocos2d: GL_MAX_SAMPLES: 4

17:28:26.525  -[CCConfiguration init] : cocos2d: GL supports PVRTC: YES

17:28:26.526  -[CCConfiguration init] : cocos2d: GL supports BGRA8888 textures: YES

17:28:26.528  -[CCConfiguration init] : cocos2d: GL supports NPOT textures: YES

17:28:26.529  -[CCConfiguration init] : cocos2d: GL supports discard_framebuffer: YES

17:28:26.531  -[CCConfiguration init] : cocos2d: compiled with NPOT support: NO

17:28:26.532  -[CCConfiguration init] : cocos2d: compiled with VBO support in TextureAtlas : YES

17:28:26.533  -[CCConfiguration init] : cocos2d: compiled with Affine Matrix transformation in CCNode : YES

17:28:26.535  -[CCConfiguration init] : cocos2d: compiled with Profiling Support: NO

17:28:26.994  -[AppDelegate applicationDidFinishLaunching:] : Retina Display Not supported

17:28:27.007  -[ES1Renderer resizeFromLayer:] : cocos2d: surface size: 1024x768

17:28:27.022  Memory Capacity of 14165 MiB with 5422 MiB Free memory available.

AudioStreamBasicDescription:  2 ch,  44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved

17:28:27.728  -[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 1

17:28:27.733  record processing begin

17:28:28.004  record file path set up finished

17:28:28.329  recorder allocated assigned to path

17:28:28.352  Recording initiated

17:28:32.434  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_background.png

17:28:32.439  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_title.png

17:28:32.440  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_mics.png

17:28:40.117  -[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 15

17:29:05.758  record processing begin

17:29:05.867  record file path set up finished

17:29:05.878  recorder allocated assigned to path

17:29:06.078  Recording initiated

17:29:06.080  -[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 15

17:29:06.085  -[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 1

17:29:10.254  OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)

17:29:10.257  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:10.259  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:10.261  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:10.262  OAL Error: +[ALWrapper sourcef:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:10.264  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:10.266  OAL Error: +[ALWrapper sourcef:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:10.268  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:10.269  OAL Error: +[ALWrapper source3f:parameter:v1:v2:v3:]: Invalid Value (error code 0x0000a003)

17:29:10.270  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:10.272  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:10.273  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:10.275  OAL Error: +[ALWrapper sourcePlay:]: Invalid Value (error code 0x0000a003)

17:29:10.276  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:10.853  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_quickset_background.png

17:29:10.857  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_multi-task_rec-on.png

17:29:10.859  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_detailedset-active.png

17:29:10.861  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_instant_replay.png

17:29:10.863  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_repeat_button-off.png

17:29:10.865  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_savedrecordings-active.png

17:29:10.866  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_settings.png

17:29:10.868  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_quickset-active.png

17:29:10.870  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_instant_replay-active.png

17:29:10.872  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_record_light-off.png

17:29:10.874  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_detailedset.png

17:29:10.875  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_quickset-button.png

17:29:10.877  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_recording_savedrecordings.png

17:29:10.879  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V1_ear.png

17:29:10.880  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_repeat_button-on.png

17:29:10.882  -[CCTextureCache removeUnusedTextures] : cocos2d: CCTextureCache: removing unused texture: V2_multi-task_rec-off.png

17:29:12.627  OAL Error: +[ALWrapper genSources:numSources:]: Invalid Operation (error code 0x0000a004)

17:29:12.629  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.631  OAL Error: +[ALWrapper getSourcef:parameter:]: Invalid Value (error code 0x0000a003)

17:29:12.633  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.730  OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)

17:29:12.732  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.734  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:12.736  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.737  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:12.739  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.742  OAL Error: +[ALWrapper sourcePlay:]: Invalid Value (error code 0x0000a003)

17:29:12.743  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.745  OAL Error: +[ALWrapper genSources:numSources:]: Invalid Operation (error code 0x0000a004)

17:29:12.746  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.748  OAL Error: +[ALWrapper getSourcef:parameter:]: Invalid Value (error code 0x0000a003)

17:29:12.750  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.751  OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)

17:29:12.753  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.754  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:12.756  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.757  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:12.759  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.761  OAL Error: +[ALWrapper sourcePlay:]: Invalid Value (error code 0x0000a003)

17:29:12.762  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.764  OAL Error: +[ALWrapper genSources:numSources:]: Invalid Operation (error code 0x0000a004)

17:29:12.765  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.767  OAL Error: +[ALWrapper getSourcef:parameter:]: Invalid Value (error code 0x0000a003)

17:29:12.768  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.770  OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)

17:29:12.771  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.773  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:12.774  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.776  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:12.777  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:12.779  OAL Error: +[ALWrapper sourcePlay:]: Invalid Value (error code 0x0000a003)

17:29:12.781  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.898  OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)

17:29:20.901  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.904  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:20.905  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.907  OAL Error: +[ALWrapper deleteSources:numSources:]: Invalid Operation (error code 0x0000a004)

17:29:20.908  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.910  OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)

17:29:20.911  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.913  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:20.916  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.917  OAL Error: +[ALWrapper deleteSources:numSources:]: Invalid Operation (error code 0x0000a004)

17:29:20.919  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.920  OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)

17:29:20.922  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.923  OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)

17:29:20.925  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.

17:29:20.926  OAL Error: +[ALWrapper deleteSources:numSources:]: Invalid Operation (error code 0x0000a004)

17:29:20.929  OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.


electro

unread,
Jan 8, 2013, 9:35:40 AM1/8/13
to objectal-...@googlegroups.com
I am experiencing the same issue in my game, where I am primarily using OALSimpleAudio to play sound effects via the playEffect: method.

The forceEndInterruption: workaround does indeed solve the problem, however I have managed to reproduce it using the ObjectAL Demo iOS app. Here are my steps to reproduce:
  1. In the ObjectALDemo app, select the "Audio Sessions" demo
  2. Uncheck "Allow iPod"
  3. Under the "ALSource" heading, press "Play/Stop"
  4. Double-click the physical home button on the device, and play some music from the quick app switcher thing. Pause it after a few seconds, then return to the ObjectAL demo app. The console now says: 
    OAL Debug: -[OALAudioSession handleInterruption:]: iOS 6+ interrupt type 1
    OAL Debug: -[OALAudioSession beginInterruption]: Received interrupt from system.
    OAL Debug: -[OALAudioSession setSuspended:]: setSuspended 1
    OAL Debug: -[OALAudioSession setAudioSessionActive:]: Deactivate audio session

  1. Return to the app, and press the same "Play/Stop" button again. You'll notice it stopped working, the "Suspended" checkbox/light comes on, and it can't seem to be coerced into working again. Every time you press the Play button, the console says:
  1. OAL Error: +[ALWrapper sourceStop:]: Invalid Value (error code 0x0000a003)
  1. OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.
  1. OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)
  1. OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.
  1. OAL Error: +[ALWrapper sourcei:parameter:value:]: Invalid Value (error code 0x0000a003)
  1. OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.
  1. OAL Error: +[ALWrapper sourcePlay:]: Invalid Value (error code 0x0000a003)
  1. OAL Warning: -[OALAudioSession onAudioError:]: Received audio error notification, but session is suspended. Doing nothing.
These steps were performed on iOS 6.0.1 (iPhone 4S) using ObjectALDemo in Debug configuration (git hash 3c017aab46c59397f8f6e49d8ee60ef5c9a364e4)


...and while I'm at it, a big "Thank You!" for sharing this project!

Timothy Scott

unread,
Jan 14, 2013, 12:45:18 PM1/14/13
to objectal-...@googlegroups.com
I've run into this problem as well.  I implemented the forceEndInterruption() workaround and it works MUCH better, but the fix is not 100%.  I'll still sometimes lose sound after switching between my apps that employ ObjectAL.  When the problem occurs, I can get sound going again if I dismiss my app and then bring it back up.  It doesn't do a full relaunch, but sound does come back for me (at least, it has so far).

Thanks,
--tim

Apostoli

unread,
Jan 15, 2016, 12:25:07 PM1/15/16
to ObjectAL-for-iPhone
Karl,

First and foremost:
A huge thank you for what you have done with ObjectAL. Without it, my project would have been miles harder to complete.

Regarding the fix using forceEndInterruption, it works great for me but here is one issue I have not been able to resolve:

I have set my UIBackgroundModes to include playing audio, so the audio always continues playing if I leave the app.
If there is an interruption, upon returning to my app the sound resumes, thanks to your suggested forceEndInterruption fix.
However, if I EXIT the app again the sound does not play in the background anymore.
This only applies to the source that was already playing at the time of the interruption.
If another source starts playing after the interruption, it will continue to play when the app is in the background.

How can I ensure that the interrupted sound will keep playing in the background after calling forceEndInterruption?

I don't know if this helps you at all but I am using ALChannelSource instances to play ALBuffer's. 

Thank you in advance,

Apostoli 
Reply all
Reply to author
Forward
0 new messages