Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sound issue: plateform discrepancy

Author
Message
TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 21st Apr 2014 13:00
Hello guys.

Since the stopsound function didn't work everytime to stop a looping sound, I made a looping function with a very short sound file. Something like that:

if getsoundinstances(sound_a) = 0
playsound(sound_a)
endif

Here's my issue: on PC, the looping is not slower than with the loop mode of playsound, but it is reliable. This is no big deal, I shortened the sound file to make it smoother.

But when playing on android through the player, the app repeats the sound file WAY faster, I believe it loops as fast as the loop mode of the playsound function. However it is not reliable at all: after 30 or 40 seconds, it stops playing the sound. Besides, when this sound is called later in the game, it doesn't play at all. As if the sound file was unloaded (which is not, I never unload sound file).

Any useful input to solve this mystery?
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 21st Apr 2014 13:30
Make sure that your loop checks the sound is NOT playing before playing it again. You may be exceeding the number of simultaneous sounds allowed - this is unlimited on the PC but probably 8,16 or 32 on mobiles.

-- Jim - When is there going to be a release?
TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 21st Apr 2014 20:17 Edited at: 22nd Apr 2014 12:07
I think I got part of the problem.

At the beginning of the program I play every sound (45) at once to preload them and getsoundinstance(sound_a) returned -1.

I removed the preloading code and now the sound finally loops using getsoundinstances.

However the loop on android is choppy. The delay between replays is not constant. I'll try something else.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st Apr 2014 20:19
It's due to sync rate differences.
Don't use code like that in a loop.
You should use PlaySound with the loop parameter set. It will ensure that the sound is played through before starting again. Either that or set a timer on the sound in the loop for the length of the track before you start it again.

On that note, I've also noticed some weird things with looped sounds on Android. Sometimes GetSoundsPlaying will return 0 although the sound is looping. I'm thinking what is happening is that the check is happening right in between two loops. I added in some extra checks and it seems better, but it is so intermittent that it is very hard to tell.

TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 21st Apr 2014 22:40 Edited at: 21st Apr 2014 22:42
I tried to make a loop using my internal timer and this custom made loop works as intended in the main menu. But the second time I call this function, in the scripted intro, it doesn't work on android while it works on PC.

On android I checked if the sound is playing in the scripted intro and getsoundsplaying returns -1. Why is it returning -1? It's supposed to return the number of instance of this sound playing. So why -1?
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st Apr 2014 22:46
That's interesting!
So really that's a bad return from that function. I think that should be brought to Paul's attention and if it is necessary then the documentation needs to be updated.
So that could be the reason I was having issues too.
I was getting 2 instances of a loop sometimes and I was checking if GetSoundsPlaying = 0.
So if it was actually coming back -1 then it was probably starting the sound up. But what does that -1 mean? Very odd.
If you can get a stable example of it can you check it with Paul so we can find out what to do with it?

TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 22nd Apr 2014 12:05 Edited at: 22nd Apr 2014 14:41
Yesterday I checked a random sound with getsoundsplaying in the main menu and it was returning -1 as well. It would be easier to reproduce so I'll check it first.

I get random freeze when playing sounds as well but it might be a memory issue. My image folder was 686ko big, and my sound folder is 15.2Mo big so the memory footprint of my game might have gone out of control. I'll lower it first before reporting about random freezes.

edit:
I tried my function on 3 android devices.
On PC, getsoundsplaying returns 1 as expected and the sound is playing.
On Defy (android), it returns -1 (sound not playing).
On Huawei Honor, it returns 0 (sound not playing).
On nexus 10, it alternatively returns -1, 0 then 1 (sound playing).
TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 22nd Apr 2014 15:33 Edited at: 22nd Apr 2014 16:05
There's definitely something wrong with the getsoundsplaying function.

I went back to using the built in loop function:

playsound(sound_a, 100, 1, 0)

I tried to stop it with:

stopsound(sound_a)

On PC it works as expected. On a nexus 10, the sound keeps playing 10% of the time.

So i tried to stop it using this code:

repeat
stopsound(son_nuageboucle)
until getsoundsplaying(son_nuageboucle) < 1

On a nexus 10, the sound keeps playing 10% of the time as well so I believe agk doesn't register well which sound is playing.

Another issue. My program plays a lot of sounds one after another (around 400 in a level). There's never more than 4 sounds playing at the same time and after a while the nexus 10 freezes when playing a sound. This might be device related as it hasn't happened on the huawei honor, for instance.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 22nd Apr 2014 19:13
This should definitely be reported to Paul. Please do so and hopefully we'll get a patch. I moved mine to a time based stop and don't use GetSoundPlaying/GetSoundInstances and so far so good. But I don't play many sounds at once nor do I have a lot of sounds loaded (maybe a dozen).

So I do this:
//start sound
PlaySound(A)
aTime# = timer()

//to stop the sound
if GetSoundExists(A) = 1 and timer() - aTime# > soundA_duration#
StopSound(A)
endif

It might be calling StopSound too often, but it seems to be OK.

TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 22nd Apr 2014 23:41
Do you mean that I need to stop my sounds manually after I played them? I thought they were stopped automatically at the end of the file.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 22nd Apr 2014 23:51
Sorry, no, just looping sounds.

TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 23rd Apr 2014 11:45 Edited at: 23rd Apr 2014 13:01
Oh! I see! My bad!

So after a short delay, you tell the app to try to stop the sound every frame if it still exists. I guess I could delete the sound after the scripted sequence and reload it later. I'll think about it.

edit: I made a short program to create a looped sound with getsoundinstances and see if I could have it return -1. Unfortunately I couldn't reproduce it. There must be some interference with another function from my loading sequence. Strange fact though: in the same amount of time, my defy played the sound file 1250 times while my nexus 10 played it 1000 times. I know there are sync differences, but it is quite a huge difference, considering the fact that the nexus is supposed to compute way faster than my aging phone.

Anyway, I'll keep searching for a while unless I find a satisfying workaround.
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 23rd Apr 2014 20:02
Quote: "my defy played the sound file 1250 times while my nexus 10 played it 1000 times. "

That's really odd, but could be sync descrepancy. I'd be curious to know how many times it was supposed to play (i.e. number of program loops vs. sound loops)

I don't delete the sound at all I just let it keep stopping it and use a timer variable to stop stopping it.
So you could do this:
timerNow# = timer()

//stopping the sound
dTime# = timeNow# - soundTime#
abitraryRetryStopSeconds# = 2.0
if dTime# > soundDuration# and dTime# < soundDuration# + abitraryRetryStopSeconds#
if GetSoundExists(soundA) = 1
StopSound(soundA)
endif
endif


Then when you play the sound just make sure to set it's soundTime# variable to when it was initiated. You could also get more fancy and make a type for your sound objects that has variables for the start time, duration, if it is playing, how many times it has been stopped, etc. Make it global and then just make your own PlaySound function and StopSound function to wrap it up neatly.

However, this is a convoluted system and StopSound or GetSoundsPlaying needs to be more reliable.

Login to post a reply

Server time is: 2024-11-25 04:30:48
Your offset time is: 2024-11-25 04:30:48