ComParser
index
  ComParser  1.42
  source code
ComParser

ComParser is written in platform independant ISO/ANSI C as far as possible. Platform dependant code (for audio, midi, and user i/o) is kept in separate files and directories, away from the core ComParser code, which consists of: The commandline version of ComParser relies on Portaudio for realtime audio input. In the current implementation, the callback routine forms the background thread that runs the preprocessing layer, while the foreground thread, which also handles incoming MIDI events and the communication with the user, runs our spatiotemporal layer.

Under UNIX, this approach works fine (foreground process does not get interrupted too much). On the Macintosh, however, the spatiotemporal process may get hindered by concurrent processes (user-clicks, mouse, MacOS, other applications, etc). So for the Macintosh implementation we'd better move the avalanche-code to the background (in which case an overload-protection must be built in), or a separate, third thread must be created for it.

 
Background thread:
(Portaudio callback routine)

Realtime audio input in chunks of 512, 1024 or 2048 sampleframes, at any user-selectable samplerate).
Apply 100% overlapping Hamming window (windowsize = 1024 samples).
Perform 1024, 2048, or 4096 point, real-input, FFT (always yielding 513 squared magnitudes (any higher bins are thrown away)).
Reorganize FFT output on to a (more or less) logarithmic frequency scale with the 'varidist' or 'equidist' algorithm. For example 27 equidist bands (minor thirds) or 60 varidist bands (slightly narrowing, from major third up to minor second).
Include some more linear measurements like RMS and peak magnitude and normalize the composite input vector.
Store vectors in a large circular buffer in RAM (storage for 1 hour just takes some Megabytes).

 
Foreground thread:

Run the following network which reads from the large circular buffer in RAM that is filled by the background process.
Perform simultaneous audio recording to file (again large circular buffer in RAM that is filled by the background process).
Send out MIDI messages when audio fragments are recognized.
Process user commands from the console.
Process incoming MIDI events.
In case of errors, report these on the console (or file).

  fig.3: Preprocessing and spatiotemporal layers are run as separate processes.

MIDI i/o has been implemented for Silicon Graphics IRIX and for Apple Macintosh (OS 7,8,9) OMS. Stephane Letz contributed MidiShare support, which may be helpfull for the Linux, Windows, and OSX implementations. Many thanks!

Contrary to the standalone version of ComParser, the PD external runs both the preprocessor and the neural network in the same thread.

Project guidelines / standards / choices made

Download source code

The latest version of ComParser may be downloaded from http://kmt.hku.nl/~pieter/SOFT/CMP.

download CMP as gzipped tar-file CMP1.42.tar.gz Complete ComParser sources, binaries and documentation, version 1.42, tarred and gzipped (about 5 Megabytes).

After unpacking this, subdirectory '/src' should look something like this
(below, files can also be viewed or downloaded individually):

subdirectory aiff To read and write audiofiles in AIFF format (endian-safe).
C source CMP.c Main() for the standalone ComParser.
C header CMP.h Version number, included by both the standalone ComParser and the PD external.
C source CMP_audiorecord.c Record audiofile while following (handy during rehearsels with musicians).
C header CMP_audiorecord.h Headerfile.
C source CMP_avalanche.c To write and read avalanche files.
C header CMP_avalanche.h Headerfile defining memory and file structures.
C source CMP_network.c To load network files in memory (linked list management).
C header CMP_network.h Headerfile defining internal memory structure and the network file format.
C source CMP_portaudio.c Realtime analysis object (wrapping the PREP with PortAudio).
C header CMP_portaudio.h Datastructures and constants for realtime audio analysis based on PortAudio.
C source CMP_prep.c Implements preprocessing object (delivers feature vectors).
C header CMP_prep.h C API header for audio preprocessor.
subdirectory console/ Platform specific code for polling console-input (done SGI and Mac).
Quite clumsy, actually... We'd better create a separate 3rd thread for the spatiotemporal layer, instead of avoiding blocking fgets-calls.
subdirectory fft/ FFT code and code-generators from Eyal Lebedinsky.
subdirectory gt/ Minimal graphic toolkit for drawing and writing (not reading) JPG-files. Incorporates the compression-part of the JPEG-library from the Independent JPEG Group (version 6b, 27-Mar-1998). Include source gt/gt.c in the compiler-project.
subdirectory midi/ MIDI API. Support for SGI and Mac-OMS and a generous gift from Stephane Letz for MidiShare support.
subdirectory pd The comparser~ external for Pure Data (sourcecode, PD-helpfile plus precompiled binaries).
subdirectory portaudio Copy of the portable audio library by Phil Burk and Ross Bencina (renamed 'index.html'), version 18 (CVS-patch).
UNIX script makefile To compile the standalone program and the PD-external under IRIX, Linux and Mac OSX.
Binhexed self extracting archive for Mac macCW.sit.hqx To compile on Apple Macintosh, OS 7, 8 or 9. Contains a projectfile for the Metrowerks Codewarrior compiler, version 5 (IDE version 4.0); a picture resource; and some additional sources (for strdup(), usleep() etc).

Older versions

Some of the older versions are kept available. All versions up to 1.30 compile under IRIX and Mac OS 7.6 to 9 and use the portaudio v18 API. All tarred and gzipped packages contain full sources, documentation and some precompiled binaries.

Contributions