Editor's note: In part one of this two-part series on sound editing under Linux, Dave Phillips showed us how to move over from Windows-based Cool Edit to Linux-based Snd. He compared the two software packages, then discussed the installation and configuration of Snd. Now, in part two, Dave walks you through a Snd tutorial and shows you some advanced sound-editing techniques including batch processing.
Now that you're familiar with the basic features of the Snd package for sound editing on Linux, let me walk you through some of the techniques for using this tool. Before beginning this tutorial, you should load the following Scheme files into Snd. These files are included with the Snd source package:
Provides Motif GUI components (sliders, buttons, entry boxes)
Some DSP code
Envelope editing routines
Routines for mixing soundfiles
The Moog filter code
Provides various pop-up menus
Code to stretch/contract sound
The following files are my own additions (see the Resources at the end of this article):
Adds a special menu to the main menu bar
Some background pixmaps
Adds a menu for mark processes
Adds an expanded effects menu
Adds a panic menu for stopping Snd processes
Includes all of these files and some miscellaneous code
You could add an
-l flag at the command prompt for each one of these files but your command string would quickly grow unwieldy (and your wrists would tire). Fortunately you can simply include all of them in a single file, as seen in the
misc.scm file. Download the customization package listed in the Resources for this article, edit
misc.scm to reflect your path to the Scheme files packaged with the Snd sources and the new extension files, then launch the Snd with this command string:
snd -l misc.scm foo.wav
You must specify the complete path to
misc.scm. Loading the sound file is optional.
You can, of course, add new sound files via the File/Open dialog box at any time. The customization package adds some nice features to the dialog, including buttons for toggling a sound files-only listing and for playing the selected file. Multichannel sound files are listed in different colors, and the dialog displays useful information about the selected file. [Figure 1]
Bill Schottstaedt has provided extensive and well-written documentation for Snd in the
snd.html file (or
snd1.html if your browser supports frames). The HTML documentation is quite complete and should be considered the definitive reference. I advise all users to read at least the "Getting Started" section. As mentioned earlier there is also a man page, but it is very brief, containing only a description of the program and a list of some of the command-line flags. I'll cover some of the material found in the HTML documentation, but in a more tutorial fashion.
In his Computer Music Tutorial, Curtis Roads lists these basic functions of sound file editors:
Snd meets nearly all the baseline criteria in that list. Direct I/O with external samplers is perhaps better considered as a function of hardware support, although Snd does support the MIDI Sample File Dump standard as well as a variety of sampler-specific file formats. The identification of a sound sample's musical note values is still technically very problematic and is not commonly found in the popular sound file editors for Windows, Mac OS, or Linux. All the other operations are present and accounted for in Snd.
Beyond the baseline criteria, I've culled a set of common operations from the results of an informal poll of Cool Edit users on the mail lists for Csound, LAD (Linux Audio Developers), and Common Music. Those users most frequently employed the following functions and operations in Cool Edit:
With only a few exceptions Snd again meets the criteria. Noise reduction and compression/limiting are still in development, and of course DirectX plug-in support is absent. However, Snd does support the LADSPA plug-ins, and there are a few other ways of plugging into Snd that we'll look at later.
However, it is one thing to say that Snd has this or that specific function available, and it is another thing to access the function or operation. In classic Snd, many of the baseline functions and Cool Edit-style edits are invoked from the Listener via the Guile/Scheme language. However, the most recent releases of Snd have added a number of widgets and menu items to graphically access its editing tools and signal processors. Power users still have the Listener, but new users can now more easily make their way into Snd's considerable toolkit.
Before we start using that toolkit, let's see how to determine an editing area in Snd.
Edit areas in Snd include the whole file or files, the area between marks, and the selection (highlighted) area. The assumed edit area is the whole file. At this time, most of the effects are applied only to whole files, but work is underway to add options to restrict processing to the highlighted selection or to a marked area.
Marks can be placed into a file in three different forms. Type Ctrl-M or select "Add mark" from the graph display pop-up menu to add a normal mark into your file. Named marks are created with the Ctrl-X-M keyboard combination, and synch marks are added with the Ctrl-M command. In each case, the cursor position defines the mark insert point in the graph display. Delete marks via the channel graph pop-up: Set the cursor near the mark you want to delete, select "Delete mark" from the pop-up, and it's gone.
Any mark can be moved by left-clicking and holding on the handle at the top of the mark and carrying it with the mouse to a new location. You can toggle playback from any mark position by clicking on the triangular tab at the bottom of the mark, or you can drag the mark tab to "scrub" through the sound data. Marks can be used to move sections of a file forward or backward in time: Just hold down the Control key and left-click on the mark handle, then drag the mark forward to replace the existing data (if any) with the dragged material, or drag the mark backward to shift the sound file back and to add silence for the space of the drag. Marks can be used to define sample-accurate boundaries for processing a selection area: Place your marks at single-sample resolution, then select "Define selection by marks" from the Marks menu, and voilà, the marked area will become a sample-accurate highlighted selection area.
Named marks are simply normal marks with names added for display and identification. If Snd's
marks.scm package is loaded, the report-mark-names function will display mark names in the minibuffer during playback.
Synch marks are marks whose actions are synchronized. Whatever is done with one mark will be done for all others synchronized with it: move one mark and the others will follow, even across different channels and files. Click on any synchronization mark's tab and multichannel playback will begin from the position of each synch mark.
You can synch previously-placed normal and named marks with the Start/Stop mark synch items in the Marks menu provided by the customization package. That menu includes many other mark-related editing functions, such as crop and trim operations, loop-play between marks, and a "fit selection to marks" function that time-scales a selected (highlighted) area and fits it between two marks, mixing it with any pre-existing material in the same marked area.
A highlighted selection area is made by holding down the left mouse button anywhere within the channel graph display and sweeping the mouse to the left or right. The swept area will be highlighted; release the mouse button to finalize your selection (a Select All/Unselect All function is also available from the channel graph pop-up menu). Right-click anywhere within the highlighted area to pop up a menu of actions to perform on the selection, such as playback, loop play, reverse, and copy-to-new.
A selected area defines a region. View/Regions will call up the Regions Browser [Figure 2], a dialog window that includes a list of all the selections you've made up to that point, including selections from files that have been closed. At present, the browser is not too useful. You can play individual regions and send them to new edit channels, you can lock regions from deletion or further editing, and you can delete selections from the browser. However, the
examp.scm file includes code for two forms of sequential playback of regions. This command in the Listener:
(region-play-sequence '(0 2 1))
will play regions 0, 2, and 1 in an uninterrupted sequence. This command:
(region-play-list (list (list 0.0 0) (list 0.5 1) (list 1.0 2) (list 1.0 0)))
will play region 0 at 0.0 seconds, region 1 at .5 seconds, and regions 2 and 0 together at 1 second after the start. Hopefully the regions browser will eventually incorporate these commands into a set of graphic controls.
Standard sound file mixing operations include functions to paste, insert, and replace data. Paste-mix blends the mix file (which Snd just calls a mix) with the original data, insert-mix splices in the mix at the cursor point (lengthening the original by the length of the mix data), and replace-mix wipes out the original data and replaces it with the new.
Snd provides a few different methods of paste-mixing. Double-clicking on a sound file name in the File/Mix dialog will paste-mix that file into the active channel. Alternately, you can drag a highlighted file name from the entry box of any file dialog in Snd and drop it into any channel graph display. Paste-mix is also available from the channel graph pop-up menu, but in this case the mix source is the currently selected area. Make your selection, position the cursor at the mix point, then click on Mix Selection from the pop-up menu. In all these methods the mix is pasted in at the cursor position, and a waveform graphic will appear at the top of the channel display. You can reposition the mix waveform by clicking and dragging the handle at the left end of the graph [Figure 3].
Insert-mix is present as an insert-file action and as an insert-selection operation. To make things easy, I've added an Insert File item to the menu created by the
special.scm file. Click on the menu item, select your file from the dialog box, and the original data will be pushed aside by the inserted mix data. The Edit menu and the channel graph pop-up menu both provide an Insert Selection function that operates the same way using the selected area for the mix data. Note too that middle-clicking will insert the last selected area at the cursor position for very fast insert-mixing.
Mix by replacement is also available from the Edit and channel pop-up menus. Once again the mix point is the cursor location in the active channel, and any highlighted data will be mixed into the channel, replacing any existing data from the cursor forward.
Here's a rather elaborate replace-mix technique for a precise remove/edit/replace operation: Select an area in your sound file and copy it to a new file. Snap a pair of marks to the original selection boundaries, then zero out the selected area (copy-to-new, snap-marks, and zero-out are all found in the selection area pop-up menu). Now switch to the copied selection (named
newf-n.snd by default), edit and add effects to taste, click on Edit/Select All, then switch back to the original channel. Position the cursor anywhere before the first marker and type
C-j to accurately position the cursor at the mark point. Right-click in the channel graph display and choose "Mix selection" or "Replace with selection" from the pop-up menu to replace the zeroed out area with your edited region. If the mix material is longer than the original selection area the mix method will determine whether the mix blends with existing data or replaces it.
Other mixing functions are available via the Mix Panel (see Figure 3), including a way to organize your mix files into tracks. A track is a specifier for a group of mix files: When mixes are defined into a track, any action on one of the track members occurs upon all other members sharing the same track identifier. If you move one mix file, all other mix files with the same track number will be moved too. The Mix Panel also includes speed and amplitude sliders that again can be used to adjust one or several mix files at once. Note that clicking on any mix file in the channel graph will update the mix panel to represent the selected mix.
Mixing creates temporary files stored in Snd's
$TMPDIR directory. These files add up, so make sure
$TMPDIR points to a spacious directory. I put the following line in my
$HOME/.bashrc file to set the temporary files in a large empty directory:
Finally, be aware that by default the various mix procedures do not automatically normalize or scale amplitudes. You may want to adjust the gain of your original file, or you can use the Mix Panel amplitude slider to scale the volume of the mix file (or files).
Now that we know how to designate edit areas, let's perform some of those operations commonly employed by Cool Edit users to see how Snd does the same things.
Gain and normalization are simple processes. Go to the Effects menu, select the appropriate process, adjust the value slider in the GUI widget, and click on the DoIt button. Most (but not yet all) effects in Snd will call a small hourglass icon to indicate elapsed time during the processing; when the hourglass has filled its bottom half the process is ended and the channel display will update automatically. Gain and normalize can be applied to the whole file, highlighted selection, or marked area.
The easiest way to cut data from a file is to select it with the mouse, then right-click in the selected area to open the Selection pop-up menu. From there, you can choose to delete or erase the area or to crop the data surrounding the selected area. Alternately, you can cut or copy your selection to a new channel. If you synch a group of files you can perform the same cut over all the synchronized files. Trimming and cropping are also mark operations, available as Scheme code or items in the Marks menu. Trim cuts the file length before or behind a mark; crop cuts everything outside a marked area.
Snd has excellent zoom controls. You can use the horizontal sliders beneath a sound's channel graph display to adjust zoom factor and and viewing position, or you can use the keyboard's arrow keys to zoom in or out and move the display view from left to right. The zoom focus can be controlled from the whole-file view down to the individual sample level. To the left of the channel graph display, you can see Snd's vertical resolution sliders. These sliders are especially helpful when editing files with very low amplitudes. You can quickly set the x/y axes to minimum or maximum view by middle-clicking at either end of the slider trough.
Some Cool Edit users specifically mentioned that program's use of sinc interpolation between sample points. According to one user, this method of interpolation yields smoother sound, reducing the possibility of clicks after an edit. Snd employs linear interpolation between sample points, but it also provides a smooth-sound function similar to sinc interpolation for smoothing the results of some editing processes. Snd's default interpolation is quite good though, and all operations available for marked and selected areas can be applied to a single sample.
Sinc interpolation is employed by default for Snd's high-quality sample-rate conversion. The sinc width can be set to improve the lowpass filter during conversion, and sinc interpolation can be toggled to linear interpolation for lower-powered machines.
Snd provides an "unlimited" undo/redo function. Snd's Edit History panel (see Figure 4) provides another way to undo/redo and compare edits: Simply click on any listing in the panel, and the channel graph immediately displays that particular edit stage. Very sweet.
From the main menu, click on View/Show Controls. A set of sliders and other control widgets will unfold beneath the active file's channel graph display (see Figure 2-04). All of the sliders work in real time: The amplitude and speed controls are always active, the others are toggled on or off by a checkbox to the right of their displays. Select Options/Hidden Controls to open a bank of sliders to fine-tune some of the effects parameters [Figure 5]. In case you were wondering, the icon to the right of the speed slider is a pair of arrows (<-->) for toggling playback direction, in real time of course.
Real-time response was quite smooth for most of the effects. High values for the reverb scaler tended to distort the sound, and the Contrast effect was particularly sensitive. Time compress/expand and pitch-shifting performed smoothly over a looping playback (an ideal setup for the musician trying to learn a difficult passage from a recording), and within reasonable scaling limits the reverb was equally responsive.
Snd provides two graphic filter editors, one below the default control panel display and one in the Edit menu. Several pre-defined filters are also available in the Effects menu.
Pull up the control panel's sash from its default position to uncover a frequency response envelope editor for an arbitrary-order (even-numbered) FIR filter. Plot your envelope points, set the order of the filter by clicking the tiny increment/decrement buttons to the right of the data box labeled "filter:", then press Apply to filter the active sound file. Judge the results, and undo as necessary and repeat the process until you're satisfied.
Select Edit Envelope from the Edit menu to open another graphic editor [Figure 6]. This one is more general purpose: You can create linear or exponential envelopes for amplitude (amp), frequency (flt), and sample rate conversion (src), and you can apply them to the whole file or just to the selected area. The frequency response envelope is applied to an arbitrary-order FIR or FFT filter, the exponentiation factor can be adjusted (with the slider labeled "exp:"), and envelopes can be named and saved to files for later use.
The Effects menu includes a variety of pre-fabricated filters. Butterworth filters are available in band-pass, band-reject, high-pass, and low-pass configurations; two comb filters are on the menu; and there's even a Moog-style lowpass-filter (24db/oct) with variable Q. More filters and filter parameter controls are available via the Listener, and work proceeds to bring more of that code into the Effects menu and the graphic control widgets.
We have already seen the real-time reverb controls available on Snd's control panel. The algorithm employed for that reverb is from composer Michael McNabb's Nrev, and it can now be called from the Effects menu with more of its parameters exposed. Composer John Chowning's reverb also produces a good sounding reverb with only two controls.
Convolution is an excellent means of applying a natural reverberation to a sound file. The process typically requires a sound file to be effected and an impulse response (IR) file to supply the effect. IR files are recordings of very brief sound events such as a finger-snap or a firecracker in an interesting acoustic environment. When a sound file is convolved with an impulse response file, it will sound as though it had been originally recorded in that environment. Snd's "simple" convolution is surprisingly effective, and I had great fun reverberating sound files with impulse responses from subway stations, stone cathedrals, and gigantic gas tanks. I also rediscovered the value of the Normalize amplitude scaler: The convolution produced a sound file with a greatly expanded dynamic range, but normalizing scaled the data back to the range comfortable for my 16-bit audio device.
The Effects menu includes other common signal-processing routines such as flange, echo, and time-scaling/pitch-shifting. It also includes less-common routines such as cross synthesis and adaptive saturation. All of these processing options have been available via the Listener, but the graphic controls invite experimentation without the language learning curve.
Snd's frequency analysis displays are impressive. Your sound file can be analyzed by any of nine transforms, with more than a dozen window types and sizes. The spectral view itself can be controlled by the keys of your numeric keypad: The arrow keys control the perspective, the forward slash and asterisk keys control the transform size, and the plus and minus keys adjust the analysis window's "hop" size. The keypad Enter key resets the analysis defaults. You can also control the resolution of the x axis by left-clicking on the axis display and dragging the mouse to zoom in and out of the analysis data. Many other options are available from the frequency graph pop-up menu [Figure 7] or from Options/Transform Options on the main menu bar.
Snd correctly reads and displays 32-bit sound files, automatically scaling the output for 16-bit audio equipment. I tested Snd's 32-bit capability by using Csound to create two 32-bit files -- one in IRCAM's SF format and the other as a WAV file. Both sound files loaded and played without complaint.
You can convert the sound file's format with File/Save As. That dialog includes selection boxes for header style and data representation (with default associations), an entry box for comments, and the default sampling rate (user-definable).
If Snd is configured
--with-ladspa, you can dynamically load LADSPA plug-ins (see my article on LADSPA plug-ins on the O'Reilly Network). Unfortunately Snd does not yet provide graphic controls for LADSPA plug-ins, but loading them via the Listener is not terribly difficult. Here's a basic example:
(apply-ladspa (make-sample-reader 0) (list "cmt" "delay_5s" .3 .5) 12000 "/home/dlphilp/soundfiles/bunt.wav")
This sequence tells Snd to read a block of 12,000 samples from the
bunt.wav file, starting at sample number 0, and apply the
delay_5s LADSPA plug-in (found in the
cmt.so library) with a delay time of .3 seconds and a 50/50 balance of unaffected and affected sound.
Play commands are available everywhere in Snd. The Play button toggles playback from the start of the file; when toggled off, the cursor returns to its original position. Normal play and loop play are available for the whole file, highlighted selection, or marked area. The channel graph pop-up menu includes commands for normal play (from the start of the file), play from cursor position, play previous edit, and play the original unedited file. Use synch marks for multichannel play as described above. Press the space bar to pause playback, press again to continue playback from the stop point. Type
C-t to stop the player at any time, or select Stop Play from the Panic Control menu created by the customization package.
Snd will load and play monaural, stereo, and multichannel soundfiles in 8-, 16-, or 32-bit resolution. If your audio hardware supports true multichannel playback, Snd will distribute the channels properly, but it will also nicely fold multichannel files into stereo output if the hardware is not capable of handling more than two channels. You can also make a multichannel sound file by specifying the desired number of channels when creating a new empty file from the File/New dialog.
Go to File/Record to open Snd's Recorder window [Figure 8]. In this window, you can monitor and record audio input, set system sound levels, and save your recordings in a variety of file formats. You can specify a file name for your recording, along with its sample rate and number of channels, and if necessary, you can adjust the record buffer size.
Snd's default input device is the microphone channel of the system sound card mixer. To change the recording device, close the Recorder and make this entry in the Listener:
(set! (recorder-in-device) mus-audio-line-in)
Reopen the Recorder and the input channel will now be set to the line-in of your sound card mixer. To set the input channel back to the microphone, close the record window and run this command in the Listener:
(set! (recorder-in-device) mus-audio-microphone)
cd to record from your CD player. Or you can skip all that typing by using a widget I put together for my SBLive (found in the Special menu), but you'll still need to open/close the Recorder window to reset the input device.
The instructions above are valid for ALSA, OSS/Linux, and the kernel drivers. However, if you're using the ALSA drivers you have an extra record input option: You can tap the sound card mixer's master output as a recording source, letting you record the output from programs like Freebirth (a cool synth/sample-player/sequencer with, alas, no file-save function), or from Internet streaming audio broadcasts. This Listener command correctly informs the Recorder to take its input from the soundcard mixer's master output:
(set! (recorder-in-device) mus-audio-line-out)
It will not reset the system mixer, because Snd is slightly out of synch with the current ALSA packages. Any ALSA-aware mixer should include a switch to set the master output as the record source, and hopefully Snd's support for native ALSA features will improve after ALSA reaches version 1.0. Until then, ALSA's OSS emulation layer works perfectly for Snd compiled with support for the OSS/Free (kernel sound) API.
Note: As mentioned earlier, Fernando Lopez-Lezcano has been working to improve Snd's support for native ALSA. Snd does support ALSA 0.5.x and 0.9.x beta, though your mileage may vary according to your particular sound card. See the documentation in the latest Snd packages for the latest information regarding Snd and ALSA.
Once you've selected your recording device, you can set its level from the mixer in the top-right corner of the Recorder window. When you are satisfied with the level settings, activate the Recorder's input channels by pressing one or both of the A/B buttons beside the input level meters. Now give your recording a new name and press the Record button. When you've finished, press the Done button (it replaced Record). If you toggled the Autoload button, your new file will be loaded immediately after recording.
You can also start recording only after the input signal passes a certain level. When you move the Trigger slider, the Record button becomes a Triggered Record button: press it, but no recording will occur until the input level reaches the amplitude set by the threshold slider.
Snd's recording facilities are rather Spartan, but Snd was not designed to replace a hard-disk recording system. The Recorder is a useful tool, and if your recording needs are not particularly heavy, it may suit your purpose perfectly.
There are too many other untapped resources in Snd to cover in this article, such as the scanned synthesis display, the FM violin controls, and running Snd remotely. But before we leave let's take a brief look at a few advanced uses of Snd.
You may recall that Snd can be compiled without any GUI at all. In this form, it can be used as an interactive interpreter for Scheme commands, as seen in the following very simple sequence:
[dlphilp@localhost snd-5]$ ./snd snd> (open-sound "bunt.wav") 0 snd> (play) #t snd> (close-sound 0) (null)#f snd> (exit)
The call to open
bunt.wav returns the file ID, the
play command plays any files opened (all at once if several are loaded), and
close-sound closes out the file with the particular ID.
Snd with no GUI can also function as a batch processor for Scheme scripts. For example, this
(open-sound "bunt.wav") (scale-by 0.5) (save-sound-as "bunt-scaled.snd") (exit)
bunt.wav, reduce its amplitude by half, save it as a new file, and exit. Run it with this command under Snd with no GUI:
snd -l test.scm
Obviously far more complex scripts can be assembled, and the interested reader is advised to refer to the relevant sections of Snd's documentation.
So far we have only considered Scheme code files as a way to dynamically load new functions into Snd. Snd is also capable of loading shared objects at runtime via commands issued in the Listener. The procedure for building shared objects from the Scheme code is described in detail in the Snd documentation, and I refer the interested reader to those sections dealing with Snd's use of runtime modules and external programs. The documentation also describes methods for using external applications with Snd, such as Perry Cook's STK (synthesis toolkit), the SoX "Swiss Army knife of audio," and Bill Schottstaedt's own Common LISP Music.
For example, you can link a shared object into Snd with these commands:
(define lib (dynamic-link "/home/dlphilp/snd-5/eff.so")) (dynamic-call "init_eff" lib)
At this point, you can invoke the flange processor from the shared object:
(loop-samples (make-sample-reader 0) (get-flange) (frames) "flange" (make-flange 2.0 5.0 0.001))
Called this way, the flange processor should run about 30 times faster than if it were called via the same code in
If you load the customization package Snd will place a Special menu on the main menu bar. Among other things that menu offers a Start/Stop Enveloping feature. When Start Enveloping is invoked, the next file opened will appear with a graphic envelope editor beside the usual time-domain waveform display [Figure 9]. This editor will appear along all subsequently opened files until the Stop Enveloping item is selected. When Start Enveloping is active, you can create an envelope in the graphic editor and apply it to either amplitude or panning. I have added a widget for the panning function, available from the Special/Play Panned menu item, to make it easier to experiment with this interesting feature.
I hope you've enjoyed this article. Above all, I hope you actually tried using Snd with its latest enhancements on some files of your own. I welcome any feedback, particularly with suggestions for improving the interface components and corrections to parameter definitions.
Snd is rich in editing, processing, mixing, and synthesis capabilities, and the customization of Snd is an ongoing process. The addition of GUI widgets and pop-up menus has contributed greatly to the new Snd's ease of use, but much of Snd's power remains to be revealed to the non-programming user. Work on improving Snd's interface will continue, and the interested reader is advised to join the Snd mailing list to stay current with its latest developments (see the Snd home page for details).
I would like to thank the many respondents to my query regarding Cool Edit on the mail lists for Csound, the Linux Audio Developers group, and the "Common" software packages: Their responses formed the core around which my customization of Snd took shape, and I am truly in their debt. I must also thank Fernando Pablo Lopez-Lezcano for his assistance in resolving my problems with ALSA and Snd. But by far the greatest thanks goes to Snd author Bill Schottstaedt. He endured a nearly unceasing flow of questions and requests during the writing of this article, and he provided nearly all the tools needed to create the Snd presented in this article.
Part one of this series: Developing and Using Snd: Editing Sound Under Linux, Part One
Other Necessary Software
Dave Phillips maintains the Linux Music & Sound Applications Web site and has been a performing musician for more than 30 years.
Return to the Linux DevCenter.
Copyright © 2009 O'Reilly Media, Inc.