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 / Help needed with sound instances...

Author
Message
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 24th Feb 2016 22:41
I'm firing off sounds for my crumbling tiles as below. This is a segment of code where you can see the sounds being spawned. When I run the command GetSoundsPlaying(SND_CrateCreek1) or GetSoundInstances(SND_CrateCreek1), I get an increasing number of instances being shown as playing. Given that the sounds do not loop, I would have expected the reported value to go up as I walk on crumbing tiles but then return to zero when I leave them and the sounds naturally come to their end and therefore get automatically deleted. As a belt and braces I even delete the sounds when they are not needed but still the reported value is going up...

Any clues? I think I'm still slightly confused on the sound instances!

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 24th Feb 2016 23:18
Check if CrumbleTiles[1].Sound2Vol is ever <= 0. DeleteSound should delete EVERY instance of a particular sound, but it looks you may be calling it with the instance of a sound, rather than the ID of a sound (I can't be certain as I cannot see where you are playing CrumbleTiles[1].Sound2 in this snippet (giving it an instance number), or if you are using that as a sound ID). If you are looking to stop individual instances of the sound playing, then use StopSoundInstance( instanceID ) instead of DeleteSound.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 25th Feb 2016 13:56 Edited at: 25th Feb 2016 13:56
Cool. I'll take another look tonight and if I can't work it out will paste more code. I need to get my head around sound instances a bit more so might ask for some clarification on that if that's ok? I've read the manual and think I get it but I seem to have a block on that particular area!

Thinking aloud for a second, irrespective of stopping sound instances, when they get to the end of playing shouldn't they delete themselves (unless looped which they are not) and so shouldn't I find that the number of instances playing for any given sound goes down to zero after a short while regardless of what I do to them? My sounds are only about 1 to 1.5 seconds long?

Edit: typo
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 25th Feb 2016 15:21
Yes. I'd expect the number of instances playing to go down as sounds stop playing. .. I'll knock together a little test to see if this is a bug....
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 25th Feb 2016 15:34 Edited at: 25th Feb 2016 20:30
It's looking okay here (v2016). Quick test code :

[edit] - now shows instances...

V2 T1 (Mostly)
Phone Tap!
Uzmadesign

Attachments

Login to view attachments
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 25th Feb 2016 19:57
Still not sure where I'm going wrong. Can you take a look at the full code snippet and let me know what I'm doing wrong? There are actually one of these segments of code for the left and right foot.

I load the sounds like....



Then they are played at specified times, based on how close the tile is to crumbling (TBC = Time Before Crumble) like this.....




I'm then getting the following commands to report back to me and it's saying that there are an ever increasing number of sound instances playing (each sound instance never seems to die)


Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 25th Feb 2016 20:14 Edited at: 25th Feb 2016 20:17
To see if I'm understanding this, some psuedo...



Zebra = LoadSound("SoundFile.wav") // Load a sound

SoundID1 = Playsound(Zebra) // Does create a sound instance or a sound is there a difference?!?

SoundID2 = Playsound(Zebra) // If I call the same sound to be played again, does this create another instance?

At this stage do SoundID1 and SoundID2 now hold the ID's of the sound instances, at least until they get to the end and then auto-delete themselves?



I'm using 2.0.14b at the moment but I've got a program that Jim (I think) created that spawns sound instances and I can see that works fine deleting the instances as they get to their ends...
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 25th Feb 2016 20:45
Quote: "SoundID1 = Playsound(Zebra) "


Yes, SoundID1 and SoundID2 are the instances of the sound. Zebra is the ID of the sound. Playing the same sound ID creates new instances of the same sound. Playsound returns a new ID each time it is called, even if playing the same sound.

When the sound comes to an end, the instance is deleted and GetSoundInstances(zebra) should reduce accordingly.

What happens when you run the code I pasted above (I included the gong wav too). You should be able to click to make sounds and see the values increase, and then decrease when the sounds stop playing.


V2 T1 (Mostly)
Phone Tap!
Uzmadesign
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 25th Feb 2016 21:01
How long are your wavs? If the sound volume hasn't reached zero by the time your if conditions change, then I think you might start playing the next sound before you have stopped the first. The first sound will continue playing even if you reassign the variable containing the instance to a new instance. To test the theory, as an experiment, can you try stopping the sound right away (rather than ramping the volume down first)? Something like this:

V2 T1 (Mostly)
Phone Tap!
Uzmadesign
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 25th Feb 2016 21:28 Edited at: 25th Feb 2016 21:29
Wavs are only alike a second or so long. OK, I'll try that. In the meantime, I having tried your code successfully and my own separate code fine too, I got thinking about the differences...so tried an experiment. I simply replaced the variable that holds the sound ID as shown below (DebugFlag3 is just a global variable that I use for testing) and it works as expected - the number of "SND_CrateCreek1" instances playing goes up...then down to zero again. The "@@@@@" are just to highlight the changes lines!



That doesn't make sense to me?!?!
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 25th Feb 2016 21:57
The rem'ing out doesn't change it. The "instances playing" still climb up and remain high.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 25th Feb 2016 23:02
Seems odd. Is anything else happening with CrumbleTiles elsewhere in your code that might change or reset CrumbleTiles[1].Sound1? Add a line: CrumbleTiles[1].Sound1 = DebugFlag3 under the playsound line with the @@@@s so that it should have the same instance ID as the sound being played, and then check if the values diverge at some point. Being old-school, I'd probably do this with loads of PRINTs everywhere to show me the values, but I've heard about this debug thing that I've yet to really try in anger.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 26th Feb 2016 08:45
Hi CJB, Seems like a good idea - I'll try that. I won't be able to get back to the code until Sunday PM now so apologies for a short pause

Regards prints for debugging....exactly the same for me. I've got into the habit, for reasonably sized projects, of creating two long lists of text that I can have displayed or hidden. One that allows you to track values in real-time and one that can send a value to the top of a stack so you can see historical changes. An absolute life saver (you can see them briefly on this video.)

Must also remember to do some tests on my other sounds to make sure it's not happening everywhere! Eeek.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 28th Feb 2016 19:31
OK, it does appear that somehow the CrumbleTiles[1].Sound1 (in the original code version) IS being set to zero when I don't expect it to. I'm wondering if somehow the line "If GetSoundInstancePlaying(CrumbleTiles[1].Sound1) " is returning a zero on the first time it is tested even though the playsound command should have started a sound? Is this possible?

I'll have to dig deeper to see how/if this is happening?
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 2nd Mar 2016 20:46
If I remove the line "StopSoundInstance(CrumbleTiles[1].Sound1)" from the code below then it works fine - all instances auto delete.....but I'm not sure why....any clues?



At least I can carry on now but I'd like to understand why that line prevents the instances from auto-deleting if anyone can figure it out?
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 2nd Mar 2016 23:02
Quote: "I'm using 2.0.14b at the moment "

There was a bug fixed in 2.0.15 where StopSoundInstance would not decrease the instance count
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 3rd Mar 2016 09:00
Aaah! Thanks Paul. So glad to get that sorted!

I'll upgrade and add the StopSoundInstance back in.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 3rd Mar 2016 20:51
2017 installed, running and instances-playing number is as I previously expected. Nice when things come together.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)

Login to post a reply

Server time is: 2024-11-25 10:42:08
Your offset time is: 2024-11-25 10:42:08