SOUND EFFECTS

Sound is very important. A killer shot, a baby laughting, an old Xmas song (Merry Xmas, friends!). Sound is important for the creation of a nice Croquet space. Could be an ambient sound or a sound played when something happens, a collision , by example.

Squeak-Croquet has the Class StreamingMP3Sound. To use it you need to create an object-reference , a "prefix", writing something like:

 
sg1:= StreamingMP3Sound onFileNamed:  
 (FileDirectory pathFrom:
           {FileDirectory default pathName.  'Content'. 'columnLogo4x6x4' .'aSound.mp3'}) .

And the more used method is:

sg1 play.

But here, for you, a " quick reference" of the Class:

 
StreamingMP3Sound 

onFileNamed:filepath+name       Look the sample...


duration                       Returns the duration of this sound in seconds.

repeat                          Returns the repeat flag.

repeat:true | false            Set the repeat flag. If true, this sound will 
                                loop back to the beginning when it gets to the end.

soundPosition                   Returns  the relative position of sound playback as a 
                                number between 0.0 and 1.0.

soundPosition:n                Jump to the position the given fraction through the sound 
                                 file. The argument is a number between 0.0 and 1.0.

volume                          Returns the volume.

volume:n                       Set the volume to the given number between 0.0 and 1.0.
 
closeFile                      Close the .MP3  file.

millisecondsSinceStart          Returns the number of milliseconds since this sound 

                                started playing.

play                            Plays...

reset                            Reset the internal state for a replay.  

The exercice you will do is: when the car kicks the column, in the exercice of the previous lesson, play a sound. You need to download:

babylaughting.mp3 - in the folder columnLogo4x6x4

You need only to change the method:

verifycL4x6x4a 
| onetime dist sg1 |
onetime:=0.
dist:=(bC distanceTo:cL4x6x4a).
(dist<8 & onetime=0) ifTrue: [
 cL4x6x4afly:=1.

 sg1:=StreamingMP3Sound onFileNamed:  
  (FileDirectory pathFrom:
           {FileDirectory default pathName.  'Content'. 'columnLogo4x6x4' .'babylaughting.mp3'}) . 
 sg1 play.

 onetime:=1.
].  

Like this method is executed in the moment of the collision, you will hear the sound.

And here, some selected .MP3 sound effects you can download and use.I think that they don't have copyright). You can download all the collection (4.7 MB):

sounds.zip



PREVIOUS LESSON NEXT LESSON
T. CONTENTS HOMEPAGE

DISCLAIMER: This material can be translated for any language, and reproduced total or partially by anybody using any type of media. But, please, don't put your name like author. And let me know if it was useful (americo@dmu.com).The use of any code, 3D model or technique published is free and doesn't need to have any reference about this source.The author is not responsible for any damage that the material can cause to your professional or sexual life.