Android - repeated small sound

Previous topic - Next topic

erico

Hi guys,
here is the thing:

I´m tunning sound on my game, it all works fine on PC and MAC so far.
On Caanoo, I had a problem when the same sound gets called more then once without finishing playing first.
So I reduced the length of the sound file and placed a timer to make sure it is done before requiring to play again.
Works fine on caanoo now.

It is a ´steps / walking´ sound, very short one, and while the player is walking it must be called consecutively.

Problem is that none solution worked on android, the sound gets played on a weird out of rhythm way,
fps is fine and stable at 60, I tried to allocate more channels to it but no good, I tried spacing the calls a bit more, but no good.
I tried the SOUNDPLAYING() command but after a while it returns -1 instead of 0 or 1.

I don´t know what else to try, maybe doing a more lengthy sound comprising, lets say, 2 or 4 steps and spacing out the calls?
Any idea on what I´m missing here?

Android is really crazy, and while on the subject, when players walk on rain, I´m plotting a splash sprite on their feet. Strangely, it shows one wrong frame from another sprite instead, something that dosen´t happen on all other platforms. I must be going cucu :S

While the sprite problem seems like an easy thing to figure out, the sound is not.
Thanks for any help on this front.

I can let loose of this sound/feature, but it does add to the experience.

EDIT: best rename the topic and add a little code example...
Code (glbasic) Select
// PLAYER SOUND TIMER
pts=pts+1
IF pts=8 THEN pts=0

// PLAYER
IF ps=1
IF pts=5
IF lama=0 THEN PLAYSOUND (0,0,.5)
IF lama>0 THEN PLAYSOUND (1,0,.5)
ENDIF
ENDIF


So PTS is the timer I´m using, while PS at 1 means walking. LAMA is when the floor is wet and I´m using a different walking sound for that. Strange that it now works nice on all platforms but android. I´m thinking it must be something related to calling really small sounds repeatedly.

fivesprites

#1
Unfortunately, all platforms use a different sound API so it's not so easy to compare one with another.

I ran into a similar problem with Android and it took a while to figure out properly.  I'm away from my development PC at the moment so can only recall from memory!...

Small sounds - if you have one that repeats, try to make it a longer sample if possible (a few footsteps in one sample rather than one).  Also, keep your sounds in a low bitrate, mono format (mono, 16bit pcm, 22.5khz).  Having a few buffers also helps.  I also find that OGG format plays better.

There's an issue with ISSOUNDPLAYING.  If the call to PLAYSOUND returns -1 (quite possible with hammering the sound engine with lots of play requests) then performing ISSOUNDPLAYING with a channel id of -1 will cause an error (something like -7 - out of memory). 

To check for this error, print out the last error message in GLB:

STDERR "LAST ERROR: " + GETLASTERROR$() + "\n"

Do that after PLAYSOUND and again after ISSOUNDPLAYING.


You have to check that the channel id from PLAYSOUND is valid before calling ISSOUNDPLAYING.

Repeatedly calling PLAYSOUND can also lead to the channel id being returned as -1.

It's probably a good idea to take a look at the Android log file whilst running your game - you should be able to see if the sound engine is farting or not.  Note: Don't use _Logview.bat to view the logs as this only shows GLBasic specific log output - you need to see everything!

Instead, in a command tool, cd to:

C:\Program Files (x86)\GLBasic_v11\Compiler\platform\android\android-sdk-windows\platform-tools

and then run:

adb shell logcat

//Andy

erico

Thanks Andy,

I will will give a go on the longer sample idea.
Never tried ogg, but I heard they are better, I will try to stick with wav for this one project.
They are all mono, 16b but 48 khz.
I did try reducing to 22.5khz before but the same thing happened.

It must be the short sample...let me give a try.
Tks!

erico

#3
Tried longer sample but didn´t work.
Even spacing the sound a lot more on the timer it still plays out of the supposed fixed rhythm.

Maybe ogg could do the trick? Will give a go on that now.

EDIT: ogg didn´t work either, same results. I also tried adding some silence to the start and end of the sound file but no good. Could it be my version of java (7)? I will install the v6 as that is the recommended one...

Wampus

You could try this: http://www.glbasic.com/forum/index.php?topic=9023.0

It doesn't use SOUNDPLAYING. Instead it reads the length of the sound from the WAV file and times how long until it needs to repeat by reading GETTIMERALL(). It should fix the problem. If it doesn't then something unusual is happening, like sound being played back at a different rate.

erico

I got java back into v6, but no good...I hope at least that is fine on the signing part.

