---
title: 'Between: 2014/08/01 en 2014/08/31 - 0110.be'
canonical: https://0110.be/date/2014/8
markdown_url: https://0110.be/date/2014/8.md
page: 0
posts_per_page: 30
total_posts: 2
filters:
  year: 2014
  month: 8
previous:
next:
---

# Between: 2014/08/01 en 2014/08/31 - 0110.be

## [TarsosDSP on Android - Audio Processing in Java on Android](https://0110.be/posts/TarsosDSP_on_Android_-_Audio_Processing_in_Java_on_Android.md)

- Published: 2014-08-14T00:00:00Z
- Updated: 2025-11-29T22:28:08Z
- Author: Joren
- ID: 420
- Canonical: https://0110.be/posts/TarsosDSP_on_Android_-_Audio_Processing_in_Java_on_Android

- Tags: [TarsosDSP](https://0110.be/tags/TarsosDSP.md), [UGent](https://0110.be/tags/UGent.md)

<img src="https://0110.be/files/attachments/420/android-audio.jpg"  width="20%" alt="Audio on Android" style="float:right;margin-left:1.5rem;margin-bottom:1.5rem"/>This post explains how to get TarsosDSP running on Android. 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 Java and without any other external dependencies.

Since version 2.0 there are no more references to `javax.sound.*` in the TarsosDSP core codebase. This makes it easy to run TarsosDSP on Android. Audio Input/Output operations that depend on either the JVM or Dalvik runtime have been abstracted and removed from the core. For each runtime target a Jar file is provided in the [TarsosDSP release directory](https://0110.be/releases/TarsosDSP).

The source code for the [audio I/O on the JVM](https://github.com/JorenSix/TarsosDSP/tree/master/jvm/be/tarsos/dsp/io/jvm) and the [audio I/O on Android](https://github.com/JorenSix/TarsosDSP/tree/master/android/be/tarsos/dsp/io/android) can be found on GitHub. To get an audio processing algorithm working on Android the only thing that is needed is to place [`TarsosDSP-Android-2.0.jar`](https://0110.be/releases/TarsosDSP/TarsosDSP-2.0/TarsosDSP-Android-2.0.jar) in the `lib` directory of your project.

The following example connects an `AudioDispatcher` to the microphone of an Android device. Subsequently, a real-time pitch detection algorithm is added to the processing chain. The detected pitch in Hertz is printed on a `TextView` element, if no pitch is present in the incoming sound, --1 is printed. To test the application download and install the https://0110.be/files/attachments/420/TarsosDSPAndroid.apk(https://0110.be/files/attachments/420/TarsosDSPAndroid.apk) application on your Android device. The [source code](https://0110.be/files/attachments/420/TarsosDSPAndroid.zip) is available as well.

````java
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
PitchDetectionHandler pdh = new PitchDetectionHandler() {
    @Override
    public void handlePitch(PitchDetectionResult result, AudioEvent e) {
        final float pitchInHz = result.getPitch();
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                TextView text = (TextView) findViewById(R.id.textView1);
                text.setText("" + pitchInHz);
            }
        });
    }
};
AudioProcessor p = new PitchProcessor(PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(p);
new Thread(dispatcher, "Audio Dispatcher").start();
````

Thanks to these changes, the fork of TarsosDSP kindly provided by GitHub user [srubin](https://github.com/srubin/TarsosDSP), created for [a programming assignment at UC Berkley](http://husk.eecs.berkeley.edu/courses/cs160-sp14/index.php/Individual_Programming_Assignment_3), is not needed any more.

Have fun hacking audio on Android!


- [android-audio.jpg](https://0110.be/files/attachments/420/android-audio.jpg)

- [TarsosDSPAndroid.apk](https://0110.be/files/attachments/420/TarsosDSPAndroid.apk)

- [TarsosDSPAndroid.zip](https://0110.be/files/attachments/420/TarsosDSPAndroid.zip)

---

## [Haar Wavlet Transform in TarsosDSP](https://0110.be/posts/Haar_Wavlet_Transform_in_TarsosDSP.md)

- Published: 2014-08-08T00:00:00Z
- Updated: 2014-08-08T13:01:02Z
- Author: Joren
- ID: 422
- Canonical: https://0110.be/posts/Haar_Wavlet_Transform_in_TarsosDSP

- Tags: [TarsosDSP](https://0110.be/tags/TarsosDSP.md), [UGent](https://0110.be/tags/UGent.md)

<img src="https://0110.be/files/attachments/422/Haar_wavelet.svg" width="30%" style="float:right;margin: 10px 10px"> The TarsosDSP Java library for audio processing now contains an implementation of the [Haar Wavelet](https://en.wikipedia.org/wiki/Haar_wavelet) Transform. A discrete wavelet transform based on the Haar wavelet (depicted at the right). This reversible transform has some interesting properties and is practical in signal compression and for analyzing sudden transitions in a file. It can e.g. be used to detect edges in an image.

As an example use case of the Haar transform, a simple lossy audio compression algorithm is implemented in TarsosDSP. It compresses audio by dividing audio into bloks of 32 samples, transforming them using the Haar wavelet Transform and subsequently removing samples with the least difference between them. The last step is to reverse the transform and play the audio. The amount of compressed samples can be chosen between 0 (no compression) and 31 (no signal left). This crude lossy audio compression technique can save at least a tenth of samples without any noticeable effect. A way to store the audio and read it from disk is included as well.

The algorithm works in real time and an example application has been implemented which operates on an mp3 stream. To make this work immediately, the `avconv` tool needs to be on your system's path. Also implemented is a bit depth compressor, which shows the effect of (extreme) bit depth compression.

The example is available at the [TarsosDSP release directory](https://0110.be/releases/TarsosDSP), the code can be found on the [TarsosDSP github page](https://github.com/JorenSix/TarsosDSP).


![Haar Wavelet Audio Compression](https://0110.be/files/photos/422/haar_wavelet_audio_compression.png)

---
