# FFT.forward equivalent for AudioSample

**URL:** https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464
**Category:** Libraries
**Created:** [April 18, 2021, 3:03am UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464 "2021-04-18T03:03:01Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![indicator\_red](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@indicator\_red](https://discourse.processing.org/u/indicator_red)
#### Post date: [April 18, 2021, 3:03am UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/1 "2021-04-18T03:03:01Z")

</div>

Hello, I am attempting to get audio/video sync working for exporting a music visualization. I’m working with this demo script from VideoExport:[withAudioViz.pde](https://github.com/hamoid/video_export_processing/blob/master/examples/withAudioViz/withAudioViz.pde).

I am able to generate the analysis .txt file and get the synced example. However, I am attempting to integrate with this visualizer [ProcessingCubes](https://github.com/samuellapointe/ProcessingCubes/blob/master/cubes.pde) and having some issues.

The crux of my issue is that the VideoExport example is bucketing the fft output from the AudioSample while the visualization script is parsing the fft.getband() data directly. Is it possible to do something similar to fft.forward() with AudioSample? It doesn’t appear to have this capability. Sorry if this is a bit hard to follow, happy to give additional information or follow up. Thank you!

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [April 18, 2021, 9:04am UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/2 "2021-04-18T09:04:45Z")

</div>

hi! welcome to the forum! It would be helpful if you can share what you already tried.

Also ping @hamoid as he perhaps knows something 🙂

---

<div class="post-metadata">

### Author: ![indicator\_red](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@indicator\_red](https://discourse.processing.org/u/indicator_red)
#### Post date: [April 18, 2021, 6:25pm UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/3 "2021-04-18T18:25:12Z")

</div>

Sure, I will try to write some notes on the current state. Mostly I’ve just been looking at print statements to try to find parity between the bucketing procedure done in withAudioViz.pde and the cubes.pde .

**For cubes:**

```auto
Minim minim;
AudioPlayer song;
FFT fft;

minim = new Minim(this);

song = minim.loadFile(song_path);
song.play(0);

Then in the draw function the below is called:
//This moves the buffer read forward in the AudioPlayer song object
fft.forward(song.mix);

fft.getBand() calls are then used to extract the magnitudes of the different frequency bands. Our buffer size for the AudioPlayer is 1024, so there are 513 frequency bands.

```

* * *

**For withAudioViz:**

```auto
//This loads an *AudioSample* of the track with the same buffer size as with cubes.
 AudioSample track = minim.loadSample(fileName, 1024);

//Creates a new fft object with the track parameters
fft = new FFT(track.bufferSize(), track.sampleRate());

```

–

At this point I’m a bit stuck because there’s no equivalent .forward method for AudioSample. I need to figure out how to move the sample window to do the cubes processing on the Sample fft data.

I will tag @hamoid to say this is an awesome library and the example is super helpful so thank you! The issue I’m having is the bucketing in withAudioViz is sort of off from the spectrum processing that I’m hoping to achieve with the synced cubes.pde visualization.

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [April 18, 2021, 8:16pm UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/4 "2021-04-18T20:16:07Z")

</div>

cool but please use `</>` button to format your code! (even if it’s a snippet)

I haven’t tried any code but basically what you want to do is to move forward at the fixed rate so that you can render sequential images - is it correct? Assuming that is the case, I checked some examples and with `AudioSample` you can extract the float array:

> <https://github.com/ddf/Minim/blob/v2.2.2/examples/Advanced/AudioSampleGetChannel/AudioSampleGetChannel.pde#L23>

and you can pass an array to run FFT on with specified offset (`startAt`)

> <https://github.com/ddf/Minim/blob/v2.2.2/src/ddf/minim/analysis/FFT.java#L281>

so I’m guessing that you need to move `startAt` at a fixed rate - which is perhaps `floor(sampleRate / fps)` where fps is the framerate of the output video.

---

<div class="post-metadata">

### Author: ![indicator\_red](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@indicator\_red](https://discourse.processing.org/u/indicator_red)
#### Post date: [April 18, 2021, 10:34pm UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/5 "2021-04-18T22:34:35Z")

</div>

Thank you for the formatting guidance. I will be sure to format code in posts as such going forward.

I think you’re on the right track with the startAt offset read windows. I’ve been looking at AudioStream as a possibility too. Do you know if there’s a getChannel equivalent for mix rather than LEFT or RIGHT? Thank you again for posting with me, definitely learning a lot about minim & fft.

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [April 18, 2021, 10:43pm UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/6 "2021-04-18T22:43:31Z")

</div>

> equivalent for mix rather than LEFT or RIGHT?

I don’t know. But since you are not doing it real time, I would simply edit the sound with an external tool (like audacity) or compute it within Processing (simply take two arrays and generate an averaged array)

---

<div class="post-metadata">

### Author: ![indicator\_red](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@indicator\_red](https://discourse.processing.org/u/indicator_red)
#### Post date: [April 18, 2021, 11:07pm UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/7 "2021-04-18T23:07:57Z")

</div>

I agree that taking the average would be a good workaround.

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [April 19, 2021, 9:55am UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/8 "2021-04-19T09:55:01Z")

</div>

Hi hi,

I tried reading the thread but I’m not sure I understand the issue 🙂 Is one issue that the two FFT implementations give different values? In the example I use `logAverages` but there’s also `linAverages`, in case that makes a difference: [FFT](http://code.compartmental.net/minim/javadoc/ddf/minim/analysis/FFT.html)

Ah… Maybe I get it now: you prefer the values you are getting from the standard Processing audio library in real time, and you want a way to get those values not-in-real-time, the same way you get them when using Minim. Right?

In recent years I haven’t use this approach, but used [https://sonicvisualiser.org/](https://sonicvisualiser.org/) instead. It has tons of plugins for different types of analysis, and has also a command line version you could use to automate converting audio files to text files.

Unfortunately I can’t help much with the standard audio library.

Cheers 🙂

---

<div class="post-metadata">

### Author: ![indicator\_red](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@indicator\_red](https://discourse.processing.org/u/indicator_red)
#### Post date: [April 20, 2021, 2:55am UTC](https://discourse.processing.org/t/fft-forward-equivalent-for-audiosample/29464/9 "2021-04-20T02:55:17Z")

</div>

Hi hamoid, thanks for following up.

After many print statements and reading of the minim documentation I have figured it out! So for the ProcessingCubes the visualization iterates over the specSize() bands (513 because of the 1024 buffersize).

In your example logAverages causes the FFT array to contain 30 bands, by setting fftSlices to 513 and averaging the right and left channel values each slice is an array of 513. I tried linAverages but it didn’t agree with the code (more testing might help here), I just used getBand once I had the desired parameters of the .txt sorted to the chunks and slices.

By modifying the ProcessingCubes code to iterate over the array values rather than getBand()'s of a live fft I can parse the .txt into the visualizer. With your while logic I’m able to generate synced A/V.

I definitely learned a lot through this process and am pleased with the results. I’ll write some comments up on the withAudioViz example for how it can be modified to generate specSize arrays rather than logAverage ones and begin working on a de novo viz for my tunes.

Thank you again for your help micuat and hamoid.
