TarsosDSP: a Java Library for Audio Processing
TarsosDSP is a Java library for audio processing. Its aim is to provide an easy-to-use interface to practical music processing algorithms implemented, as simply as possible, in pure...
Below you can find links to the open source software I developed during my research. It is always nice to hear how this software is used, don’t hesitate to drop me a line. Bug reports are welcomed as well.
TarsosDSP is a Java library for audio processing. Its aim is to provide an easy-to-use interface to practical music processing algorithms implemented, as simply as possible, in pure...
MI-Kit is a low-cost, open-source system for controlling music production software through body movement. Designed for creative music practice and embodied music interaction research. EMI-Kit can be used...
Panako is an extendable acoustic fingerprinting framework. The aim of acoustic fingerprinting is to find small audio fragments in large audio databases. Panako contains several acoustic fingerprinting algorithms...
Olaf is a portable, landmark-based, acoustic fingerprinting system released as open source software. Olaf runs on embedded platforms, traditional computers and in the browser. Olaf is able to...
mot consists of several MIDI and OSC command line tools. These are mainly of interest to debug and check OSC messages and MIDI devices. The tools are written...
Thanks to WebAssembly it is possible to repurpose software for use on the web, even if it was originally designed with other use in mind. I have developed...
This library calculates fine-grained constant-Q spectral representations of audio signals quickly from Java. The spectral transform can be visualized or further processed in a (Music Information Retrieval) processing...
SyncSink is able to synchronize video and audio recordings of the same event. As long as some audio is shared between the multimedia files a reliable synchronization solution...
Tarsos is a software tool to analyze and experiment with pitch organization in all kinds of musics. Most of the analysis is done using pitch histograms and octave...
TarsosLSH is a Java library implementing Locality-sensitive Hashing (LSH), a practical nearest neighbor search algorithm for multidimensional vectors that operates in sublinear time. It supports several LSH families:...
TeensyDAQ is a Java application to quickly visualize and record analog signals with a Teensy micro-controller and some custom software. It is mainly useful to quickly get an...
The idea behind AMPEL (by Lousin Moumdjian, Marc Leman, Peter Feys) is to combine both motor and cognitive rehabilitation in a single combined ‘embodied learning’ paradigm. To this...
The Pidato experiment demonstrates a rather straightforward method to handle vibrato on a digital piano. It ‘solves’ the age-old problem on what to do with the enigmatic “vibrato”...
Vorige zaterdag werd Apps For Ghent georganiseerd: een activiteit om het belang van open data te onderstrepen in navolging van onder meer Apps For Amsterdam en New York City Big App. Tijdens de voormiddag kwamen er verschillende organisaties hun open gestelde data voorstellen de namiddag werd gereserveerd voor een wedstrijd. Het doel van de wedstrijd was om in enkele uren een concept uit te werken en meteen voor te stellen. Het uitgewerkte prototype moest gedeeltelijk functioneren en gebruik maken van (Gentse) open data.
Luk Verhelst en ikzelf hebben er TwinSeats voorgesteld.
TwinSeats is een website / online initiatief om nieuwe mensen te leren kennen. Met hen deel je dezelfde culturele interesse en ga je vervolgens samen naar deze of gene voorstelling. Door events centraal te stellen kan TwinSeats uitzonderlijke cultuurburen zoeken. Leden vinden die cultuurburen dankzij een gezamenlijke voorliefde voor een artiest of attractie of eender welke bezigheid in de vrijetijdssfeer.
Het prototype is ondertussen terug te vinden op TwinSeats.be. Let wel dit is in enkele uren in elkaar geflanst en is verre van ‘af’, het achterliggende concept is belangrijker.
Samen met Wa Kank Doen van SumoCoders werden we door de jury tot winnaar uitgeroepen. Maandag verscheen er een artikel in de Standaard over AppsForGhent met een vermelding van TwinSeats. Op de Apps For Ghent site is uiteraard ook iets te vinden over TwinSeats ook het juryverslag is er te vinden. Zoals het hoort bij die categorie evenementen werd ook wat afgetweet.
Er is ook een publieksprijs verbonden aan AppsForGhent die wordt over enkele weken uitgereikt.
TarsosDSP is a collection of classes to do simple audio processing. It features an implementation of a percussion onset detector and two pitch detection algorithms: Yin and the Mcleod Pitch method.
Its aim is to provide a simple interface to some audio (signal) processing algorithms implemented in JAVA.
To make some of the possibilities clear I coded some examples.
“TarsosDSP UtterAsterisk”:[UtterAsterisk.jar] a game that shows real-time pitch detection with YIN.
“TarsosDSP Sound Detector”:[SoundDetector.jar] is simply to show how to react when (loud) sound is available.
“TarsosDSP Percussion Detector”:[PercussionDetector.jar] is capable of detecting percussion onsets using the method described here. It plays a sound from freesound.org when percussion is detected.
The source code of TarsosDSP is available on github.
Saturday the 25th of March TarsosDSP was presented at Newline, a small conference organized by whitespace. Here you can download “the slides I used to present TarsosDSP”:[tarsosDSP_presentation.pdf], I also created “an introductory text on sound and Java”:[sound_and_java.pdf].