Oh well, I guess it is either try Wampus´ SSSS or leave that kind of sound off the app.
Altough I think the routine done is great, I was waiting to try out on next game...didn´t want to get things too complex on my side.

My plan is to use the routine only on the repeated sounds and leave the rest as it is.

I get these errors:
Quote"HT-AVOCADO MAYHEM.gbas"(3311) error : redefinition as different type : gf is of type DGInt
"HT-AVOCADO MAYHEM.gbas"(141) : GLOBAL definition here

But most likely I have no idea how to use other people´s code.
I opened file SS.gbas and then copied the first part to the beginning of my code and copied the functions to the end.
I did not use any commands yet, just tried it out clean to see if it compiles.

It is all in one code/file. Am I doing something horribly stupid?

erico

I took an extra time to examine the example, it works there.
But I guess I´m too dumb to implement it on my code, will leave it for next game when things are fresh.

Thanks for the help Wampus! :good:

erico

#7
Scavenging the forum, I came into this Hemlos post here:
http://www.glbasic.com/forum/index.php?topic=3917.0

It uses GETTIMERALL() like Wampus´ routine.

I tried that but no dice, fps on my game falls short of 60 once in a while, so I limited that on the LIMITFPS command to something I´m sure would not fall short...dosen´t work either.

I don´t need a perfect repeating sound, but the repetitions must happen between fixed intervals. I need only 1 buffer, no overlapping.
My sound is 0.077s long, even if I call it every half second (0.500) it won´t play even.
It kind of does but every now and then it skips a beat and almost double plays it.

You can better hear it on this crappy last-minute video:
http://youtu.be/-VzF8dyE25Y

"There is a fifth dimension beyond that which is known to man. It is a dimension as vast as space and as timeless as infinity. It is the middle ground between IOS and WEBOS, between sound and music, and it lies between the pit of man's fears and the summit of his knowledge. Meet Enrico Monteiro, 37 years old. An indie game creator wannabe. Today, after two weeks, he coded into the twilight zone."

Heck, who needs a walking sound anyways... my bet is the game will be a lot more fun to play without this distracting walking sound! ;/

fuzzy70

Hi Erico, I wonder if your sound problems are related to this forum post?

http://www.glbasic.com/forum/index.php?topic=8393.msg71153#msg71153

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

erico

I´m not sure fuzzy70,

I have other sounds playing in the game(not in the video as I turned them off). Some can play about 4 times simultaneously (ye the avocados or bark´s crashing sound) and they all go ok and perfect. It is just the repeating sounds that lack a hold on the in between time before they play again.
It works on pc/mac/caanoo so I will just leave that part of the code commented till we get an update on the sound system.

Oh well, Shadow of the Beast didn´t have a walking sound and neither did most of the great platformers, single or multi screen. :-[
I can do without it. I´m just a bit sad about the time I enforced on looking for a solution. It was a week gone searching till I posted my problem here.

Best to get the game finished :good:
There are still more strange grounds to strive on android...like certifications, resolution, etc.

Thanks for the help!

fivesprites

Well, I fixed my issue by using soundpool/mediaplayer for a glb game I'm working on.  It seems that there may be some interest in this until our busy bee Gernot has time to implement all sound fixes (I know he's got sound working on V11 beta again).

So, as soon as my day job has calmed down a little, I'll find some time to extract out the code I used and post it on the Code Snippets forum.  Hopefully be soon, but I'm mega busy :(

//Andy

erico

Thanks Fivesprites,

that snippet could help some people with a more urgent case. :good:
I my case though, I´m afraid I would not know how to use more complex codes. :(

I will advance the other parts of the game that needs finishing and that is a lot of stuff and it will take some time.
So my best option is to wait for Gernot´s update. I will also take a look at the latest beta, it seems sound is back but on 22.5khz 16b mono only.

But I read some people have a more urgent need for this kind of fix and sound on android in general, so when you have time, sharing that solution could do a lot of good.
Thanks for caring and don´t work yourself too hard!

erico

Out of pure hapiness, I´m going to  :offtopic: myself.

Today I strugled to figure out the screen size to deploy this game to as many possible androids as there are.
I know there are screen resize routines around the forum made by some excellent coders...but I´m not one of them :(
It is really hard for me, a legacy basic user, to understand such.

I tried to figure my way around GETSCREENSIZE  to at least hardcode support for the more common android resolutions.
And it worked! Worked perfectly!

That way I can still use the same code to support a great set of android tablets/mobiles, desktops, caanoo and pandora!
It is really great when things work out like that! :-* :booze: