Purpose: to describe the Snack sound extension and provide examples, tips, etc. This package is part of the [ActiveTcl] Batteries Included distribution. From http://www.purl.org/NET/Tcl-FAQ/part4.html one can find programs like the following. ---- http://www.purl.org/NET/Tcl-FAQ/part5.html> What: Snack Where: http://www.speech.kth.se/snack/ Description: The Snack sound extension adds commands to play and record audio. Snack supports in-memory sound objects, file based audio, and streaming audio, with background audio processing. It handles fileformats such as AIFF, AU, MP3, NIST/Sphere, and WAV. Snack is extensible; new commands and sound file formats can be added using the Snack C-library. Snack also does sound visualization, e.g. waveforms and spectrograms. The visualization canvas item types update in real time and can output postscript. Works with Tcl 8.0.3 and later, as well as is stubs enabled. Works with the Tcl plug-in. Platforms: HP-UX, Irix, Linux, Solaris, Windows 95/98/NT. Updated: 05/2001 Contact: mailto:kare@speech.kth.se (Kare Sjolander) What: WaveSurfer Where: http://www.speech.kth.se/wavesurfer/ Description: A tool for recording, playing, editing, viewing, printing, and labelling audio data. Runs on Macintosh, Unix, Windows, Solaris and Linux. Has its own sound visualization megawidget. Reads and writes CLS, WAVE, AU, AIFF, and other file formats. Requires Tcl/Tk 8.x and Snack 1.7.0 or newer. Latest version is 1.0.4 . Updated: 05/2000 Contact: mailto:kare@speech.kth.se (Kare Sjolander) What: Netscape client Tcl Tclet (joakim_g) Where: http://www.speech.kth.se/labs/analysis/ http://www.speech.kth.se/%7Ejoakim_g/plan/icslp98_web.html http://www.speech.kth.se/snack/ Description: Set of exercises on speech technology. Requires Snack. The html page is a paper describing the setup. Updated: 05/1999 Contact: mailto:joakim_g@speech.kth.se What: transcriber Where: http://www.etca.fr/CTA/gip/Projets/Transcriber/ Description: Tool for assisting the creation of speech corpora. Allows one to manually segment, label and transcribe speech signals for laster use in auto speech processing. Developed in Tcl/Tk, and C, and requires Snack and tcLex. Tested on Linux, Solaris, SGI, and Windows NT. Updated: 07/2000 Contact: mailto:majordomo@etca.fr ("subscribe transcriber-announce") ---- '''Additional commands not in the official manual''' (why?) [PS] 30Mar2004: I've found these because I wondered how the 'tomAmp.tcl' showed the current position in a file. The '''current_position''' is probably the most important omission. * ''soundName'' current_position ?-type samples|seconds?: returns the current playing/paused position, defaults to sample number. * ''soundName'' datasamples ?-begin sample? ?-end sample? ?-byteorder littleEndian|bigEndian?: returns the sample data from the sound as (tcl string?) * ''soundName'' swap: works only on in-memory sounds, function unclear, either swaps the left-right channels or reverses the sound. * ''soundName'' an: Declared, but does nothing. * ''soundName'' stretch ?-pitch x? ?-pitchlist x? ?-rate x? ?-ratelist x? ?-tract x? ?-segments x?: stretches the sound somehow. I haven't examined it yet. * ''soundName'' op: Declared, but does nothing. ---- Applications based on Snack, or in related areas * [SnackAmp] * [a musicbox] * [A Radio Recorder] * See [A toy piano] for a simple Snack demo. See also [Using Tcl/Tk in Multimedia Applications] , ---- How does Snack compare to Audacity [http://audacity.sourceforge.net]? Well, for one thing, Audacity is a C/C++ application, which Snack is a C Tcl extension. This makes Snack capable of being used within other Tcl applications relatively easily, while one would have to work harder at using Audacity... ---- [TV] I just tried a little addition to the [Colliding Balls] where I loaded a drum sample and play it at every bounce: package require snack snack::sound -load soundfilename.wav Is needed at init somewhere, and then: # collide a given coin with all other coins that overlap with it # proc collide {coin radius} { # find coin's center foreach {x1 y1 x2 y2} [$::canvas coords $coin] break set x [expr {($x1+$x2)/2.0}] set y [expr {($y1+$y2)/2.0}] # find other coins that overlap with the given coin set overlap [list] $::canvas raise $coin ;# not sure if really needed set next $coin while {[set next [$::canvas find closest $x $y $radius $next]] != $coin} { lappend overlap $next } # when there is a collision play the sound if {[llength $overlap] >0} {sound1 play} # collide the given coin with other coins foreach other $overlap { collideCoins $coin $other } } The soundfile, a kick drum, I used you could get from here [http://82.168.209.239/Tripod/Diary/Samples/kick.wav]. I was running quite some things and didn't pay much attention to simultaneously sounding sounds, and even loaded tcltalk simultaneously to feel right at homein computer game lab and let the thing speak to me where a certain ball is, and it crashed after maybe 15 minutes... Have a ball. ---- [Jason Tang]: You may have noticed that snack doesn't play well when some other application has control of the sound card. On Windows based systems, the ''package require snack'' will immediately return with an error if something is using the sound card. In [Linux] (and I presume other Unix based systems) ''package require snack'' blocks untils the other process relinquishes control. Here's a little hack to prevent this blocking: proc soundInit {} { set soundAvail 1 global tcl_platform if {$tcl_platform(platform) == "unix"} { # on unix, libsnack blocks if sound device is in use; so # detect by trying to open /dev/dsp if {[catch {open /dev/dsp "WRONLY NONBLOCK"} f]} { set soundAvail 0 return } else { close $f } } if {[catch {package require sound}]} { set soundAvail 0 return } if {[catch {package require snackogg}]} { set soundAvail 0 return } } Note that this detection works under x86, kernel 2.4.18, Tcl/Tk 8.4.2, OSS drivers. I do not know the behavior when run under ALSA, esd, and/or non x86 systems. [DKF]: The problem is that [Linux], like many other [UNIX] systems, only allows exclusive opens on the sound device. If you're going to support multiple channels assigned to different apps, you need to put a mixer on the front end. That's what the likes of ''esd'' etc. do. (I've no idea how to configure Snack to make use of these sorts of resources though.) ---- [[ [Category Package] | [Category Multimedia] [Category Sound] ]]