FFTMAX Script and C++ project by Danny Mcauliffe ..............

Click on the Icon to download file ver 1.6

A Fast Fourier Transform (FFT) is an efficient algorithm to compute the DFT,Discrete Fourier Transform .FFTs are of great importance to a wide variety of applications,from digital signal processing to solving partial differential equations to algorithms for quickly multiplying large integers.

In many applications.The input data for the DFT are purely real, in .which case the outputs satisfy the symmetry X_{N-k} = X_k^*, and efficient FFT algorithms have been designed for this situation .One approach consists of taking an ordinary algorithm (e.g. Cooley-Tukey) and removing the redundant parts of the computation, saving roughly a factor of two in time and memory. Alternatively, it is possible to express an even -length real-input DFT as a complex DFT of half the length (whose real and imaginary parts are the even/odd elements of the original real data), followed by O(N ) post-processing operations.

The math behind DFT's's and FFT's goes on for sometime but we dont need to get into all that to be able to use the algorithm so lets forget the Math for now, if you dont have a clue as to what I'am talking about or you just want to know more about FFT's and how they work click on this Link

I have written a program in C++, the program reads an audio file then outputs data to a text file this data is a list from the Fast Fourier transform,The algorithm gives an output of levels from a group of bins set at diffrent frequencies.The 3d max script then reads the data file and animates a set of objects.I dumped the Window based app I was using before with this project now Im just using a simple console application this way I can run it in the background but best of all I can pass all of the controls over to max script.


The Program

Heres a simple explanation of how the program works ;

The program first reads it's arguments and sets its self up accordingly.Next the sound buffer fills up with all the Data Bytes from the audio files data chunk.Then from the sound buffer the Data Bytes pass to the FFT rotuine in 1024Kb chunks,you could say This rotuine spilts the audio into a set of frequency bands. there can be from 8 to 64 bands.The FFT rotuine returns its 1024 chunk back to the main program from here the data is scaled to a range of 0 to 256 then output to a text file along with a time stamp taken from working out how far along the wave file the FFT routine has passed . The stamp can be set to output time in 25 fps PAL or 30 fps NTSC. if theres still more audio data to be read the whole loop starts again if not then the program will exit. What you end up with is a file looking like the one below.I have cut this one down to save space but its just a small version of what you would get when running the program;

25
1
1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 5 6 8 10 16 39 178
2
1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 4 4 5 6 8 11 15 25 57 92 24 163
3
8 8 8 8 8 8 8 8 8 9 9 9 9 10 10 11 12 12 13 15 16 18 21 24 30 41 71 222 42 77 9 148
4
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 6 9 15 26 115 207 27 62 10 133
5
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 3 4 6 13 88 50 100 192 12 47 0 118
6
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 7 28 31 73 35 85 177 0 32 0 103
7
0 0 0 0 1 1 1 1 2 2 3 3 4 5 6 7 9 11 16 23 42 182 43 59 58 20 70 162 16 17 14 88
8
2 2 2 2 2 2 2 2 2 2 3 3 0 0 0 0 0 0 1 8 57 167 28 44 43 5 55 147 1 2 0 73
9
0 0 0 0 0 0 2 2 2 2 0 3 3 4 5 6 9 13 25 193 202 152 13 29 28 7 40 132 5 5 5 58
10
0 0 0 1 1 2 2 3 4 4 5 7 8 11 14 20 31 64 90 178 187 137 25 14 13 16 25 117 13 12 12 43
11
4 4 5 5 5 5 5 5 6 6 7 7 8 0 0 5 16 110 103 163 172 122 10 0 0 1 10 102 0 0 0 28
12
8 8 8 8 8 8 9 9 10 11 12 14 17 21 29 48 248 167 88 148 157 107 0 8 6 5 0 87 4 3 3 13
13
0 0 0 0 0 0 0 0 0 0 0 0 2 6 14 253 233 152 73 133 142 92 1 0 0 0 0 72 0 0 0 0
14
5 6 6 6 6 7 7 8 9 10 13 16 23 42 40 238 218 137 58 118 127 77 7 6 6 6 5 57 5 5 4 4
15
0 0 0 0 0 0 0 0 0 0 0 1 8 27 149 223 203 122 43 103 112 62 0 0 0 0 0 42 0 0 0 0
16
11 11 11 12 12 1 14 16 1 23 29 43 89 88 134 208 188 1 28 88 97 47 7 7 6 6 5 27 5 5 4 4
17
0 0 0 0 0 0 0 1 4 8 29 54 74 73 119 193 173 92 13 73 82 32 0 0 0 0 0 12 0 0 0 0
18
0 0 0 0 0 0 0 0 0 0 14 233 59 58 104 178 158 77 0 58 67 17 0 0 0 0 0 0 0 0 0 0
19
2 2 2 2 2 3 3 4 6 10 26 218 44 43 89 163 143 62 2 43 52 2 1 1 1 1 1 1 1 1 1 1
20
8 8 9 9 11 13 16 22 33 62 199 203 45 28 74 148 128 47 12 28 37 9 9 8 8 8 7 7 7 7 7 7
21
0 0 0 0 0 0 16 25 45 153 184 188 30 13 59 133 113 32 13 13 22 10 10 9 9 9 9 8 8 8 8 8
22
4 5 6 8 10 14 20 32 63 138 169 173 33 25 44 118 98 17 13 0 7 11 10 10 9 9 9 9 8 8 8 8
23
13 13 13 14 16 20 26 40 107 186 154 158 18 10 29 103 83 2 0 4 0 0 0 0 0 0 0 0 0 0 0 0
24
0 0 0 0 1 5 30 66 243 171 139 143 22 19 14 88 68 12 11 10 10 9 9 8 8 8 8 8 7 7 7 7
25
9 9 10 11 13 17 15 87 228 156 124 128 7 4 0 73 53 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

