Sound Visualization

New releases and general discussions.

Post » Thu Oct 09, 2008 3:45 am

I'm don't no how it name, but possible maked in construct something like winamp :roll:
B
3
G
4
Posts: 21
Reputation: 1,142

Post » Thu Oct 09, 2008 4:28 am

I don't think so, but I could be wrong.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Thu Oct 09, 2008 5:56 am

The spectral analysis of audio (which equalizers like that do) requires pretty hardcore math, so unless there is some tools for that in the new XAudio2, it would be hardly possilbe.

AFAIK the audio is divided into different (ie. bass, mid and treble... of course there could be more) bands in digital enviroments using so-called Fourier transformations. (Or discrete cosine transofrmations) but that would require a direct access to the waveform and pretty hc math... Is here anybody here with signal engineering degree :D?
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Thu Oct 09, 2008 6:35 am

maybe just add some plugin or new Expressions for audio.
B
3
G
4
Posts: 21
Reputation: 1,142

Post » Thu Oct 09, 2008 6:43 am

[quote="flud":1j1uumz9]maybe just add some plugin or new Expressions for audio.[/quote:1j1uumz9]

Yeah, and if the XAudio2 doesn't offer the features, some 3rd party library could be used :)
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Thu Oct 09, 2008 7:00 am

Fourier transformation is needed, that's for sure. How to achieve it and make it fast at once? "Normal" Fourier Transformation algorithm uses O^2, and Fast Fourier Transformation uses n*log2(n). I can recommend getting FFTW:
:arrow: one of the fastest FFT algorithms - see benchmark results (and one sample to let you know which one to check)
:arrow: deals with non 2^N arrays of probes (but takes more time then)
:arrow: open source, free for noncommercial use
:arrow: AFAIR written in ANSI C
:arrow: support for optimalization of FFT-ing signal (but I don't think this would be useful in non-industrial use)
AFAIR applications like Winamp uses FFTW to make spectrum analysis.

The only problem is how to access XAudio2's pointer to actually played buffer. And I don't know how many samples are taken to analysis every "frame" (maybe 1k?). Anyways, FFTW deals with 2^19 samples in about 100ms.
B
6
S
3
G
6
Posts: 219
Reputation: 3,013

Post » Thu Oct 09, 2008 7:21 am

BROO: That FFTW looks promising... but yes, there is the problem of getting the buffer. I don't know much about Construct's plugin architecture, but even if there would be an function retrieving the buffer in XAudio2 plugin, how would it pass to separate audio analyser plugin?
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Post » Thu Oct 09, 2008 7:59 am

Method for making FFT

FFTW has functions to which you have to pass:
:arrow: input buffer
:arrow: output buffer
:arrow: number of samples
:arrow: (and some other flags for optimalization and stuff).
If you happen to retrieve pointer to XAudio2 buffer, you'll have to create your Output memory buffer. FFTW operation will populate the Output buffer with calculated Fourier Transformation.

There are some ways (AFAIR in FFTW it's called kinds) of getting output data buffer. I'll explain it on example later in this post.

Accessible frequencies depend on amount of probes you pass in Input Buffer. If you pass 8192-element Input Buffer, you'll get frequencies from -4095Hz to 4096 Hz. Then in order to get 20kHz spectrum you'd probably want to pass 40000 elements buffer. Since processing 2^N sized arrays is better, I recommend 65536 elements sized arrays to get -32767Hz to 32768Hz.

Don't worry about working with transfering data, retrieving and stuff, it'll be done within 10msec for sure.
And how to know which table indexes are the positive and negative frequencies? Well it depends on KIND of getting output data.

Sample of usage:
Let's say you want frequencies 1..8Hz. You have then to pass Input Buffer array of 16 float numbers. Then, you have to prepare memory for Output Buffer: it'll be array of 16 float numbers. FFTW works like this:
:arrow: retrieve/malloc Input/Output buffers
:arrow: select PLAN you want to do (as for us it'll be fftw_plan fftw_plan_r2r_1d(int n, double *in, double *out, fftw_r2r_kind kind, unsigned flags);
:arrow: execute PLAN
:arrow: free memory

When you execute plan, your Output array will be probably populated with such points ( x(n) = amplitude at n Hz freq):
x(0), x(1), x(2), x(3), x(4), x(5), x(6), x(7), x(8), x(-7), x(-6), x(-5), x(-4), x(-3), x(-2), x(-1). So get rid if last 7 elements and you get what you're interested in.

If XAudio2 would have "get pointer to buffer" expression, then everything should be all right. And if you're going to make 0..20kHz in few bars like in Winamp, you'll have to sum/average parts of array.
B
6
S
3
G
6
Posts: 219
Reputation: 3,013

Post » Thu Oct 09, 2008 1:53 pm

The best way to implement this would be via a custom XAPO effect in XAudio2. You could probably get it working with FFTW. I might get round to it, but it's a bit of a gimmick really.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Thu Oct 09, 2008 1:56 pm

[quote="BROO":2ih9xns1]If XAudio2 would have "get pointer to buffer" expression, then everything should be all right. And if you're going to make 0..20kHz in few bars like in Winamp, you'll have to sum/average parts of array.[/quote:2ih9xns1]

BROO: What are the minus frequencies representing :o? I don't quite get why does the function return those also.


I just began to wonder if it is possible to combine the frequencies afterwards and input them back to XAudio2 :D. I was thinking some kind of controllable equalizer...
B
3
S
2
G
5
Posts: 263
Reputation: 2,201

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 2 guests