We are about to switch to a new forum software. Until then we have removed the registration on this forum.

- All Categories 25.7K
- Announcements & Guidelines 13
- Common Questions 30
- Using Processing 22.1K
- Programming Questions 12.2K
- Questions about Code 6.4K
- How To... 4.2K
- Hello Processing 72
- GLSL / Shaders 292
- Library Questions 4K
- Hardware, Integration & Other Languages 2.7K
- Kinect 668
- Arduino 1K
- Raspberry PI 188
- Questions about Modes 2K
- Android Mode 1.3K
- JavaScript Mode 413
- Python Mode 205
- Questions about Tools 100
- Espanol 5
- Developing Processing 548
- Create & Announce Libraries 211
- Create & Announce Modes 19
- Create & Announce Tools 29
- Summer of Code 2018 93
- Rails Girls Summer of Code 2017 3
- Summer of Code 2017 49
- Summer of Code 2016 4
- Summer of Code 2015 40
- Summer of Code 2014 22
- p5.js 1.6K
- p5.js Programming Questions 947
- p5.js Library Questions 315
- p5.js Development Questions 31
- General 1.4K
- Events & Opportunities 289
- General Discussion 365

I want to create audio visuals like the bars visual that is commonly used in music videos. Minim has an FFT that gets the amplitude of each frequency band, but each band is evenly spaced. So the result is that the bars are mostly showing only the high frequencies, and the mid and low frequencies are bunched up on the left. I tried this, but I'm not good with logarithms and have no clue what the correct math to calculate this should be, and it didn't really work:

```
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer song;
FFT fft;
// the number of lines/bands to draw
int bands = 512;
float a = (log(20000 - 20) / log(bands));
void setup()
{
size(512, 200);
minim = new Minim(this);
song = minim.loadFile("test.mp3", 2048);
song.loop();
fft = new FFT(song.bufferSize(), song.sampleRate());
}
void draw()
{
background(0);
stroke(255);
fft.forward(song.mix);
for(int i = 0; i < bands; i++)
{
// calculate the frequency for the current band on a logamorithmic scale
float freq = pow(i, a) + 20;
// get the amplitude at that frequency
float amplitude = fft.getFreq(freq);
// convert the amplitude to a DB value.
// this means values will range roughly from 0 for the loudest
// bands to some negative value.
float bandDB = 20 * log(2 * amplitude / fft.timeSize());
// so then we want to map our DB value to the height of the window
// given some reasonable range
float bandHeight = map( bandDB, 0, -150, 0, height );
// draw the band as a line
line(i, height, i, bandHeight);
}
}
```

I don't even know if it can be done using the FFT in Minim because there might not be enough bands calculated for the lower frequencies. If not, what can I use to accomplish this?

Tagged:

## Answers

Relevant to your post:

https://forum.processing.org/two/search?Search=octave

Kf

There's a logaverages in minim, does that do what you want?

http://code.compartmental.net/minim/fft_method_logaverages.html

Aha! This post answered my question:

https://forum.processing.org/two/discussion/comment/17292/#Comment_17292

My new code is:

I also want to mention that converting the amplitude to decibels gives a much better result for anyone else who wants to do this effect.