LOADSOUND/PLAYSOUND help with buffers when used with iPod/iPhone

Previous topic - Next topic

Nathan

In the game I'm currently writing, I wish to play a sound effect, which could be played more than once at the same time, therefore I'm make use of the buffers% parameter of LOADSOUND, which is all well and good.  When compiling for win32 this works fine, when the project is compiled on the iPod however, the sound is cut off, each new PLAYSOUND iteration stops the present iteration playing.

In the game I've used DEBUG/STDOUT statements to see what channel% number is generated from each PLAYSOUND, on win32 it correctly increments, on the iPod it always uses the same number, hence the sound cut off.

To test further and to demonstrate I've written a small program ...
Code (glbasic) Select
// --------------------------------- //
// Project: SoundTests
// Start: Wednesday, January 04, 2012
// IDE Version: 10.209

SETCURRENTDIR("Media") // go to media files
LOCAL channel%
LOADSOUND "smallSound.wav", 0, 4

FOR i = 0 TO 3
channel = PLAYSOUND(0, 0.0, 1.0)
STDOUT channel + "\n"
SLEEP 200
NEXT
SHOWSCREEN
MOUSEWAIT
END


Win32 output gives ...

Code (glbasic) Select
Channel number = 0
Channel number = 1
Channel number = 2
Channel number = 3


... and the iPod gives ...

Code (glbasic) Select
Channel number = 0
Channel number = 0
Channel number = 0
Channel number = 0


Does anyone else have experience with this, is it a bug or does iOS not support this sort of functionality?  I've tried other GLB  iPhone games and they seem to be playing the same sounds without cut off, so I'm just not sure what I'm doing wrong?

bigtunacan

The only thing I'm unclear about is how you would get that output on Windows.  You are playing to the same channel every time. The first parameter to PLAYSOUND is the channel you want to play on and you have it set to 0 rather than a variable.

Code (glbasic) Select

FOR i = 0 TO 3
channel = PLAYSOUND(0, 0.0, 1.0) // This should be channel = PLAYSOUND(i, 0.0, 1)
STDOUT channel + "\n"
SLEEP 200
NEXT

Slydog

QuoteThe first parameter to PLAYSOUND is the channel
I just checked, the help info says the first parameter is the buffer number, which is the sound id specified in the LOADSOUND command.  So in this example code, it should be '0'.

Is the length of the sound less than 200ms?
If so, then the iPhone results would seem to be more correct, as it should reuse the same channel if it is no longer being used.  Then maybe the Windows compiled code handles this differently such as auto-incrementing the channel id and only reusing a channel when it gets to the end?  Or maybe Windows takes longer to dispose of the resource so the channel is still tied up, so it is issued a new channel? 

Try lowering or removing the SLEEP delay to see if that changes anything.  Just some thoughts.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

bigtunacan

Heh; yes Slydog is right.  I should have checked the docs.  I went off of my mistaken memory :(

Nathan

I added the SLEEP command so all four sounds don't play at once and I so I can physically hear it working or not on the devices I was trying, but for this testing example it's not necessary and can be removed, as it's not in my main program anyway, all four sounds should then play instantly together, but returning a different channel number each time.  But it doesn't on iOS.

The length of the sound is longer than 200ms.
There's some good thoughts there, but on iOS you can phyiscally hear the sound cut off.

Kitty Hello


matchy


Generally, check the status before playing a sound!  ::)

Code (glbasic) Select

status% = SOUNDPLAYING(channel%)
if status% = 1
channel% = PLAYSOUND(0, 0,1)
endif


Nathan

And how does that help playing THE SAME SOUND using a different sound BUFFER?!    ::) ::)

matchy

Quote from: Nathan on 2012-Jan-09
And how does that help playing THE SAME SOUND using a different sound BUFFER?!    ::) ::)

Calm down dude. Either it's mentioned it's a bug, which I suspect, and I noted a general comment.

Nathan

Okay fair enough.
For the moment I've got a work around, load the same wav file into four different IDs, keep an index of the last one played, which increases each time the sound is played.  And I might enhance it with the SOUNDPLAYING function.
Basically a manual version of what I suspect the buffer% function does internally, maybe.
But it'll be nice of the original problem can be looked into at some point.