-
Notifications
You must be signed in to change notification settings - Fork 0
How_to_use_sound
Feature require: 'Sound'.
(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
The information about what to play is in this array of arrays:
#((c4 1 500)
(d4 1 500)
(e4 1 500)
(g4 1 500)
(a4 1 250)
(a4 1 250)
(c5 1 500)
)
If you do a printIt of it or open an inspector you get
#(#(#c4 1 500)
#(#d4 1 500)
#(#e4 1 500)
#(#g4 1 500)
#(#a4 1 250)
#(#a4 1 250)
#(#c5 1 500))
Each note is defined by a triplet starting with a symbol (e.g. #c4.) and the two integer values.The individual notes are given by a symbol,
Triplets of
- note (a-g, optionally b or s for flat or sharp, and a number indicating octave)
- duration, and loudness
- loudness range is 0..1000;
The note may also be given as an integer value in Hertz as the class method of PluckedSound bachFugueVoice1On: aSound shows
bachFugueVoice1On: aSound
"Voice one of a fugue by J. S. Bach."
^ self noteSequenceOn: aSound from: #(
(1047 0.15 268)
(988 0.15 268)
(1047 0.30 268)
(784 0.30 268)
(831 0.30 268)
...
(622 0.15 268)
(698 0.15 268)
(784 0.15 268)
(880 0.15 268)
(932 0.45 268)
(622 0.15 268)
(698 0.15 268)
(784 0.15 268)
(831 0.15 268)
(784 0.15 268)
(698 0.15 268)
(622 0.15 268)
(587 0.30 268)
(1047 0.15 268)
(988 0.15 268)
(1047 0.60 268)
(rest 0.9)
(1397 0.30 268)
(1245 0.30 268)
(1175 0.30 268)
(rest 0.3)
(831 0.30 268)
(784 0.30 268)
(698 0.30 268)
(784 0.30 268)
(698 0.15 268)
(622 0.15 268)
(698 0.30 268)
(587 0.30 268)
(784 0.60 268)
(rest 0.3)
(988 0.30 268)
(1047 0.30 268)
(1047 0.15 268)
(988 0.15 268)
(1047 0.30 268)
(784 0.30 268)
(831 0.60 268)
(rest 0.3)
(880 0.30 268)
(932 0.30 268)
(932 0.15 268)
(880 0.15 268)
(932 0.30 268)
(698 0.30 268)
(784 0.60 268)
(rest 0.3)
(784 0.30 268)
(831 0.30 268)
(831 0.30 268)
(784 0.30 268)
(698 0.30 268)
(rest 0.3)
(415 0.30 268)
(466 0.30 268)
(523 0.30 268)
(rest 0.3)
(415 0.15 268)
(392 0.15 268)
(415 0.30 268)
(349 0.30 268)
(466 0.30 268)
(523 0.30 268)
(466 0.30 268)
(415 0.30 268)
(466 0.30 268)
(392 0.30 268)
(349 0.30 268)
(311 0.30 268)
(349 0.30 268)
(554 0.30 268)
(523 0.30 268)
(466 0.30 268)
(523 0.30 268)
(415 0.30 268)
(392 0.30 268)
(349 0.30 268)
(392 0.30 268)
(784 0.15 268)
(740 0.15 268)
(784 0.30 268)
(523 0.30 268)
(622 0.30 268)
(784 0.15 268)
(740 0.15 268)
(784 0.30 268)
(880 0.30 268)
(587 0.30 268)
(784 0.15 268)
(740 0.15 268)
(784 0.30 268)
(880 0.30 268)
(523 0.15 268)
(587 0.15 268)
(622 0.60 268)
(587 0.15 268)
(523 0.15 268)
(466 0.30 346)
(rest 0.45)
(587 0.15 346)
(659 0.15 346)
(740 0.15 346)
(784 0.15 346)
(880 0.15 346)
(932 0.45 346)
(659 0.15 346)
(698 0.15 346)
(784 0.15 346)
(880 0.15 346)
(932 0.15 346)
(1047 0.45 346)
(740 0.15 346)
(784 0.15 346)
(880 0.15 346)
(932 0.30 346)
(622 0.15 346)
(587 0.15 346)
(622 0.30 346)
(392 0.30 346)
(415 0.30 346)
(698 0.15 346)
(622 0.15 346)
(698 0.30 346)
(440 0.30 346)
(466 0.30 346)
(784 0.15 346)
...
(494 0.30 346)
(523 0.60 346)
(rest 0.3)
(659 0.30 346)
(698 0.30 346)
(698 0.15 346)
(659 0.15 346)
(698 0.30 346)
(523 0.30 346)
(587 0.60 346)
(rest 0.3)
(587 0.30 346)
(622 0.30 346)
(622 0.15 346)
(587 0.15 346)
(622 0.30 346)
(466 0.30 346)
(523 1.20 346)
(523 0.30 346)
(587 0.15 346)
(622 0.15 346)
(698 0.15 346)
(622 0.15 346)
(698 0.15 346)
(587 0.15 346)
(494 0.30 457)
(rest 0.6)
... (698 0.30 268)
(587 0.40 268)
(rest 0.4)
(587 0.40 268)
(rest 0.4)
(523 1.60 268)).
(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
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
TODO: use a Dictionary object to map Solfège sound indication and use as illustration a very basic canon
Frère Jacques (Brother John)
to create a WAV version of https://en.wikipedia.org/wiki/File:Fr%C3%A8re_Jacques.ogg