Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Program Announcements / FFTW wrapper for DBP

Author
Message
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 1st Feb 2012 08:49 Edited at: 7th Feb 2012 18:52
Hello everyone,

Although I have taken my leave from these forums a while ago, I still wanted to share this plugin with you.
Sometimes I use DBP for prototyping, and a week ago I had the need for an FFT algorithm in DBP (engineers like to work in the frequency domain). DBP doesn't have this (FFT's usually aren't needed for game development), so I searched the internet and found FFTW3 (http://www.fftw.org/) and made a wrapper for it.

I realize that the audience for this is quite small, but I still think it would be a good plugin for DBP to have.

Here are the commands


Notes
Attached is a zip file containing the DLL, keywords, constants and a PDF with information that comes with FFTW3. All commands use this prototype of C++ code:



where [create plan] corresponds to the command name in question:
fft -> fftwf_plan_dft_1d()
fft_2d -> fftwf_plan_dft_2d()
fft_3d -> fftwf_plan_dft_3d()
fft_r2c -> fftwf_plan_dft_r2c_1d()
...
with a 1 on 1 mapping of the parameters.
fft/ifft are the same as fft with Flags and Sign equal to FFTW_ESTIMATE and FFTW_FORWARD(fft)/FFT_BACKWARD(ifft).
fftr/ifftr are the same as fft_r2c/fft_c2r with the flag FFTW_ESTIMATE.

To provide easier access, I also included some commands to work with memblocks.
memblock fft/ifft/...
These commands can check the memblock size and see if there is enough memory for the FFT. There is also no need for pointers this way. Downside is that it is a little slower, and that you can only compute the FFT from the start of the memblock.

Caution when using
When using the pointer versions, you must always double check that the size is large enough to contain the FFT result. If the allocated memory (memblock or 'make memory') is not large enough, then the program will CRASH. Unfortunately, this crash will often happen randomly and can become hard to trace because of that.

Examples

Record sound and display FFT (like an equalizer)


Run the program and try whistling or singing in your microphone. You can see how the frequency spectrum changes when you change your pitch height.

FFT example with time and frequency domain


A demonstration on using FFT's. The total signal is a sum of two sine waves, and by using the FFT, you can see which frequency and phase these sine waves have.

Low pass filter on an image


An example of a 2D FFT. By filtering the high frequency components, we can "blur" the image. However, due to the nature of the filter (a rectangular filter), we have artifacts near sharp edges of the image.



That was all. Have fun everyone!
Sven B

[edit]Forgot attachment.
[edit2] Updated with missing libfftw3f-3.dll file and updated instructions.

Attachments

Login to view attachments
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 12:16
Not bad for performance and gameplay analysis. Great work. I will try this out when I get some time.

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 1st Feb 2012 12:24
Thanks!
I'm a bit curious on how you can use this for gameplay analysis though .

Sven B
(Turning on mailback feature)

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 1st Feb 2012 17:46 Edited at: 1st Feb 2012 18:03
Quote: "I'm a bit curious on how you can use this for gameplay analysis though
"


So was I not too long ago. It just sprung to mind that graphs can tell you more about what you cannot see without them -- alot sooner and more easily than lists of results.

What springs to mind is the seven basic tools of quality. Where the frequency of occurances of player actions, program crashes, AI behaviour, bugs, item drops, frame rate drops within certain thresholds can be recorded an analysed in a spectral diagram; or a scatter graph.

It could be used to answer the question; how often does a particular event occur; and what is the scale of its effect, or where does it happen etc.

I'm not up with FFT as a subject, I only found out about it due to its applications in sound analysis in audio engineering; stuff like the spectro graphs.



So, instead of dealing with sound frequency, deal with action/event frequency. Instead of sound time, deal with playing (or AI activity time). Instead of sound intensity, deal with the intensity of what a player or AI entity did. EG: In a adventure game, a diagram can quickly illustrate where most players die; the frequency; when they die; the time; and how quickly they die; the intensity. Something a long list of deaths cannot illustrate quickly.

Things that I want to know include:
- Where do players get stuck (Level design flaw)
- Where do AI get stuck (AI debugging)
- Where do players search help documentation most of the time and how much gameplay have they had since installing (Possible design flaws)
- How many players lose the game at a certain location Vs how many I want to lose at that point (Level design flaw)
- Where are the items that have low frequency of pickups? Should they be found more often?
- What is the level of experience of players who exit the game in the most exited location within the game level that is most exited(Level design quality)

Stuff like that is logged anyway, but seeing them visually makes sense. I'm not sure how your plugin works and whether it can help; but I do know graphs can.

This spectrogram could overlay a game level indicating irregularities and regularities of something, somewhere.



This is not quite FFT related, but indicates a number of characteristics about stuff at certain times or locations.



The simple 2d diagram is easy to create.


