Game Development Community

Pausing audio

by Mark Davies · in iTorque 2D · 06/01/2010 (7:26 pm) · 10 replies

Hi all,

I'm working on adding a scripted sequence of events that happens towards the end of one of my levels. This sequence includes some animations and sound effects that needs to be synchronised. The synchronisation is achieved using timers, and some scheduled events.

Everything works great except for when I pause my game. I'm using pauseScene(), unpauseScene(), and $timescale = 0/1, to do the pausing, and these do pause everything except for any non-looping audio section that is playing at the time I press pause. This means that, when I un-pause, my scripted events are then out of synch with my audio effects.

Are there any audio commands I can use to pause the audio tracks, and then re-enable them when I un-pause? Or, will I have to make changes to the engine? I found an old link, and some code is provided for doing exactly what I want, but I'm wondering if this fix will work for iTGB? Here is the link:

http://www.torquepowered.com/community/resource/view/9385/

Thanks,
Mark

#1
06/01/2010 (9:19 pm)
Just letting you know, I decided to go ahead and implement those changes as described in the attached link, and it works perfectly! :).

I just had to remove some code from audioBuffer.cc that refers to OGG files that aren't supported on this platform. Apart from that, the solution works as advertised.
#2
06/02/2010 (12:57 am)
Pretty cool resource! I just cheated and removed the pause button from stuff that I felt was too complicated to orchestrate a pause ;-)
#3
06/02/2010 (3:40 pm)
Yep, the audio pause fix works perfectly. I have one particular scene where I have a ton of stuff going on with timers and scheduled events and several different animations that have to be synchronised with several different sound effects. Everything was going great until I decided to pause, and then everything fell apart and I had to do a major rethink. At that point I was only using pauseScene() and unpauseScene(), so all of my audio effects and scheduled events were still running in the background.

The solutions are pretty simple, once you know how, but I spent a few hours searching the forums. The audio pause solution goes back to 2005, so it's surprising that we still have this issue with the engine.
#4
06/03/2010 (11:42 pm)
Just letting you guys know. I've tried the audio fix on all three platforms (TGBGame for Win desktop, Mac desktop, and the actual device), and I get different results in all three cases:

1) TGBGame for Windows:
Appears to work with no issues

2) TGBGame for the Mac:
It solves the static sound problem that I've experienced since day 1, but the game experiences periodic slow downs (really slow, like slow motion).

3) iPhone sim and device:
The code won't even compile without errors.

I don't mind if it doesn't work, but different behaviour on the different platforms is starting to get old. I feel as though my creativity is stifled by poor quality software and lack of support.

Looks like I'll have to implement your solution where the pause button gets hidden. What started out as an interesting adventure is turning into a pain in the ass. I'm just looking forward to completing this game so I can move on.
#5
06/04/2010 (1:15 am)
Sorry to hear that Mark :( You must be getting close though? Any chance of of an upcomming video or some screen shots - I'm really keen to see what you've come up with.
#6
06/04/2010 (2:27 pm)
Hi Scott, yeah I think I'm getting fairly close to the point where I can release something fairly soon. I'd like to make a start on the marketing side of things, so perhaps I can release a preview video or something like that.
#7
06/04/2010 (4:18 pm)
Quote:I don't mind if it doesn't work, but different behaviour on the different platforms is starting to get old. I feel as though my creativity is stifled by poor quality software and lack of support.

I kind of understand that.
I would prefer if GG / LUMA would focus on the platform thats important (iPhone / Simulator) with secondary focus on the related OS (OSX) and drop windows thats of no use for iPhone development anyway.
#8
06/04/2010 (4:40 pm)
Marc, I agree. It's nice to have the TGBGame in Windows and OSX, and I use those because they are available and convenient to use. But, if they are available to be used, people expect them to work and it wastes a lot of time when weird bugs are discovered that are not consistent across all of the different platforms. At the end of the day, if they don't work properly, and GG don't have the resources to fix the bugs, they'd be better off dropping them and focussing on just one thing.



#9
06/18/2010 (11:37 pm)
Hi all,

I'm just wondering if anyone has had any success in implementing this audio pause fix? I'm going to have another go at it, becauase I think it should work as I don't see anything obviously different in TGB compared to iTGB that should prevent it from working. But, before I attempt it, if anyone has already got it working then please let me know,

I will post a solution if I find one.

Thanks,
Mark
#10
10/18/2010 (9:21 pm)
Hi All,

Just letting you know that I've ported the audio fix to the iPhone and it's working correctly now. I just had to make a couple of minor changes to the original code. Here is a quick description of the changes required:

1) Download the files from the link found in the original forum post
http://www.torquepowered.com/community/resource/view/9385/

2) Remove these files, as they are not used on the iPhone (no OGG support):
oggMixedStreamSource.h
oggMixedStreamSource.cc
vorbisStreamSource.h
vorbisStreamSource.cc

3) Modify audio.cc
a)
Replace line 2480:
mDevice = (ALCdevice *)alcOpenDevice((ALubyte*)NULL);
with this:
mDevice = (ALCdevice *)alcOpenDevice((const ALChar*)NULL);

4) Modify audioBuffer.cc
Remove any code that gets included #ifndef TORQUE_NO_OGGVORBIS

a)
Remove this code:
#ifndef TORQUE_NO_OGGVORBIS
#include "vorbis/codec.h"
#endif

b) Remove this code:
Class method AudioBuffer::readOgg()
Class method AudioBuffer::oggRead()