1 / 12

Using Squeak for media computation

Using Squeak for media computation. Graphics and sound low-level manipulations in Squeak (Smalltalk). What is Squeak?. Re-implementation and extension of (original) Smalltalk-80, with VM written in Smalltalk

kasia
Download Presentation

Using Squeak for media computation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Squeak for media computation Graphics and sound low-level manipulations in Squeak (Smalltalk)

  2. 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

  3. Squeak Books

  4. 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

  5. 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

  6. 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.

  7. Squeak Music Essays on CD

  8. 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

  9. 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

  10. 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."

  11. 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.

More Related