Place the type at the start of your program with the f_Init() below it. Then load a file with f_Stream_Music( "fileToLoad" ). Use f_PlayStreamed( SongID ) to play the loaded song and f_StopStream( SongID ) to stop it. With f_Delete( SongID ) you can delete a song from the array. f_Destroy() should be called at the end of the program, it will delete all songs and the dll from memory. Use f_getFFT to copy the data you need for the visuals to an array. In the loop use f_getMusicData( Index ) to get the data for the visuals per kHz, with a range of 0-63.
[ Edit ] Made a small mistake in the example, it works better now.
Example:
Type msx
handle As Integer
ffthandle As Integer
spectrum As Integer
lof As Integer
fft As Integer
storeMemblock As Integer
Endtype
Sync On
Sync Rate 60
f_init()
song = f_StreamMusic("SongToLoad")
f_playStreamed( song )
Disable escapekey
Do
Cls
f_getFFT( song )
For i=0 To 63
data# = f_getMusicData( i )
box 100 + i*5 , 200 - data# * 150 , 100 + i*5 + 4 , 200
Next i
if escapekey() then f_destroy() : wait 100 : end
text 10 , 10 , "Fps: "+str$( screen fps() )
Sync
Loop
f_destroy()
Rem *** Functions ***
Function f_Init()
global dim f_music(-1) As msx
global dim f_music_eq_data(63) as float
Load Dll "fmod.dll",1
nul=Call Dll(1,"_FSOUND_Init@12",44100,1,0)
endfunction
function f_StreamMusic(file$)
array insert at bottom f_music()
index = array count( f_music() )
f_music( index ).handle = Call Dll(1,"_FSOUND_Stream_Open@16",file$,0,0,0)
f_music( index ).lof = Call Dll(1,"_FSOUND_Stream_GetLength@4",f_music( index ).handle)
f_music( index ).storeMemblock = 1
while memblock exist( f_music( index ).storeMemblock )
inc f_music( index ).storeMemblock
endwhile
Make Memblock f_music( index ).storeMemblock , 256
f_music( index ).fft = Get Memblock Ptr(f_music( index ).storeMemblock)
endfunction index
function f_playStreamed( streamIndex )
if streamIndex<0 then exitfunction
if streamIndex > array count( f_music() ) then exitfunction
nul=Call Dll(1,"_FSOUND_Stream_Play@8",0,f_music(streamIndex).handle)
f_music(streamIndex).ffthandle=Call Dll (1,"_FSOUND_DSP_GetFFTUnit@0")
nul=Call Dll (1,"_FSOUND_DSP_SetActive@8",f_music(streamIndex).ffthandle,-1)
f_music(streamIndex).spectrum=Call Dll (1,"_FSOUND_DSP_GetSpectrum@0")
endfunction
function f_StopStream( streamIndex )
if streamIndex < 0 then exitfunction
if streamIndex > array count( f_music() ) then exitfunction
nul=Call Dll(1,"_FSOUND_Stream_Stop@4",f_music(streamIndex).handle)
nul=Call Dll(1,"_FSOUND_Stream_Close@4",f_music(streamIndex).handle)
array delete element f_music() , streamIndex
endfunction -1
function f_delete( streamIndex )
array delete element f_music() , streamIndex
endfunction
function f_destroy()
for i=0 to array count( f_music() )
f_StopStream( i )
dec i
next i
undim f_music()
nul=Call Dll(1,"_FSOUND_Close@0")
Delete Dll 1
endfunction
function f_getFFT( streamIndex )
if streamIndex<0 then exitfunction
if streamIndex > array count( f_music() ) then exitfunction
Copy Memory f_music(streamIndex).fft,f_music(streamIndex).spectrum,256
nr=0
For i=0 To 252 Step 4
f_music_eq_data(nr)=Memblock Float(f_music(streamIndex).storeMemblock,i)
Inc nr,1
Next i
endfunction
function f_getMusicData( index )
if index<0 then exitfunction
if index>63 then exitfunction
musicData# = f_music_eq_data( index )
endfunction musicData#