Wize /
Snack
Search:  

1.  Snack

Snack adds sound to Tcl as a shared library extension (Source in CVS).

Documentation is available here.

NOTE: MP3 handling has been rewritten and now uses libmpg123.

2.  The "sounds" Command

Wize adds a new command sounds which:

  • automatically does a package require snack
  • supports validation in Wize.
  • supports command completion in Ted.

2.1  Example

Here is an example using sounds:

  set s [sounds new -load "/tmp/ex1.wav"]
  sounds op play $s

or the more traditional way (but code is not validated).

  package require snack
  set s [snack::sound -load "/tmp/ex1.wav"]
  $s play

3.  Snack Sound Formats

Snack has been built with support for the following sound formats:

  • WAV and cousins are builtin to snack.
  • OGG the free lossy compression format.
  • MP3 the not-so-free lossy compression format.

4.  Modifications

The Snack used by Wize contains the following modifications:

4.1  Auto-rate

Lower end cards have playback rate limitations which unfortunately causes the play command to fail. A manual work-around was available using something like:

  if {[catch {$s play}]} {
     $s play -devicerate 48000
  }

The change involves having play do this automatically. To disable this and fallback to the old behaviour, issue the command:

  sounds audio fallbackrate 0

4.2  MP3 Rewrite

Although new code projects should certainly be encouraged to use OGG, there are some things you just need MP3 for (like playing legacy music files).

Support for MP3 in Snack has been rewritten to use libmpg123 version 1.7.3 (with --disable-largefile).

There were several problems with the old MP3 implementation:

  • Using -file (on-the-fly loading) was noisy.
  • Small .mp3 files didn't work reliably (under 20k?).
  • The copyright was non-commercial use only.
  • MP3 is patented, so MP3 needs to be an optional DLL.

4.3  Disabling MP3

Since mpg123 support is now implemented as a loadable library, disabling MP3 is as easy as removing libsnackmpg.so (or libsnackmpg.dll). Afterwards, snack can still be used with OGG, WAV, etc.

4.4  New MP3 Options

MP3 supports the following new readonly options: '-author -album -title -year -tag -genre -played -remain.

The last 2 options give info on the current position in the song.

 set played [sounds op conf $s -played]
 set remain [sounds op conf $s -remain]
 set len [expr {$played+$remain}]

© 2008 Peter MacDonald

Page last modified on June 11, 2009, at 04:49 PM