Download - Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)
![Page 1: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/1.jpg)
Using Squeak for media computation
Graphics and sound low-level manipulations in Squeak (Smalltalk)
![Page 2: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/2.jpg)
What is Squeak?
Re-implementation and extension of (original) Smalltalk-80, with VM written in Smalltalk
Runs on over 30 different platforms, including Linux, Windows, MacOS, Solaris…even Windows CE Apple license allows commercial apps, but system fixes must be posted
Squeak has faster, more stable, cross-platform media than Java Media: 3-D graphics, MIDI, Flash, MPEG, sound recording Network: Web, POP/SMTP, zip compression/decompress Beyond Smalltalk-80: Exceptions, namespaces
![Page 3: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/3.jpg)
Squeak Books
![Page 4: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/4.jpg)
![Page 5: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/5.jpg)
Heart of graphics in Squeak: Form
The class Form is what represents pictures in any Smalltalk. To load it from a file, Form fromFileNamed: ‘myfile.gif’ (or .jpg
or .bmp) To display a Form in Smalltalk, you can just send it the
message display To display it in a “window” (Morph) in Squeak, use a
SketchMorph (SketchMorph withForm: form) openInWorld
To write it out to JPEG file, use form writeJPEGfileNamed: filename
![Page 6: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/6.jpg)
Manipulating pixels in Squeak
Forms understand form colorAt: x@y which returns a Color Colors understand methods like red, green, blue, lighter,
darker, duller, brighter Color will create new colors with the r:g:b: method
Forms understand form colorAt: x@y put: aColor
![Page 7: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/7.jpg)
Negative example in Squeak
form := Form fromFileNamed: 'C:\Documents and Settings\Mark Guzdial\My Documents\mediasources\barbara.jpg'.
1 to: (form width) do: [:x | 1 to: (form height) do: [:y | color := form colorAt: x@y. newcolor := Color r: (1.0-color red) g: (1.0-color green) b: (1.0-color
blue). "newcolor := Color r: (color luminance) g: (color luminance) b: (color
luminance)." form colorAt: x@y put: newcolor]].(SketchMorph withForm: form) openInWorld.
![Page 8: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/8.jpg)
Squeak Music Essays on CD
![Page 9: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/9.jpg)
Sound Support in Squeak
Class AbstractSound is heart of sound support in Squeak It knows how to write files
sound storeWAVonFileNamed: ‘fred.wav’ sound storeAIFFonFileNamed: ‘fred.aif’
Class SampledSound knows how to read recorded sounds (SampledSound fromAIFFfileNamed: '1.aif') play (SampledSound fromWaveFileNamed: 'c:\windows\media\
chimes.wav') play
![Page 10: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/10.jpg)
Manipulating Sounds: SoundBuffer
A SoundBuffer knows how to manipulate samples for conversion to sounds later sr := SoundPlayer samplingRate. anArray := SoundBuffer newMonoSampleCount: (sr *
seconds) .
SoundBuffers are manipulated with at:put: and at: like any other array in Smalltalk.
You get the SoundBuffer for a SampledSound using the method samples
![Page 11: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/11.jpg)
Converting SoundBuffers to SampledSounds
|base sound|“Generate a SoundBuffer at the right frequency”base := SoundBufferGenerator forFreq: 440 amplitude:
3000 duration: 2.sound := SampledSound samples: base samplingRate:
SoundPlayer samplingRate.sound viewSamples."sound play."
![Page 12: Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)](https://reader035.vdocuments.us/reader035/viewer/2022070410/56649f1c5503460f94c3300a/html5/thumbnails/12.jpg)
Playing a sound backwards in Squeak
source := SampledSound fromWaveFileNamed: 'C:\Documents and Settings\Mark Guzdial\My Documents\mediasources\thisisatest2.wav'.
target := source copy.samples := target samples.sourceIndex := source samples size.1 to: (samples size) do: [:index | samples at: index put: (source samples at: sourceIndex). sourceIndex := sourceIndex - 1.].target play.