The 25 at the top is the amount of frames in the file.The rest of the lines are Frame then bin level data,Frame always being the first number of each line.so in this data file you can see there are 25 frames and 32 bin levels in each frame, so thats one second of data for PAL Video.


There are 4 arguments that need passing to the console app

Argument 1 Scale Mode; This can set 0,1,2 to give Magnitude Squared , Amplitude Scaled or Decibels db output.

Argument 2 Bin Amount ; This can set 0,1,2,3 to give 8,16,32 or 64 frequency Bins

Argument 3 Video Mode ; This can set 0,1 to give 25 PAL or 30 NTSC fps output.

Argument 4 F-back Amount ; This can set 0 to 9 to give 0 to 9 levels of how much effect the bins level in the last frame have on the new set of bins in front. it looks something like this ; New Bin Level = Old Bin Level - Feedback amount , Feedback amount being a float. it works as a sort of lag ,it may not be the best way to do it but it seems to work ok.


The Script

I could enter the arguments in by hand but as I will be using this with 3d max why not get Max Script to do all the work.The FFTMAX Script takes care of the arguments with a simple interface as you can see below.

With the script I can load a wave file set all the arguments and send them to the FFT program ,set max to PAL or NTSC then make a set of blocks and finally animate the blocks to the wave file, and all without leaving the script interface :) . infact it can animate most sets of objects therefore using the data I could control anything from the height of a box to the brightness of a light.

The wave file must be PCM 16bit, 44100khz and Mono or the FFT program wont read it correctly, most of the code for reading stereo files has been done but I just need a few more bits setting up plus a bit of time so I may get round to adding stereo support at some point,but untill then anything other than the correct file format could,and probbaly will cause read errors.

This script needs the Avguard MAXScript Extension Package to set the frame rate, you can get this from scriptspot.

Here's 6 frames from a test animation for more examples click the picture below.

 

You can download FFTMAX by clicking on the icon at the top of the page.I'am still working on this program and script so I will be updating this file from time to time.The script was wrote using max 9 but has been saved as a *.ms file so you can edit it if you need to.I will get round to making a better script but rightnow Im working on a better FFT program.if you do make a better script please let me know.


Version History

2005/04/10 ... .... .... ..... Came up with the idea for this script
2005/04/20 ...ver 1.0 .... Started writing the script and then did no more for some time
2006/08/15 ...ver 1.1 .... Got back to work on the script and started on the C++ part of the project
2007/07/07 ...ver 1.2.... Added control spinner so the user is able to select one band from the FFT output
2007/07/08 ...ver 1.3.... Added flex modifier option
2007/07/10 ...ver 1.4.... Added scale control and rotation control option
2007/07/20 ...ver 1.5.... Added basic Light control
2007/07/21 ...ver 1.6.... Added an Array control

 


To install the Script and FFTMAX.exe

Make a folder named FFTMAX in your Max script folder and place the two files from the rar file inside.


To use the script.

Load max and run the FFTMAX.ms Script

Step 1 Load a wave file, This file must be Uncompressed PCM 16Bit Mono 44100khz

Step 2 Set the Output Scale, Bin Count, Video Mode and Delay/lag Settings , note the Rotate and Scale tick boxes make sure you set at least one of the tick boxes or the script will not set any keys.

Step 3 Press the analyze button this will run FFTMAX.exe
Once the program is done the dos window will close.

Step 4 Press the create button this will make a set of blocks/Bins based on
the settings you made in Step 2.

Step 5 The last step is to press the set keys button.This step reads the data file made in Step 3 based on the settings made in Step 2 the result is it animates the set of blocks/Bins using the data in the data file. At the end of all of this you should have a set of blocks/Bins changing in height with the audio file.


 

Please note;
When you hit the analyze button a text file is created with a set amount of data in it.
Dont change any settings once you have hit the analyze button or you may get an error
because the data may not be right for the new settings, if you do need to change the settings
hit the analyze button once your done just to rewrite the data file.

This script needs the Avguard MAXScript Extension Package to set the frame rate, you can get this from scriptspot.


 

Need help ? Email Me

back to main page