First experiments with sound

From Cuis CookBook
Jump to navigation Jump to search

These notes were started from hhzl observations here.

The sound system was exported from Squeak, more information can be found in the Swiki, see [1] and [2].

The sound system isn't loaded in the Cuis base system, but it is included in it, you just need to load it with:

Feature require: 'Sound'.
Play a melody writing note names and duration
(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
TODO. Play a melody with note names in Italian: Do, Re, Mi ...

xxxxx Should be easy.

xxxxx link to the interesting story of the two different note names

TODO. Realtime sound. on envent play a sound as soon as possible

This is necessary to simulate instruments playing on a computer keyboard or on some other external harware device. It is important that the delay is small otherwise the effect will be not realistic and not fun. At the moment i don't know how to do it.

Create 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'.
Play a *.wav file
(SampledSound fromWaveFileNamed: 'maryhadalittlelamb.wav') play


Exercise.1. Check that the class Sound isn't present in Cuis by default.

References
  • xxxx
  • xxxx