PDA

View Full Version : GFX and MSX synchro and sleep support



AxeD
01-11-2012, 03:53 PM
Hi,
I need to save some space in APK, so I decided to remove video with screens + Voice over in ogg file. All is working , but when I switch between tasks, and go back audio and screens are out of sync. For this I'm using:

pEnt = CreateTextLabelEntity( _StoryFrame, caption, GetScreenSizeXf() / 2.0f, GetScreenSizeYf() * 0.85f, caption );
SetAlignmentEntity( pEnt, ALIGNMENT_CENTER );
pEnt->GetVar( "scale2d" )->Set( CL_Vec2f( GetScreenSizeYf() / 250.0f, GetScreenSizeYf() / 250.0f ) );

FadeInEntity( pEnt, true, 300, startTime );
FadeOutAndKillEntity( pEnt, true, 300, endTime - 300 );

Any visible issues ?

-AxeD

Seth
01-11-2012, 09:12 PM
Hmm... which part is wrong, the video timing or the audio timing?

For video:

Unless you've set GetApp()->SetGameTickPause(true), the default timer used for those fades will be the gametimer, which should perfectly pause when the app is suspended and resume when the app is restored, even in mid-fade, etc.

For audio:

Well, AudioManagerAndroid.cpp is pretty basic, it basically doesn't do anything when you suspend and resume, so you need to stop/restart your ogg yourself in App::OnEnterBackground() and App::OnEnterForeground. (These are virtuals that can be overidden from BaseApp)

For music/oggs, GetPos() and SetPos() is supported in the proton android audio manager, so you could move to the exact place you need to, but you currently have to do it yourself.

Something like this in OnEnterBackground:


uint32 m_savedPosition = GetAudioManager()->GetPos((GetAudioManager->GetLastMusicID());
string m_savedMusic = GetAudioManager()->GetLastMusicFileName();
GetAudioManager()->StopMusic();

in OnEnterForeground:


GetAudioManager()->Play(m_savedMusic, false, true);

//move to the exact point we stopped
GetAudioManager()->SetPos((GetAudioManager->GetLastMusicID(), m_savedPosition);

I should probably set that to happen automatically when the task is switched on Android, I do that with some of the other audio managers but it's only recently I added the GetPos/SetPos support to the Android audio manager.

AxeD
01-12-2012, 07:32 PM
Hi Seth,
I had such implementation in my code... but this did't done the trick. Looks like sound is 'saved' in correct way but game timer jumps approx 1 second ahead... and I just noticed Audio heap overflow :/


Best
-AxeD

Seth
01-12-2012, 10:29 PM
Hmm... not sure. To diagnose the problem you should probably pepper things with LogMsg("GameTimer is currently %u", GetApp()->GetGameTick());

I could see losing some time due to texture loading upon returning to the game, but the maximum delta allowed for a gametick is 100 ms, and it sounds like you're losing 10x that.

You could also just save the tick yourself, and set it when you come back: GetApp()->SetGameTick(m_mySavedTick);


and I just noticed Audio heap overflow :/

Note: Sfx (if not played as "music", which streams) on audio must be < 1 mb (after decompression) decompressed. Limitation of Android's SoundPool class.

AxeD
01-12-2012, 10:54 PM
Hi Seth,
hmm.. it is strange - only music is played as stream (double checked), then on_single click is able to play once, on second attempt I have this overflow info

AudioFlinger could not create track, status: -12


-AxeD

Seth
01-12-2012, 11:09 PM
Hmm, does same problem happen when playing music from the RTSimpleApp example? (from the debug menu in it) If not, maybe try putting your .ogg in that example, if it then causes problems we'd know it had to do with the length or format of the .ogg maybe.

AxeD
01-12-2012, 11:12 PM
Can You tell me that format do You use ? From latest test- I turned off music and only 2 files are preloaded, when I try to use one of them twice I have:

AudioFlinger could not create track, status: -12
and
no more names available

But there are only 2 files preloaded (click x 2)
-AxeD

Seth
01-13-2012, 12:33 PM
I use standard .wavs for the sfx, and .ogg's for the music. (music can be a few megs in size, never had a problem) I think in Dink I use oggs for both.. I load 80+ sounds at once in some of my games so there is no reason it shoudn't be able to handle what you're doing. I've used different kinds of ogg compression.

Try taking some .wavs/oggs from RTSimpleApp I guess and see if there is still a problem. If that fixes it, you might want to try a different sound editor. I use Sound Forge.

AxeD
01-13-2012, 03:44 PM
Hi,
so I just changed size of sfx and it looks better, but when I'm starting next music I have again that overflow info :/ And I checked this with Your msx.... and I have this same !

-AxeD

Seth
01-13-2012, 10:38 PM
Hmm, how can I reproduce the problem? Is there any way to get RTSimpleApp to show the same problem?

AxeD
01-14-2012, 01:30 AM
I just went through all devices I could have and it looks like two of my devices are corrupted (?). I check that code on two others and it looks like all is working just fine....

Thank You for Your help!