Skip to content

How_to_use_sound

hhzl edited this page May 10, 2025 · 9 revisions

Installation of the 'Sound' package

Feature require: 'Sound'.

First example

(AbstractSound noteSequenceOn: 
    PluckedSound default from: 
      #((c4 1 500) 
        (d4 1 500) 
        (e4 1 500) 
        (g4 1 500) 
        (a4 1 250)
        (a4 1 250) 
        (c5 1 500)
       ) 
) play

Source: http://wiki.squeak.org/squeak/152

How to generate a 'WAV' file

(AbstractSound noteSequenceOn: FMSound flute2 from: #(
(e5 0.5 500)
(d5 0.5 300)
(c5 0.5 350)
(d5 0.5 300)
(e5 0.5 500)
(e5 0.5 300)
(e5 1.0 350)
(d5 0.5 400)
(d5 0.5 300)
(d5 1.0 330)
(e5 0.5 400)
(g5 0.5 300)
(g5 1.0 500)
)) storeWAVOnFileNamed: 'maryhadalittlelamb.wav'

And play it with

 (SampledSound fromWaveFileNamed: 'maryhadalittlelamb.wav') play

Source: http://wiki.squeak.org/squeak/152

Class AbstractSound

Adapted from: http://wiki.squeak.org/squeak/2125

AbstractSound is a the superclass which represents sounds. It's abstract, which means that generally you'll be working with one of its subclasses instead of AbstractSound directly.

 AbstractSound new play

just gives an error.

See the first example above how to use it.

The usual way to use these methods is with classes that inherit from AbstractSound, such as on the Squeak wiki: SampledSound http://wiki.squeak.org/squeak/2125 or FMSound.

TODO:add list of implemented instruments/sounds here

Example with specifying the tune with Solfège (do re mi)

TODO: use a Dictionary object and as illustration a very basic canon

https://en.wikipedia.org/wiki/Fr%C3%A8re_Jacques

Clone this wiki locally