Enabling All Sprites to Access Sounds

I have a series of sounds that I would like all sprites to access. For now, I am attaching the sounds to the Stage. I then ask each sprite to tell the Stage to play a sound when needed.

Is there a more efficient or elegant way to accomplish this?

you could also put all the sounds into a global list...
(and then remove them from the "jukeboxes" they're in to reduce memory footprint)

@jens My inclination was to drag the sounds directly into the list from the desktop. However, the sounds dragged into Snap! attached themselves to the sprite. At that point I set the global variable "List of Sounds" to List [Samples of Sound 1] [Samples of Sound 2], etc.

image

Is this the best way to import the sounds into a list, or can sound files be dragged directly into items in a list?

[scratchblocks]
set (List of Sounds v) to (my (sounds v) :: sensing)
[/scratchblocks]

this publishes a sprite's "jukebox" to all. I like it, because it doesn't duplicate any data and is also a dynamic reference. @glenbull if you want to make a copy of the sounds you don't need to extract the samples, you could just make a (shallow) copy of my sounds using map or - in this case even - id of (my sounds.

@sir_kitten2 @jens Excellent! We hope to have a demo of the activity later in the week. Thanks for the assist.

@jens I imported a list of 47 sounds into Snap! and set a variable, List of Sounds, to MySounds. I then created a loop to play the sounds. However, the loop only played the first 29 sounds before the audio stopped. Is there a buffer that is filled or some other issue that prevents the entire list of sounds from being played? Here's a link to the Snap! program (named "Sound Test"):

https://snap.berkeley.edu/snap/snap.html#present:Username=glenbull&ProjectName=Sound%20Test

image

not your fault, Glen, there's a bug with sounds (unrelated to the global list design), let me investigate.....

hmm... this appears to be Chrome bug, though, there's a known "memory leak" issue with sounds. Your project works fine for me on Firefox, and even somewhat okayish in Safari. Same procedure as every year: Come summer Google breaks some crucial part of Chrome :frowning: Lets hope they'll fix it soon. Sorry!

What is the

Although I did hear something about sounds and RAM being used up.

crbug.com/1144736#c27

But you know what actually works beautifully across all browsers? Your original idea:

also, I'm happy to report that the memory leak issue seems to be fixed in the current Chrome canary. So we can expect it to just work (again) in Snap in a few weeks, and we don't actually have to come up with a workaround for it ourselves.

@Jens To work around the sound memory leak issue, I sampled one note for each of three octaves and scaled them. This seemed to work - here's the result:

https://snap.berkeley.edu/snap/snap.html#present:Username=glenbull&ProjectName=Animated%20Art%20%26%20Music

Thanks for your assistance with this.