0
0

Hi,

I want to show a spectrum-analysis of the current song in a player.
I’m streaming it:
[code:1a0m012c]
private
fmod : FMOD_SYSTEM;
fmodr : FMOD_RESULT;
fmods : FMOD_SOUND;
fmodc : FMOD_CHANNEL;
end;

[...]

fmodr := FMOD_System_CreateStream(fmod, PAnsiChar(f), FMOD_SOFTWARE, nil, fmods);
[/code:1a0m012c]
I read in the documentation that FMOD_SOFTWARE is needed for something like this:
[code:1a0m012c]
function TAudio.GetSpectrum : Single;
begin
if fmodc = nil then
Exit;
fmodr := FMOD_Channel_GetSpectrum(fmodc, Result, 512, 0, FMOD_DSP_FFT_WINDOW_RECT);
Fehler;
end;
[/code:1a0m012c]
But I get a AccessViolation in the CPU when I call the function.

There is one thing I cannot understand: In Cpp a float-[b:1a0m012c]array[/b:1a0m012c] is used , in Pascal I only need the floattype Single ? If I look in the fmod.pas there is following line:
[code:1a0m012c]function FMOD_System_GetSpectrum (system: FMOD_SYSTEM; var spectrumarray: Single; numvalues: Integer; channeloffset: Integer; windowtype: FMOD_DSP_FFT_WINDOW): FMOD_RESULT; stdcall;[/code:1a0m012c]
So I think Single is really right but how should I go on with the var ?

Can someone give me an answer for the AV and the theoretically question ?

It is okay if you use another languages for explaining than Pascal.

  • You must to post comments
0
0

Delphi probably passes a pointer to the specified float or float array, so using floatarry(0) should do the trick (yes, it is (a pointer to) an float array)

  • You must to post comments
0
0

Thanks. :)

I think that is the best way to do it:
[code:3iuvdb9c]
type
TAudio = class
...
private
fmod : FMOD_SYSTEM;
fmodr : FMOD_RESULT;
...
procedure Fehler;
public
...
function GetSpectrum(d : Integer) : TDynSingleArray;
end;

function TAudio.GetSpectrum(d : Integer) : TDynSingleArray; // TDynSingleArray = Array of Single
begin
if fmodc = nil then
Exit;
SetLength(Result, d);
fmodr := FMOD_System_GetSpectrum(fmod, Result[0], d, 0, FMOD_DSP_FFT_WINDOW_RECT);
Fehler;
end;
[/code:3iuvdb9c]

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.