An example extension can be found in the ext directory of the Snack source distribution together with information on how to build and use them on both Unix and Windows.
Source code showing how a speech recognizer can track a Snack sound object can be found here.
Below is a minimal example of a command that extends Snack. The code and related files can be found in the ext directory of the Snack distribution.
int
Square(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj
*CONST objv[])
{
Sound *sound;
int i;
/* Get the sound structure for this sound. */
sound = Snack_GetSound(interp, Tcl_GetStringFromObj(objv[0], NULL));
for (i = 0; i < Snack_GetLength(sound); i++) {
if ((i/10)%2) {
Snack_SetSample(sound, 0, i, 10000);
} else {
Snack_SetSample(sound, 0, i, -10000);
}
}
return TCL_OK;
}
/*
Initialize the square package and create a new sound command
'square'.
The syntax is: sndName square
*/
EXPORT(int, Square_Init)(Tcl_Interp *interp)
{
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8", 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_TK_STUBS
if (Tk_InitStubs(interp, "8", 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_SNACK_STUBS
if (Snack_InitStubs(interp, "2", 0) == NULL) {
return TCL_ERROR;
}
#endif
if (Tcl_PkgProvide(interp, "square", "1.0") != TCL_OK) {
return TCL_ERROR;
}
Snack_AddSubCmd(SNACK_SOUND_CMD, "square", (Snack_CmdProc *) Square, NULL);
return TCL_OK;
}
#/usr/local/bin/wish
# 'info sharedlibext' returns .dll on Windows and .so on most Unix systems
load libsquare[info sharedlibext]
sound s
s length 10000
s square
pack [button .b -text Play -command {s play}]
Here is a step by step guide for Windows users using MS Visual C++ 6.0.