Updated 2011-09-18 01:18:50 by RLH

Muzic is the Tcl music interface used in the Eolas Muse product. It provides a simple interface that allows the playing of notes and loading of SoundFonts from Tcl scripts.

Muzic was developed by Steve Landers and is Copyright (c) 2005 Eolas Technologies Inc. It is released under a Tcl/BSD style license.

It can be downloaded from http://tcl.tk/starkits/muzic.kit

Muzic uses the built-in softsynth on platforms that support it (currently MacOS X and Windows) and optional SoundFonts via the Fluidsynth library - a real-time software synthesizer based on the SoundFont2 specification (see http://www.fluidsynth.org).

This Starkit contains the Muzic library built for Linux, MacOS X and Windows. It also contains the Muzic source (located in muzic.vfs/lib/muzic/Tcl/muzic.tcl).

The MacOS X version requires a recent build of Tcl (i.e. after Tcl 8.4.11) that supports the loading of bundles.

Using the Muzic starkit

The Muzic starkit is a convenient way to get the Muzic package, its documentation and test program.

If you run muzic.kit without options you will see a help page.

To play some sample sounds using the built-in softsynth use the play command without arguments
  muzic.kit play

On platforms without a built-in softsynth (e.g. Linux) a sample SoundFont will be used. To explicilty request that the sample SoundFont use
  muzic.kit play default

To play using other SoundFonts list these as arguments to the play command
  muzic.kit play Scc1t2.sf2 moog.sf2 ...

If you want to see the source for the play command, use the following
  muzic.kit playsrc

And, if you're interested in seeing the Muzic source just unwrap the Starkit, or use the following command
  muzic.kit src

Using Muzic in your application

To use Muzic, either source this starkit or extract the compiled Muzic package from muzic.vfs/lib/muzic and add it to the lib directory of your application (i.e. a directory on your auto_path).

The Muzic API contains just four procedures
    muzic::init

  • call once to initialize Muzic
   muzic::soundfont file

  • selects a SoundFont to use
  • call with no arguments to use the built-in softsynth (if available)
  • to use a SoundFont call with a single argument which is the path to the SoundFont file
   muzic::channel chan inst

  • assigns an instrument to a channel
  • chan is an integer - usually from 0 to 15 (i.e. 16 channels are guaranteed to be supported but some SoundFonts may support more)
  • inst is the instrument number - typically a MIDI instrument number from 0 to 127 (although this again may vary with specific SoundFonts)
  • for an example run "muzic.kit playsrc" and look for the "chan_def" array and the muzic::channel call that uses it
   muzic::playnote chan pitch volume <duration>

  • plays a note on specified channel, at specified pitch and volume
  • pitch is the raw MIDI pitch, as per the general midi standard - where middle C is 60 (see http://www.mozart.co.uk/information/articles/midinote.htm which has a table of MIDI pitch values)
  • volume is a number between 0 and 100
  • duration is optional, and defaults to 500 (i.e. 500 ms)

Implementation

On MacOS the built-in softsynth is accessed via the QuickTime Music APIs.

On Windows the built-in softsynth is accessed via the Windows Multimedia SDK.

There is no builtin softsynth on Linux, so Muzic.kit includes a sample SoundFont called "Gort's Doubledecker" that is relatively small (< 100k) and approximates the built-in SoundFonts on MacOS X and Windows.

SoundFont support is via the FluidSynth library, which is statically linked into the Muzic shared library/DLL. Fluidsynth is configured as follows:

  • on Linux it uses uses the Open Sound System (oss) driver
  • on MacOS X it uses the Core Audio (coreaudio) driver
  • on Windows it uses the DirectSound (dsound) driver

Muzic is implemented using Critcl - the facility that allows C code to be embedded into Tcl scripts. See http://www.equi4.com/critcl.html for more information or grab the Starkit from http://www.DigitalSmarties.com/pub/critcl.kit.

See Building Muzic in the Muzic help pages for instructions on building Muzic and Fluidsynth.

Additional Soundfonts

There are many additional SoundFonts available at the following websites


Having Fun with Muzic

DKF: Note that this is really designed to be used interactively.
 package require muzic
 muzic::init
 file copy muzic.kit/default.sf2 .
 muzic::soundfont default.sf2
 catch {file delete default.sf2}
 proc playnotes {{idx 0}} {
    global notes chan stop offset
    if {$stop} return
    if {$idx>=[llength $notes]} {set idx 0}
    foreach c $chan {
       muzic::playnote $c [expr {$offset+[lindex $notes $idx]}] 70 250
    }
    after 150 playnotes [incr idx]
 }
 set chan {0 2 3 4}
 set offset -5
 set stop 0
 set notes {48 52 48 55 48 57 60 48 52 48 55 48 50 48 47}
 playnotes 
 after 30000 set stop 1

Have fun!

Ro 2011 September: On debian squeeze I had to install the oss-compat package since muzic relies on OSS and /dev/dsp and after that all is well.