With this post I would like to draw attention to the fact that remote port forwarding with OpenSSH 4.7 on Ubuntu 8.04.1 does not work as expected.
If you follow the instructions of a SSH remote port forwarding tutorial everything goes well until you want to allow everyone to access the forwarded port (not just localhost). The problem arises when binding the forwarded port to an interface. Even with GatewayPorts yes present in /etc/ssh/sshd_config the following command shows that it went wrong:
```ruby\ user@local$ssh -R 2222:localhost:22 user@remote\ user@remote$sudo netstat -lntp #on the remote server\ Active Internet connections (only servers)\ Proto Recv-Q Send-Q Local Address Foreign Address State\ tcp6 0 0 ::1:2222 :::* LISTEN\ ```
It listens only via IPv6 and only on localhost an not on every interface (as per request by defining GatewayPorts yes). The netstat command should yield this output:
```ruby\ user@local$ssh -R 2222:localhost:22 user@remote\ user@remote$sudo netstat -lntp #on the remote server\ Active Internet connections (only servers)\ Proto Recv-Q Send-Q Local Address Foreign Address State\ tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN\ ```
I do not really know here it goes wrong but there is an easy workaround. By defining both
```ruby\ GatewayPorts yes\ AddressFamily inet\ ```
in /etc/ssh/sshd_config remote port forwarding works fine but you lose IPv6 connectivity (this due to the AddressFamily setting). Another solution is to use more up to date software: the bug is not present in Ubuntu 10.04 with OpenSSH 5.3 (I don’t know if it is an Ubuntu or OpenSSH bug, or even a configuration issue.
I have been struggling with this issue for a couple of hours and, with this blog post, I hope I can prevent someone else from doing the same.
ssh-copy-id is a practical bash script, installed by default on Ubuntu. The script is used to distribute public keys. The following oneliner makes it available on Mac OS X:
```ruby\ sudo bash < <( curl —silent http://0110.be[install-ssh-copy-id.bash] )\ ```\ This oneliner does three things:
It copies ssh-copy-id from this website to /bin/ssh-copy-id.
It makes sure that ssh-copy-id is executable, using chmod.
There is no three
The install procedure needs superuser rights because it writes in the /bin folder. Executing scripts from untrusted sources with superuser rights is actually really, really, extremely dangerous. But in this case it is rather innocent.
The ssh-copy-id script is the one provided with Ubuntu and Debian, I assume it is GPL’ed. I have not modified it for Mac OS X but it seems to behave as expected. I have only tested the install script and behavior on 10.6.5, YMMV (Your Mileage May Vary).

There is more to Tarsos then meets te eye. The graphical user interface only exposes some functionality; the API (Application Programmer Interface) exposes all of Tarsos’ capabilities.
Tarsos is programmed in Java so the API is accessible trough Java and other programming languages targeting the JVM (Java Virtual Machine) like JRuby, Scala and Groovy. The following examples use the Groovy programming language because I find it the most aesthetically pleasing with regards to interoperability and it gets the job done without getting in your way.
To run the examples a copy of the Tarsos JAR-file needs to be added to the Classpath and the Groovy runtime must be installed correctly. I’ll leave this as an exercise for the reader: godspeed to you, brave soul. Quick protip: placing a copy of the jar in the extensions directory seems to work best, e.g. see important java directories on mac OS X.
The first example extracts pitch class histograms from a bunch of files and saves them as EPS (Encapsulated PostScript)-files. It iterates a directory recursively and handles each file that matches a given regular expression. In this example the regular expression matches all WAV-files. Batch processing is one of those things scripting is ideal for, doing the same thing with the user interface would be tedious or even mind-numbingly boring, not groovy at all indeed.
```ruby\ import be.hogent.tarsos.*\ import be.hogent.tarsos.util.*\ import be.hogent.tarsos.util.histogram.ToneScaleHistogram\ import be.hogent.tarsos.sampled.pitch.Annotation\ import be.hogent.tarsos.sampled.pitch.PitchDetectionMode
dir = “/home/joren/audio”
FileUtils.glob(dir,”.*.wav”,true).each { file ->\ audioFile = new AudioFile(file)\ pitchDetector = PitchDetectionMode.TARSOS_YIN.getPitchDetector(audioFile)\ pitchDetector.executePitchDetection()\ //get some annotations\ annotations = pitchDetector.getAnnotations()\ //create an ambitus and tone scale histogram\ ambitusHistogram = Annotation.ambitusHistogram(annotations)\ toneScaleHisto = ambitusHistogram.toneScaleHistogram()\ //plot a smoothed version of the histogram\ p = new SimplePlot()\ p.addData 0, toneScaleHisto.gaussianSmooth(0.2)\ p.save FileUtils.basename( file) + “.eps”\ }\ ```
The second example uses functionality that is currently only available trough the API. It takes a MIDI-file and synthesizes it to a wave file using an arbitrary scale. In this case 10-TET. The heavy-work is done by the Gervill synthesizer. The resulting file is available for download, micro—macro?—tonal Bach is great: “BWV 1013 in 10-TET”:[BWV_1013_10-TET.mp3]. The result of “an analysis with Tarsos on the synthesized audio”:[120.png] clearly shows an interval of 120 cents with some deviations.
```ruby\ import java.io.File\ import be.hogent.tarsos.midi.MidiToWavRenderer\ import be.hogent.tarsos.util.ScalaFile
midiFile = new File(“BWV_1013.mid”)\ outFile = new File(“out.wav”)
tuning = [0,120,240,360,480,600,720,840,960,1080] as double []
MidiToWavRenderer renderer\ renderer = new MidiToWavRenderer()\ renderer.setTuning(tuning)\ renderer.createWavFile(midiFile, outFile)\ ```
An extended version of this second example script could be used to generate a dataset with audio and corresponding tone scale information on the fly. The dataset could then be used as a baseline.
The API is not yet well documented and is still in flux or more correctly: superflux. Note to self: I will provide documentation and a number of useful examples when the dust settles down. I’m not even sure if I will stick with Groovy. Scala has a nice Lispy feel to it and seems more developed. Groovy has a less steep learning curve, especially if you have some experience with Ruby. JRuby is also nice but the interoperability with legacy Java looks like an ugly hack.
This post describes a crucial aspect of how to connect an android phone, the LG GT540 Optimus, to an Ubunu Linux computer. The method is probably similar on different UNIX like platforms with different phones.
To recognize the phone when it is connected via usb you need to create an UDEV rule. Create the file /etc/udev/rules.d/29.lg545.rules with following contents:
```ruby\ SUBSYSTEM"usb",ATTRS{idVendor}”1004”,ATTRS{idProduct}==”61b4”,MODE=”0666”\ ```
On the phone you need to enable debugging using the settings and (this is rather important) make sure that the “mass storage only” setting is disabled.
Rooting the device makes sure you have superuser rights. Installing the android SDK is well documented.
Good luck!
This post is about the tools I use to keep the source code of Tarsos reasonably clean, consistent and readable. Static code analysis can be of great help if you want to maintain strict coding standards and follow language idioms. Some of the patterns they can detect for you:
Dead code - unused variables, parameters, methods
Suboptimal code - wasteful resource usage
Overcomplicated expressions - unnecessary if statements, for loops that could be while loops
Duplicate code - copied/pasted code is a code smell.
Formatting inconsistencies, e.g. variable modifier order
And even more subtle, but equally important:
Resource management: is a resource handled (closed) correctly on all possible code paths?
Abstraction level: is it needed to expose the concrete type of an object or could an (abstract) supertype or even an interface be used instead?
…
In a previous life I used .NET and the static code analysis tools FxCop & StyleCop. FxCop operates on bytecode (or intermediate language in .NET parlance) level, StyleCop analyses the source code itself. Tarsos uses JAVA so I looked for JAVA alternatives and found a few.
PMD & Checkstyle both operate on source code level.
FindBugs operates on bytecode level.
On freesoftwaremagazine.com there is an article series on JAVA static code analysis software. It covers PMD and FixBugs and integration in Eclipse. It does not cover Checkstyle. Checkstyle is essentialy the same as PMD but it is better integrated in eclipse: it checks code on save and uses the standard ‘Problems’ interface, PMD does not.
To fix problems Eclipse save actions can save you some time. IBM has an article on how to keep your code clean using Eclipse.
Continuous testing is also a really nice thing to have: detecting unexpected behavior while refactoring/programming can prevent unnecessary bug hunts. A video about immediate feedback using continuous testing makes this clear.
Another tip is a more philosophical one: making your code and code revisions publicly available makes you think twice before implementing (and subsequently publishing) a quick and dirty hack. Tarsos is available on github.
The problem: There is a group of people that want access to Hackerspace Ghent but there is only one remote to open the gate.
The solution: Build a system that reacts to a phone call by opening the gate if the number of the caller is whitelisted.
What you need:
A BeagleBoard or some BeagleBoard alternative with a Linux distribution running on it. Any server running a unix like operating system should be usable.
A Huaweii e220 or an alternative GSM that supports (a subset of) AT commands and has a USB port.
A team of hackers that know how to solder something togeher. E.g. The hardware guys of hackerspace Ghent.
A “python script”:[gatekeeper.py] that reacts to calls.
The Hack: First of all try to get caller id working by following the Caller ID with Linux and Huawei e220 tutorial. If this works you can listen to the serial communication using pySerial and react to a call. The following python code shows the wait for call method:
```ruby\ def wait_for_call(self):\ self.data_channel.open()\ call_id_pattern = re.compile(‘.CLIP.”\+([0-9]+)”,.*’)\ while True:\ bytes = self.data_channel.inWaiting()\ buffer = self.data_channel.readline(bytes)\ call_id_match = call_id_pattern.match(buffer)\ if call_id_match:\ number = call_id_match.group(1)\ self.handle_call(number)\ ```
The handle_call method … handles the call.
The second thing that is needed is a way to send a signal from the beagle board to the remote. Sending a signal from the beagle board using Linux is really simple. The following bash commands initialize, activate and deactivate a pin.
```ruby\ echo 168 > /sys/class/gpio/export\ echo “high” > /sys/class/gpio/gpio168/direction\ echo “low” > /sys/class/gpio/gpio168/direction\ ```
Today I created a spectrogram application using Tarsos. The application listens to an audio input, computes an FFT and at the same time calculates pitch. The expected pitch is overlaid on the spectrogram. All this happens real-time and is implemented using JAVA.

This is the most recent version of the spectrogram implementation in java.
```java\ float pitch = Yin.processBuffer(buffer, (float) sampleRate);\ fft.transform(buffer);\ double maxAmplitude = 0;\ for (int j = 0; j < buffer.length / 2; j) {\ double amplitude = buffer[j] * buffer[j] + buffer[j +\ buffer.length/2] * buffer[j+ buffer.length/2];\ amplitude = Math.pow(amplitude, 0.5);\ colorIndexes[j] = amplitude;\ maxAmplitude = Math.max(amplitude, maxAmplitude);\ }\ ```
If you want to test it yourself download the “spectrogram jar package”:[spectrogram.jar] and execute:
```ruby\ java -jar spectrogram.jar\ ```
This is the scenario: you have a Huawei e220, a linux computer and you want to react to a call from a set of predefined numbers. E.g. ordering a pizza when you receive a call from a certain number.
The Huawei e220 supports a subset of the AT commands, which subset is an enterprise secret of te Huawei company. So there is no documentation available for the device I bought, thanks Huawei. Anyhow when you attach the e220 to a Linux machine you should get two serial ports:
```ruby\ /dev/ttyUSB0\ /dev/ttyUSB1\ ```
To connect to the devices you can use a serial client. GNU Screen can be used as a serial client like this: screen /dev/ttyUSB0 115200. The first device, ttyUSB0 is used to control ttyUSB1, so to enable caller ID on te Huawei e220 you need to send this message to ttyUSB0:
```ruby\ AT+CLIP=1\ ```
To check for calls you should listen to ttyUSB1. A serial session for ttyUSB1 looks like:
```ruby\ \^BOOT:44594282,0,0,0,6\ \^RSSI:18\ RING\ +CLIP: “+33499311152”,145,,,,0\ \^BOOT:44594282,0,0,0,6\ ```
The RING and CLIP messages are the most interesting. The RING signifies an incoming call, the CLIP is the caller ID. The BOOT and RSSI are some kind of ping messages. The following Python script demonstrates a complete session that enables caller ID, waits for a phone call and prints the number of the caller.
```python\ #!/usr/bin/env python\ import serial, re
command_channel = serial.Serial(\ port=’/dev/ttyUSB0’,\ baudrate=115200,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS\ )\ command_channel.open()\ #enable caller id\ command_channel.write(“AT+CLIP=1” + “\r\n”)\ command_channel.close()
ser = serial.Serial(\ port=’/dev/ttyUSB1’,\ baudrate=9600,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS\ )
ser.open()
pattern = re.compile(‘.CLIP.”\+([0-9]+)”,.*’)
while 1:\ buffer = ser.read(ser.inWaiting()).strip()\ buffer = buffer.replace(“\n”,””)\ match = pattern.match(buffer)\ if match:\ number = match.group(1)\ print number\ ```