Advanced Tools for the Digital Arts and Humanities
Welcome to the Bregman toolbox from the Bregman Music and Audio Research Studio at Dartmouth College. These pages document the toolbox and provide a set of guided tutorials to its use.
Required: pylab (numpy + scipy + matplotlib).
Linux and OSX users with package management tools (e.g. easy_install, dpkg, apt-get, ports, yum), should install the unix packages from their distributions, e.g. (using apt-get):
sudo apt-get install ipython python-numpy python-matplotlib python-scipyWindows, and OSX without package manager, install the Enthought Python Distribution (EPD). Available for FREE for academic use.
Strongly recommended: instal scikits.audiolab for audio play and wavread/wavwrite functions.
Save the ZIP file Bregman Toolbox Version 0.12-09.15 to your machine.
unzip the installer directory. You will need to install as administrator. In a UNIX terminal:
cd /path/to/installer/directory sudo python setup.py install
If you do not have admin (sudo) privileges, you can install in your home path using the –prefix “$HOME” option to setup.py
First launch the ipython shell with pylab preloaded:
ipython --pylab # launch the ipython shell with pylab
Import the entire bregman toolbox and specify an audio file to work with:
from bregman.suite import *
#use built-in audio examples in audio_dir
audio_file = os.path.join(audio_dir,"gmin.wav")
Extract short-time Fourier transform, specifying window parameters:
linspec = LinearFrequencySpectrum(audio_file, nfft=1024, wfft=512, nhop=256)
linspec.feature_plot(dbscale=True)
title('Wide-band Linear Spectrum')
Play the audio_file using the built-in play() command”:
x,sr,fmt = wavread(audio_file) # load the audio file
play(x, sr) # play it
Invert the short-time Fourier transform back to audio using the feature inverse() method.
x_hat = linspec.inverse(usewin=0) # invert features to audio (use original phases, no windowing)
play(x_hat)
Extract the log-frequency spectrum, specifying windowing parameters:
logspec = LogFrequencySpectrum(audio_file, nhop=2205) # extract log spectrum
logspec.feature_plot(dbscale=True) # plot features on dB scale
title('Narrow-band Log Spectrum')
Invert the log spectrum using the feature inverse() method. The log-frequency spectrum does not contain complete information so we’ll need to estimate the phases, via the pvoc=True flag, and use a reconstruction window, usewin=True. The signal should also be balanced to ensure no clipping on audio output.
x_hat = logspec.inverse(pvoc=True) # invert phaseless features to audio
play(balance_signal(x_hat),sr) # play inverted features
Inspect the default feature parameters and features module help:
# list the (default) parameters that control feature extraction."
Features.default_params() # inspect default parameters
help(features) # see help on the features module
List the tutorials and run one:
# show list of tutorials:
get_tutorials()
# execute the first tutorial (1. features)
execfile(get_tutorials()[1])