You also have bargraphs, histographs & pareto charts that can be used.

TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Feb 2012 21:02
Nice stuff Sven B Your work has always amazed me. I saw an example on how to create FFT graphs in DBP a very long time ago. I believe the guy who created the example used the fmod dll.

I'd love to know more about your engineering side of life (sorry to go off topic a bit), as I'm on my way in that direction as well. I'm doing an apprenticeship as an electronic technician, and have been so for 2.5 years now. I have the option to go to university and study engineering once I've completed my apprenticeship.

TheComet

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 1st Feb 2012 21:20 Edited at: 1st Feb 2012 21:32
Hello again,

[edit] @Chris Tate
I can see where you wanted to go with this. Well, good luck In my head I'm not sure how I would implement it. In any case, if you get any results with this, I'd love to see it.

Cheers!
Sven B

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 1st Feb 2012 21:54
@TheComet
Yeah, I searched for FFT before searching for alternatives. But the fmod version didn't work for arbitrary floating point signals, only for sounds IIRC.

[Off topic]
I'm a civil engineer EIT in my 1st Master year so next year is my last. I'm not sure how it is at other universities, but here engineering (compared to other courses here) is a lot of class and a lot of courses.
In my bachelor years we got a very broad range of science disciplines, with a big emphasis on math in the first year. In the third year we could choose a profile: EIT, EIT Computer Science, Mechanics, (Building) Construction or Chemistry&Materials (I chose EIT - Electronics and Information Technology). So in this third year we got a lot more courses related to electronics. Eg. Quantum Physics, System- and Control Theory, Electromagnetism (more advanced than in previous years), Networks and Filter Design, Digital Circuits, etc.

This year, in the first master, the courses are about much more practical aspects. Eg. Measuring systems influenced by noise (involving quite a bit statistics - which is also a part of the bachelor education), programming an FPGA chip in VHDL and a Microprocessor in Assembler/C, signal and information theory: how can I efficiently send information over a noisy medium, etc.

But as I said, the above applies to my university, but might not apply for yours.

Cheers!
Sven B

gwheycs62egydws
14
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 5th Feb 2012 08:46
based on whats I read
I can see using this plug-in for collecting stats for a multiplayer games

it could also be used to help a program to learn what a player will do
and how to beat them

to move side ways - is to move forward
Since a Strait line gets thin fast
Phjon
18
Years of Service
User Offline
Joined: 28th Nov 2005
Location:
Posted: 7th Feb 2012 18:42
Sven B,

Have tried out this plugin, but I'm having trouble trying to get some of your examples to work.

I recieved an error message stating that the dll "libfftw3f-3.dll" was not found. I looked on the website you provided and found it.

However, I don't know where to place this dll in order for the examples to work. Placing it in the "plugins-user" folder didn't work.

Do you have any ideas on this?

Thanks in advance

P.S. I followed through the instructions provided in the Readme file, so the DB FFTW.dll plugin is in the right place.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Feb 2012 18:48
Hello Phjon,

I'm terribly sorry for this. You're right! You need to put libfftw3f-3.dll in the same folder as the executable. I will reupload the zip file in a second containing the dll and right instructions.

Sven B

Phjon
18
Years of Service
User Offline
Joined: 28th Nov 2005
Location:
Posted: 7th Feb 2012 18:58 Edited at: 7th Feb 2012 19:06
Sven B,

OK, that seems to have done the trick.

However, there is a bug with your first example => "Could not load sound at line 39"

It seems to appear after the program has run for a brief instant.

I haven't checked the other examples yet, will do so now.

---Edit---

The second example works fine, but the third comes up with an error message => "Memblock size value illegal at line 12"

What the program's trying to do is make a memblock from an image that doesn't exist (first line of code). I'm not sure if this can be any old image, or if this is one that you have specially prepared for the example.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Feb 2012 19:24
Hello again,

I have tried all the examples again but didn't find any errors. The third one seemed to work with all images I could find (non square, png, jpg, bmp). Maybe the size is illegal because the loaded image has a zero height and/or width (W or H = 0). Thus it tries to create a memblock of size 0 that results in an error.

The first one doesn't contain any load sound command (line 39 seems to point to make memblock from sound. I have personally no real experience with recording sounds from DBP, so it's hard to say why you're getting that error.

Sven B

Phjon
18
Years of Service
User Offline
Joined: 28th Nov 2005
Location:
Posted: 7th Feb 2012 19:40
Sven B,

Thanks for the help.

My line 39 points to "Stop Recording Sound". This is because my IDE prints a few comments at the top of the code which increases the line numbers, so my fault on not forseeing that.

I'll keep fiddling with the code for example 1 to see if can get it to work.

Login to post a reply

Server time is: 2024-03-29 05:36:34
Your offset time is: 2024-03-29 05:36:34