0
0

Hello, been reading thru the documentation on fmod again and found the spectrum analysis functions that return you a pointer to an array of the values. Would I be correct in saying that this can only be performed on what can actually be heard? I know that you can place it elsewhere in the effects chain so to speak but what I actually want to do is get the spectrum of one particular channel or stream maybe that is playing muted. It says that the spectrum can be used for beat detection which is what I want to do for a djing program but it needs to be done on the song before it actually starts playing (or in some cases while it is playing but that’s off my point). If what I’m describing cannot be done then how can I get access to the actual waveform data to perhaps do a fast fourier transform with my own code or another library etc.
Cheers

  • You must to post comments
0
0

The built-in spectrum analyser in fmod indeed only works on the sound that is actually be heard.
But, as you suggested, you can use your own FFT routines on a particular stream.
Therefore, you need to create a dsp unit, and provide it with a dsp_callback which does the FFT and beat detection stuff. It goes like this:

[code:27aff86l]
void* dspcallback(void originalbuffer,void *newbuffer,int length,int param) {
// your_fft_and_beat_detection_stuff
}
...
FSOUND_DSPUNIT
dspUnit = FSOUND_Stream_CreateDSP(yourStream,&dspcallback,0,0);
FSOUND_DSP_SetActive(dspUnit, TRUE);
[/code:27aff86l]

I did it myself and tried to write a beat detection algorythm, it basiscally works but needs to be inproved. I used the FFTW library to do the FFT, divided the spectrum in 32 subbands (on a logarithmic scale), and tried to find a beat pattern on each subband. At this moment, my code is quite unreadable and buggy, but maybe I’ll put it online somewhere in the future. If you find an accurate algorithm, let me know.

  • You must to post comments
0
0

Thanks, that looks quite comprehensive and useful – I’ll see how I get on.

  • You must to post comments
0
0

I’m not sure what people’s opinion is on posting large chunks of code here so I’m sorry if this is a bit big. Following on from the previous post I finally got round to trying the code. I wrote this:[code:2ul6y35g]#include <string.h>

include <stdio.h>

include <math.h>

include <time.h>

if defined(WIN32) || defined(WATCOMC)

#include <windows.h>
#include <conio.h>

else

#include "inc/wincompat.h"

endif

include "inc/fmod.h"

include "inc/fmod_errors.h"

FSOUND_STREAM* stream;

void* dspcallback(void *originalbuffer,void *newbuffer,int length,int param)
{
// your_fft_and_beat_detection_stuff
return originalbuffer;
}

int main()
{
if(!FSOUND_Init(44100, 32, 0))
{
printf("Error!\n");
printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
FSOUND_Close();
return 0;
}

stream = FSOUND_Stream_Open(&quot;insane.wav&quot;, (FSOUND_HW2D|FSOUND_LOOP_NORMAL), 0, 0);
FSOUND_DSPUNIT* dspUnit = FSOUND_Stream_CreateDSP(stream, &amp;dspcallback,0,0); 
FSOUND_DSP_SetActive(dspUnit, TRUE); 

return 1;

}[/code:2ul6y35g]and got this error:[code:2ul6y35g]D:\basic DSP\main.cpp(37) : error C2664: ‘FSOUND_Stream_CreateDSP’ : cannot convert parameter 2 from ‘void *(__cdecl *)(void *,void *,int,int)’ to ‘void *(__stdcall *)(void *,void *,int,int)’
This conversion requires a reinterpret_cast, a C-style cast or function-style cast[/code:2ul6y35g]As you can probably see this would do nothing but I dunno what’s wrong with it, something to do with how the function’s defined or something – all I can gather from the error is it’s possibly to do with differences in C and C++? Haylp, I hate falling at the first hurdle 😕

EDIT: Sorry, bonus fuckwit point for me – forgot F_CALLBACKAPI before dspcallback

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.