---
title: Tarsos Spectrogram
canonical: https://0110.be/posts/Tarsos_Spectrogram
markdown_url: https://0110.be/posts/Tarsos_Spectrogram.md
id: 348
published_at: '2010-04-13T14:02:33Z'
updated_at: '2013-12-05T18:19:15Z'
author: Joren
tags:
- name: Code
  markdown_url: https://0110.be/tags/Code.md
- name: Computational ethnomusicology
  markdown_url: https://0110.be/tags/Computational%20ethnomusicology.md
- name: HoGent
  markdown_url: https://0110.be/tags/HoGent.md
- name: Java
  markdown_url: https://0110.be/tags/Java.md
- name: Music Information Retrieval
  markdown_url: https://0110.be/tags/Music%20Information%20Retrieval.md
- name: Tarsos
  markdown_url: https://0110.be/tags/Tarsos.md
---

# Tarsos Spectrogram

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.

<img src="https://0110.be/files/attachments/348/spectrum.png" alt="spectrum with pitch information (red)"/>

This is the most recent version of the [spectrogram implementation in java](http://github.com/JorenSix/Tarsos/blob/master/src/be/hogent/tarsos/ui/Spectrogram.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\
\`\`\`


- [spectrum.png](https://0110.be/files/attachments/348/spectrum.png)

- [spectrogram.jar](https://0110.be/files/attachments/348/spectrogram.jar)
