Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: DrewPee on December 07, 2010
-
Guys,
I want to use FMod (or something similar if possible) to play either a .mp3 or .wav file.
I know how to get Fmod to play an .mp3/.wav file no problem at all, but once it is playing I need to be able to generate a spectrum analyser/equaliser on screen in realtime - does anybody know how to do this?
I will be using tinyptc to draw the equaliser too.
Thanks in advance . . .
DrewPee
-
I know for sure that there are more than one resource to look at:
http://www.dbfinteractive.com/forum/index.php/topic,519.0.html
it's for uFmod so some restrictions apply... but the basic steps shold be there... I'm diggin' the forum out to find some more infos...
cheers ;)
-
Thanks matey - I will take a look at that . . . ;)
Drew
-
FSOUND_DSP_GetSpectrum() (http://www.secit.at/doc/fmod-3.74/html/HTML/FSOUND_DSP_GetSpectrum.html)
-
FSOUND_DSP_GetSpectrum() (http://www.secit.at/doc/fmod-3.74/html/HTML/FSOUND_DSP_GetSpectrum.html)
I should RTFM first... as always... ;)
-
Thanks a lot guys! :)
Does anybody have an instance of this working in FreeBasic - can't seem to get it to work?
Drew
-
How about bass?
You can download one example here:
http://www.rbraz.com/files/DBF-GVY_Camouflage_src.rar
Have everything you need to make a spectrum analyser/equaliser in fb.
-
Thanks rbz. I will take a look at that too.
Cheers
Drew
-
One small question - does the bass.dll play all formats or just .xm and .mod etc? :(
I need it to play .mp3 or .wav files really?
Cheers
Drew
-
BASS is an audio library for use in Windows and Mac OSX software. Its purpose is to provide developers with powerful and efficient sample, stream (MP3, MP2, MP1, OGG, WAV, AIFF, custom generated, and more via add-ons), MOD music (XM, IT, S3M, MOD, MTM, UMX), MO3 music (MP3/OGG compressed MODs), and recording functions. All in a tiny DLL, under 100KB* in size.
Yes, it can play alot of formats.
For mp3 file which is called stream you can use:
stream = BASS_StreamCreateFile( false, "music.mp3", 0, 0, BASS_MUSIC_AUTOFREE |
BASS_STREAM_PRESCAN |
BASS_SAMPLE_FLOAT);
BASS_ChannelPlay(stream, true);
-
I still must be doing something wrong - anybody help with this . . . ?
Obviously you need to put an .mp3 of your own in there . . . :)
#include once "fmod.bi"
#Include once "tinyptc_ext.bi"
Dim Shared As Integer Xres,Yres,Value
Xres=640:Yres=480:Value=0
Dim Shared As Integer MySong
Dim Shared As Uinteger Buffer(XRES*YRES)
#define pp(x,y,argb) buffer(y*XRES+x)=argb
FSOUND_Init(48000, 4, 0)
MySong = FSOUND_Sample_Load(FSOUND_FREE, "StangeByDPC.mp3", 0, 0, 0)
FSOUND_Sample_SetMode(MySong, FSOUND_LOOP_NORMAL)
FSOUND_DSP_GetFFTUnit()
PTC_ALLOWCLOSE(0)
PTC_SETDIALOG(0,"MP3 Player Test",1,0)
IF (PTC_OPEN("Coded by AndyRCM aka DrewPee",XRES,YRES)=0) THEN
END-1
END IF
FSOUND_PlaySound(FSOUND_FREE, MySong)
WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE)
PTC_UPDATE@Buffer(0)
FSOUND_Update
value=FSOUND_DSP_GetSpectrum()
print value;" ";
WEND
-
Seems you get stuck with it, so here an example for you to play:
#include once "fmod.bi"
#Include once "tinyptc_ext.bi"
Dim Shared As Integer Xres,Yres
Xres=640:Yres=480
Dim Shared MySong as FSOUND_SAMPLE ptr 'rbz
dim shared spectrum_buffer_ptr as single ptr 'rbz
spectrum_buffer_ptr = allocate(512 * SizeOf(single)) 'rbz
Dim Shared As Uinteger Buffer(XRES*YRES)
dim as integer i,j'rbz
dim as single value'rbz
#define pp(x,y,argb) buffer(y*XRES+x)=argb
FSOUND_Init(48000, 4, 0)
MySong = FSOUND_Sample_Load(FSOUND_FREE, "srg7agosto.mp3", FSOUND_NORMAL, 0, 0)
FSOUND_Sample_SetMode(MySong, FSOUND_LOOP_NORMAL)
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE)'rbz
PTC_ALLOWCLOSE(0)
PTC_SETDIALOG(0,"MP3 Player Test",1,0)
IF (PTC_OPEN("Coded by AndyRCM aka DrewPee",XRES,YRES)=0) THEN
END-1
END IF
FSOUND_PlaySound(FSOUND_FREE, MySong)
WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE)
spectrum_buffer_ptr=FSOUND_DSP_GetSpectrum()'rbz
for i = 0 to 24 '(max 512)
value = spectrum_buffer_ptr[i]
locate i,1: Print Using "###.##"; (value*100)
next
for i = 0 to 24
value = spectrum_buffer_ptr[i] * 40.0
for j = 0 to cast(integer, value)
locate i,j+10: print "# "
next
next
PTC_UPDATE@Buffer(0)
WEND
deallocate(spectrum_buffer_ptr)
FSOUND_Sample_Free(MySong)
FSOUND_Close
Just remember that FSOUND_DSP_GetSpectrum will return a pointer to a buffer containing 512 floats, in this example I just display 24, and make sure to use a proper scale for your needs (value*scale_factor) .
My ASCII spectrum looks crap but I'm sure you will do better on ptc buffer :)
-
Thank you. Sorry I haven't replied sooner - just been to Oldenburg/Germany to visit a Retro Computer Museum! ;)
Cheers
Drew
-
That is exactly what I needed! Thank you so much! I will credit you with the code for this part of the project. ;) Massive thanks mate and Karma+ ;)
Drew