Page 1 of 2
FMODEX-include
Posted: Thu Dec 28, 2006 12:27 pm
by Froggerprogger
Today I finished an include-file for fmodex in version 4.06.01, but it should work with all later releases, as long as the API doesn't change.
I did this half-automatic, so a rebuild will not be very time-consuming.
Just include the file fmodex.pb which you'll get here:
http://www.2mal2mal.de/public/purebasic ... /fmodex.pb
and call Init_FMOD() at the beginning. See the example:
Code: Select all
;- SimplePlay with fmodex-include
IncludeFile "fmodex.pb"
Init_FMOD()
FMOD_System_Create(@fmodsystem)
FMOD_System_Init(fmodsystem, 32, 0, 0)
str.s = OpenFileRequester("Choose a soundfile", GetClipboardText(), "*.*|*.*", 0)
If str = "" : End : Else : SetClipboardText(str) : EndIf
FMOD_System_CreateStream(fmodsystem, @str, #FMOD_SOFTWARE, 0, @sound)
FMOD_System_PlaySound(fmodsystem, 0, sound, 0, @channel)
Dim Arr.f(512)
Repeat
FMOD_Channel_GetPosition(channel, @pos, #FMOD_TIMEUNIT_MS)
FMOD_Channel_IsPlaying(channel, @isPlaying)
FMOD_Channel_GetSpectrum(channel, Arr(), 512, 0, 0)
Debug "--------------------"
Debug "isPlaying: " + Str(isPlaying)
Debug "position: " + Str(pos)
Debug "spectrum: " + StrF(Arr(0),4) + " " + StrF(Arr(1),4) + " " + StrF(Arr(2),4) + " " + StrF(Arr(3),4) + " ..."
Delay(250)
Until pos > 10000 Or isPlaying = #False
FMOD_System_Release(fmodsystem)
Posted: Thu Dec 28, 2006 7:56 pm
by oryaaaaa
Thankyou. because I am making it.
for USB-HDD
Posted: Thu Dec 28, 2006 8:38 pm
by oryaaaaa
fmodex.pb BUG "VOLUME as FLOAT"
Code: Select all
Procedure.l FMOD_Channel_SetVolume (channel.l, volume.f)
ProcedureReturn CallFunction(fmodLib, "FMOD_Channel_SetVolume", channel.l, volume.f)
EndProcedure
Procedure.l FMOD_Channel_GetVolume (channel.l, *Volume.f)
ProcedureReturn CallFunction(fmodLib, "FMOD_Channel_GetVolume", channel.l, *Volume.f)
EndProcedure
require lib
Droopy Library v1.31.4 (for V4)
FMODEX.DLL
This code, Audio Files buffer on VirtualMemory.
USB-HDD Noiseless Tips
Code: Select all
IncludeFile "fmodex.pb"
Enumeration
#Window
EndEnumeration
Enumeration
#Tree_PlayList
#_Play
#_VolUp
#_VolDown
EndEnumeration
Global FSOUND_DLL.l, FSOUND_SYS.l
Global ExePath.s
;- CHANGE !!
;ExePath =GetProgramPath()
ExePath ="F:\Documents and Settings\hiroyuki\My Documents\memplay\"
Debug ExePath
Structure Station
Name.s
Url.s
Path.s
SoundHnd.l
Pointer.l
Homepage.s
EndStructure
Global NewList Station.Station()
Procedure ErrLogWrite(errstr.s)
Protected fileno
If FileSize(ExePath+"errlog.txt")>0
fileno = OpenFile(#PB_Any, ExePath+"errlog.txt")
FileSeek(fileno, Lof(fileno) )
Else
fileno = CreateFile(#PB_Any, ExePath+"errlog.txt")
EndIf
WriteStringN(fileno,FormatDate("%mm/%dd:%hh:%ii:%ss> ", Date())+errstr)
CloseFile(fileno)
EndProcedure
Procedure.l MemoryLoad(FileName.s)
Protected FileHwd.l = ReadFile(#PB_Any, FileName)
Protected filesize.l = Lof(FileHwd)
Protected FileMem.l =AllocateMemory( filesize )
If GlobalMemoryStatusAvailPhys()>(filesize/1024/1024+64)
ReadData(FileHwd, FileMem, filesize )
CloseFile(FileHwd)
ProcedureReturn FileMem
EndIf
EndProcedure
Procedure.b FSOUND_Init()
FSOUND_DLL = Init_FMOD()
If FSOUND_DLL=0
ErrLogWrite("Cant LOAD FMODEX.DLL!")
ProcedureReturn #False
Else
ErrLogWrite("Success LOAD FMODEX.DLL")
ProcedureReturn #True
EndIf
EndProcedure
Procedure FSOUND_INIT2()
FMOD_System_Create( @FSOUND_SYS )
FMOD_System_Init( FSOUND_SYS, 32, #FMOD_INIT_NORMAL, 0)
EndProcedure
Procedure FSOUND_FREE()
FMOD_System_Close( FSOUND_SYS )
FMOD_System_Release(FSOUND_SYS)
EndProcedure
Procedure DragNdropFile()
Protected exinfo.FMOD_CREATESOUNDEXINFO, NumFiles, File.s, d, c
c = ListIndex( Station() )
NumFiles=DropFilesInit()
Repeat
File.s=DropFilesEnum()
If File ="" : Break : EndIf
AddElement(Station())
Station()\Name = GetFilePart(File)
Station()\Path = File
*FileMem = MemoryLoad( Station()\Path )
exinfo\cbSize=SizeOf(FMOD_CREATESOUNDEXINFO)
exinfo\length=MemorySize(*FileMem)
d = FMOD_System_CreateSound(FSOUND_SYS, *FileMem, #FMOD_CREATESTREAM|#FMOD_OPENMEMORY| #FMOD_HARDWARE |#FMOD_LOOP_OFF, @exinfo, @Sound)
If d>0
ErrLogWrite( "Section:: DragNdropFile "+Station()\Name )
ErrLogWrite( FMOD_ErrorString(d) )
EndIf
Station()\SoundHnd = Sound
Station()\Pointer = *FileMem
AddGadgetItem( #Tree_PlayList, -1, Station()\Name )
ForEver
SelectElement(Station(), c)
EndProcedure
Procedure Open_Window()
If OpenWindow(#Window, 0, 0, 522, 330, "FMOD TEST Drag N Drop", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar| #PB_Window_Invisible|#PB_Window_ScreenCentered | #PB_Window_BorderLess )
If CreateGadgetList(WindowID(#Window))
TreeGadget(#Tree_PlayList, 10, 50, 500, 250, #PB_Tree_AlwaysShowSelection )
DropFilesAccept(GadgetID(#Tree_PlayList),#True)
ButtonGadget(#_Play, 10,5,100,40, "PLAY")
ButtonGadget(#_VolUp,255,05,50,20,"Vol up")
ButtonGadget(#_VolDown,255,28,50,20,"Vol down")
HideWindow(#Window, #False)
EndIf
EndIf
EndProcedure
If FSOUND_Init()
FMOD_System_SetSoftwareFormat(FSOUND_SYS, 48000, #FMOD_SOUND_FORMAT_PCM24, 0,0,#FMOD_DSP_RESAMPLER_SPLINE)
FSOUND_INIT2()
Open_Window()
Repeat
Delay(10)
EventID = WindowEvent()
If EventID = #PB_Event_Gadget
Select EventGadget()
Case #_Play
If CountList( Station() )>0
splaying = FMOD_Channel_IsPlaying( channel,@isplaying.b )
If isplaying
FMOD_Channel_Stop( channel )
EndIf
splaying = GetGadgetState(#Tree_PlayList)
If splaying>-1 And splaying<=CountList( Station() )
SelectElement(Station(), splaying)
FMOD_System_PlaySound( FSOUND_SYS, #FMOD_CHANNEL_FREE, Station()\SoundHnd, 0, @channel )
EndIf
EndIf
Case #_VolUp
FMOD_Channel_GetVolume( channel,@CurrentVolume.f )
Select CurrentVolume.f
Case 0 To 0.3
FMOD_Channel_SetVolume( channel, CurrentVolume+0.02 )
Case 0.31 To 0.5
FMOD_Channel_SetVolume( channel, CurrentVolume+0.05 )
Case 0.51 To 1.0
If (CurrentVolume+0.08)>1.0
FMOD_Channel_SetVolume( channel, 1.0 )
Else
FMOD_Channel_SetVolume( channel, CurrentVolume+0.08 )
EndIf
EndSelect
Case #_VolDown
FMOD_Channel_GetVolume( channel,@CurrentVolume.f )
Select CurrentVolume.f
Case 0 To 0.3
If (CurrentVolume-0.02)<0
FMOD_Channel_SetVolume( channel, 0 )
Else
FMOD_Channel_SetVolume( channel, CurrentVolume-0.02 )
EndIf
Case 0.31 To 0.5
FMOD_Channel_SetVolume( channel, CurrentVolume-0.05 )
Case 0.51 To 1.0
FMOD_Channel_SetVolume( channel, CurrentVolume-0.08 )
EndSelect
EndSelect
ElseIf EventID=#WM_DROPFILES
DragNdropFile()
EndIf
If channel>0
splaying = FMOD_Channel_IsPlaying( channel,@isplaying.b )
If isplaying=0
If NextElement(Station())
Else
SelectElement(Station(), 0)
EndIf
SetGadgetState(#Tree_PlayList, ListIndex( Station() ) )
FMOD_System_PlaySound( FSOUND_SYS, #FMOD_CHANNEL_FREE, Station()\SoundHnd, 0, @channel )
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
ForEach Station()
FMOD_Sound_Release( Station()\SoundHnd )
FreeMemory(Station()\Pointer)
Next
FSOUND_FREE()
CloseWindow(#Window)
EndIf
End
Posted: Tue Jan 02, 2007 3:58 pm
by Froggerprogger
Whoops. Thanks for the bug (...converted Single into Byte instead of Float...).
I updated the file behind the link above containing some more related fixes.
Happy New Year!
Posted: Sat Jan 13, 2007 4:26 pm
by ricardo
Can anybody give some example on using FMOD_DSP_PARAMEQ please?
I don't know how to set the frequency, octave or gain.
Thanks in advance!
Posted: Sat Jan 13, 2007 4:32 pm
by KarLKoX
Code: Select all
; ===============================================================================================
; Effects Example
; Copyright (c), Firelight Technologies Pty, Ltd 2004-2005.
;
; This example shows how To apply some of the built in software effects To sounds.
; This example filters the Global mix. All software sounds played here would be filtered in the
; same way.
; To filter per channel, And not have other channels affected, simply replace FMOD_System_AddDSP with
; FMOD_Channel_AddDSP.
; Note in this example you don't have to add and remove units each time, you could simply add them
; all at the start then use FMOD_DSP_SetActive To toggle them on And off.
; ===============================================================================================
XIncludeFile "../../api/purebasic/fmod_errors.pbi"
Global System.l, Sound.l, Channel.l
Global result.l
Procedure ERRCHECK(the_result.l)
If the_result <> #FMOD_OK
PrintN("FMOD error ! " + Str(the_result) + FMOD_ErrorString(the_result) )
Delay(2000)
End
EndIf
EndProcedure
Procedure.s IsDspActive(the_dsp)
If the_dsp
ProcedureReturn "x"
Else
ProcedureReturn " "
EndIf
EndProcedure
OpenConsole()
; Global Settings
result = FMOD_System_Create_(@System)
ERRCHECK(result)
result = FMOD_System_GetVersion_(System, @version)
ERRCHECK(result)
If version < #FMOD_VERSION
PrintN("Error ! You are using an old version of FMOD " + Hex(version >> 16) + "." + Hex(version & $FF) + ". This program requires " + Hex(#FMOD_VERSION >> 16) + "." + Hex(#FMOD_VERSION & $FF) )
Delay(2000)
CloseConsole()
End
EndIf
result = FMOD_System_Init_(System, 32, #FMOD_INIT_NORMAL, 0)
ERRCHECK(result)
; Trim the current path to the sounds directory path
currentDir$ = Space(255)
GetCurrentDirectory_(255, @currentDir$)
For i = Len(currentDir$) To 1 Step -1
If Mid(currentDir$, i, 1) = "\"
found = found + 1
If found = 2
position = i
EndIf
EndIf
Next i
soundFile$ = Mid(currentDir$, 1, position)
result = FMOD_System_CreateSound_(System, soundFile$ + "examples\media\drumloop.wav", #FMOD_SOFTWARE, 0, @Sound)
ERRCHECK(result)
PrintN("===================================================================")
PrintN("Effects Example. Copyright (c) Firelight Technologies 2004-2005.")
PrintN("===================================================================")
PrintN("")
PrintN("Press SPACE to paused/unpause sound.")
PrintN("Press 1 to toggle dsplowpass effect.")
PrintN("Press 2 to toggle dsphighpass effect.")
PrintN("Press 3 to toggle dspecho effect.")
PrintN("Press 4 to toggle dspflange effect.")
PrintN("Press 5 to toggle dspdistortion effect.")
PrintN("Press 6 to toggle dspchorus effect.")
PrintN("Press 7 to toggle dspparameq effect.")
PrintN("Press 'Esc' to quit")
PrintN("")
result = FMOD_System_PlaySound_(System, #FMOD_CHANNEL_FREE, Sound, 0, @Channel)
ERRCHECK(result)
; Create some effects To play with.
result = FMOD_System_CreateDSPByType_(System, #FMOD_DSP_TYPE_LOWPASS, @dsplowpass)
ERRCHECK(result)
result = FMOD_System_CreateDSPByType_(System, #FMOD_DSP_TYPE_HIGHPASS, @dsphighpass)
ERRCHECK(result)
result = FMOD_System_CreateDSPByType_(System, #FMOD_DSP_TYPE_ECHO, @dspecho)
ERRCHECK(result)
result = FMOD_System_CreateDSPByType_(System, #FMOD_DSP_TYPE_FLANGE, @dspflange)
ERRCHECK(result)
result = FMOD_System_CreateDSPByType_(System, #FMOD_DSP_TYPE_DISTORTION, @dspdistortion)
ERRCHECK(result)
result = FMOD_System_CreateDSPByType_(System, #FMOD_DSP_TYPE_CHORUS, @dspchorus)
ERRCHECK(result)
result = FMOD_System_CreateDSPByType_(System, #FMOD_DSP_TYPE_PARAMEQ, @dspparameq)
ERRCHECK(result)
Repeat
key.s = Left(Inkey(),1)
Select key
Case " "
FMOD_Channel_GetPaused_(Channel, @paused)
ERRCHECK(result)
paused ! 1
result = FMOD_Channel_SetPaused_(Channel, paused)
ERRCHECK(result)
Case "1"
result = FMOD_DSP_GetActive_(dsplowpass, @active)
ERRCHECK(result)
If (active)
result = FMOD_DSP_Remove_(dsplowpass)
ERRCHECK(result)
Else
result = FMOD_System_AddDSP_(System, dsplowpass)
ERRCHECK(result)
EndIf
Case "2"
result = FMOD_DSP_GetActive_(dsphighpass, @active)
ERRCHECK(result)
If (active)
result = FMOD_DSP_Remove_(dsphighpass)
ERRCHECK(result)
Else
result = FMOD_System_AddDSP_(System, dsphighpass)
ERRCHECK(result)
EndIf
Case "3"
result = FMOD_DSP_GetActive_(dspecho, @active)
ERRCHECK(result)
If (active)
result = FMOD_DSP_Remove_(dspecho)
ERRCHECK(result)
Else
result = FMOD_System_AddDSP_(System, dspecho)
ERRCHECK(result)
result = FMOD_DSP_SetParameter_(dspecho, #FMOD_DSP_ECHO_DELAY, 50.0)
ERRCHECK(result)
EndIf
Case "4"
result = FMOD_DSP_GetActive_(dspflange, @active)
ERRCHECK(result)
If (active)
result = FMOD_DSP_Remove_(dspflange)
ERRCHECK(result)
Else
result = FMOD_System_AddDSP_(System, dspflange)
ERRCHECK(result)
EndIf
Case "5"
result = FMOD_DSP_GetActive_(dspdistortion, @active)
ERRCHECK(result)
If (active)
result = FMOD_DSP_Remove_(dspdistortion)
ERRCHECK(result)
Else
result = FMOD_System_AddDSP_(System, dspdistortion)
ERRCHECK(result)
result = FMOD_DSP_SetParameter_(dspdistortion, #FMOD_DSP_DISTORTION_LEVEL, 0.8)
ERRCHECK(result)
EndIf
Case "6"
result = FMOD_DSP_GetActive_(dspchorus, @active)
ERRCHECK(result)
If (active)
result = FMOD_DSP_Remove_(dspchorus)
ERRCHECK(result)
Else
result = FMOD_System_AddDSP_(System, dspchorus)
ERRCHECK(result)
EndIf
Case "7"
result = FMOD_DSP_GetActive_(dspparameq, @active)
ERRCHECK(result)
If (active)
result = FMOD_DSP_Remove_(dspparameq)
ERRCHECK(result)
Else
result = FMOD_System_AddDSP_(System, dspparameq)
ERRCHECK(result)
result = FMOD_DSP_SetParameter_(dspparameq, #FMOD_DSP_PARAMEQ_CENTER, 5000.0)
ERRCHECK(result)
result = FMOD_DSP_SetParameter_(dspparameq, #FMOD_DSP_PARAMEQ_GAIN, 0.0)
ERRCHECK(result)
EndIf
EndSelect
FMOD_System_Update_(System)
FMOD_DSP_GetActive_(dsplowpass , @dsplowpass_active)
FMOD_DSP_GetActive_(dsphighpass , @dsphighpass_active)
FMOD_DSP_GetActive_(dspecho , @dspecho_active)
FMOD_DSP_GetActive_(dspflange , @dspflange_active)
FMOD_DSP_GetActive_(dspdistortion, @dspdistortion_active)
FMOD_DSP_GetActive_(dspchorus , @dspchorus_active)
FMOD_DSP_GetActive_(dspparameq , @dspparameq_active)
If (channel)
result = FMOD_Channel_GetPaused_(Channel, @paused);
If ((result <> #FMOD_OK) And (result <> #FMOD_ERR_INVALID_HANDLE) And (result <> #FMOD_ERR_CHANNEL_STOLEN))
ERRCHECK(result);
EndIf
EndIf
If paused
playback_status.s = "Paused "
Else
playback_status = "Playing"
EndIf
ConsoleLocate(0, 14)
PrintN(playback_status + " : " + "lowpass[" + IsDspActive(dsplowpass_active) + "] highpass[" + IsDspActive(dsphighpass_active) + "] echo[" + IsDspActive(dspecho_active) + "] flange["+ IsDspActive(dspflange_active) + "] dist[" + IsDspActive(dspdistortion_active) + "] chorus["+ IsDspActive(dspchorus_active) + "] parameq["+ IsDspActive(dspparameq_active) + "]" )
Delay(10)
Until Asc(key) = 27
; Shut down
result = FMOD_Sound_Release_(Sound)
ERRCHECK(result)
result = FMOD_System_Close_(System)
ERRCHECK(result)
result = FMOD_System_Release_(System)
ERRCHECK(result)
CloseConsole()
End
Posted: Sat Jan 13, 2007 5:07 pm
by ricardo
KarLKoX wrote:
result = FMOD_DSP_SetParameter_(dspparameq, #FMOD_DSP_PARAMEQ_CENTER, 5000.0)
ERRCHECK(result)
result = FMOD_DSP_SetParameter_(dspparameq, #FMOD_DSP_PARAMEQ_GAIN, 0.0)
ERRCHECK(result)
Thanks!! I was missing this... this dll is great!

Posted: Sat Jan 13, 2007 10:57 pm
by ricardo
Its difficult to save at HD as wav file?
Posted: Sat Jan 13, 2007 11:16 pm
by ricardo
KarLKoX wrote:Code: Select all
; ===============================================================================================
; Effects Example
; Copyright (c), Firelight Technologies Pty, Ltd 2004-2005.
;
; This example shows how To apply some of the built in software effects To sounds.
; This example filters the Global mix. All software sounds played here would be filtered in the
; same way.
; To filter per channel, And not have other channels affected, simply replace FMOD_System_AddDSP with
; FMOD_Channel_AddDSP.
; Note in this example you don't have to add and remove units each time, you could simply add them
; all at the start then use FMOD_DSP_SetActive To toggle them on And off.
; ===============================================================================================
XIncludeFile "../../api/purebasic/fmod_errors.pbi"
[/quote]
Where do you get this example?
Posted: Sat Jan 13, 2007 11:32 pm
by ricardo
Ok, founded files but not for Fmoex, right?
Posted: Sat Jan 13, 2007 11:45 pm
by KarLKoX
I worked on a purebasic "port" a long time ago, here it is it should be out of date :
Code: Select all
; =============================================================================================== ;
; FMOD Ex - Error PureBasic Module. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2005. ;
; ;
; Use this module if you want to store or display a string version / english explanation of ;
; the FMOD error codes. ;
; ;
; =============================================================================================== ;
Procedure.s FMOD_ErrorString(errcode.l)
Protected FMOD_ErrorString.s
Select errcode
Case #FMOD_ERR_ALREADYLOCKED: FMOD_ErrorString = "Tried to call lock a second time before unlock was called. "
Case #FMOD_ERR_BADCOMMAND: FMOD_ErrorString = "Tried to call a function on a data type that does not allow this type of functionality (ie calling Sound::lock on a streaming sound). "
Case #FMOD_ERR_CDDA_DRIVERS: FMOD_ErrorString = "Neither NTSCSI nor ASPI could be initialised. "
Case #FMOD_ERR_CDDA_INIT: FMOD_ErrorString = "An error occurred while initialising the CDDA subsystem. "
Case #FMOD_ERR_CDDA_INVALID_DEVICE: FMOD_ErrorString = "Couldn't find the specified device. "
Case #FMOD_ERR_CDDA_NOAUDIO: FMOD_ErrorString = "No audio tracks on the specified disc. "
Case #FMOD_ERR_CDDA_NODEVICES: FMOD_ErrorString = "No CD/DVD devices were found. "
Case #FMOD_ERR_CDDA_NODISC: FMOD_ErrorString = "No disc present in the specified drive. "
Case #FMOD_ERR_CDDA_READ: FMOD_ErrorString = "A CDDA read error occurred. "
Case #FMOD_ERR_CHANNEL_ALLOC: FMOD_ErrorString = "Error trying to allocate a channel. "
Case #FMOD_ERR_CHANNEL_STOLEN: FMOD_ErrorString = "The specified channel has been reused to play another sound. "
Case #FMOD_ERR_COM: FMOD_ErrorString = "A Win32 COM related error occured. COM failed to initialize or a QueryInterface failed meaning a Windows codec or driver was not installed properly. "
Case #FMOD_ERR_DMA: FMOD_ErrorString = "DMA Failure. See debug output for more information. "
Case #FMOD_ERR_DSP_CONNECTION: FMOD_ErrorString = "DSP connection error. Either the connection caused a cyclic dependancy or a generator unit attempted to have a unit attached to it. "
Case #FMOD_ERR_DSP_FORMAT: FMOD_ErrorString = "DSP Format error. A DSP unit may have attempted to connect to this network with the wrong format. IE a floating point unit on a PocketPC system. "
Case #FMOD_ERR_DSP_NOTFOUND: FMOD_ErrorString = "DSP connection error. Couldn't find the DSP unit specified. "
Case #FMOD_ERR_DSP_RUNNING: FMOD_ErrorString = "DSP error. Cannot perform this operation while the network is in the middle of running. This will most likely happen if a connection or disconnection is attempted in a DSP callback. "
Case #FMOD_ERR_DSP_TOOMANYCONNECTIONS: FMOD_ErrorString = "DSP connection error. The unit being connected to or disconnected should only have 1 input or output. "
Case #FMOD_ERR_FILE_BAD: FMOD_ErrorString = "Error loading file. "
Case #FMOD_ERR_FILE_COULDNOTSEEK: FMOD_ErrorString = "Couldn't perform seek operation. "
Case #FMOD_ERR_FILE_EOF: FMOD_ErrorString = "End of file unexpectedly reached while trying to read essential data (truncated data?). "
Case #FMOD_ERR_FILE_NOTFOUND: FMOD_ErrorString = "File not found. "
Case #FMOD_ERR_FORMAT: FMOD_ErrorString = "Unsupported file or audio format. "
Case #FMOD_ERR_HTTP: FMOD_ErrorString = "A HTTP error occurred. This is a catch-all for HTTP errors not listed elsewhere. "
Case #FMOD_ERR_HTTP_ACCESS: FMOD_ErrorString = "The specified resource requires authentication or is forbidden. "
Case #FMOD_ERR_HTTP_PROXY_AUTH: FMOD_ErrorString = "Proxy authentication is required to access the specified resource. "
Case #FMOD_ERR_HTTP_SERVER_ERROR: FMOD_ErrorString = "A HTTP server error occurred. "
Case #FMOD_ERR_HTTP_TIMEOUT: FMOD_ErrorString = "The HTTP request timed out. "
Case #FMOD_ERR_INITIALIZATION: FMOD_ErrorString = "FMOD was not initialized correctly to support this function. "
Case #FMOD_ERR_INITIALIZED: FMOD_ErrorString = "Cannot call this command after Systeminit. "
Case #FMOD_ERR_INTERNAL: FMOD_ErrorString = "An error occured that wasnt supposed to. Contact support. "
Case #FMOD_ERR_INVALID_HANDLE: FMOD_ErrorString = "An invalid object handle was used. "
Case #FMOD_ERR_INVALID_PARAM: FMOD_ErrorString = "An invalid parameter was passed to this function. "
Case #FMOD_ERR_IRX: FMOD_ErrorString = "PS2 only. fmodex.irx failed to initialize. This is most likely because you forgot to load it. "
Case #FMOD_ERR_MEMORY: FMOD_ErrorString = "Not enough memory or resources. "
Case #FMOD_ERR_MEMORY_IOP: FMOD_ErrorString = "PS2 only. Not enough memory or resources on PlayStation 2 IOP ram. "
Case #FMOD_ERR_MEMORY_SRAM: FMOD_ErrorString = "Not enough memory or resources on console sound ram. "
case #FMOD_ERR_NEEDHARDWARE: FMOD_ErrorString = "Tried to use a feature that requires hardware support. (ie trying to play a VAG compressed sound in software on PS2). "
Case #FMOD_ERR_NEEDSOFTWARE: FMOD_ErrorString = "Tried to use a feature that requires the software engine but the software engine has been turned off. "
Case #FMOD_ERR_NET_CONNECT: FMOD_ErrorString = "Couldn't connect to the specified host. "
Case #FMOD_ERR_NET_SOCKET_ERROR: FMOD_ErrorString = "A socket error occurred. This is a catch-all for socket-related errors not listed elsewhere. "
Case #FMOD_ERR_NET_URL: FMOD_ErrorString = "The specified URL couldn't be resolved. "
Case #FMOD_ERR_NOTREADY: FMOD_ErrorString = "Operation could not be performed because specified sound is not ready. "
Case #FMOD_ERR_OUTPUT_ALLOCATED: FMOD_ErrorString = "Error initializing output device, but more specifically, the output device is already in use and cannot be reused. "
Case #FMOD_ERR_OUTPUT_CREATEBUFFER: FMOD_ErrorString = "Error creating hardware sound buffer. "
Case #FMOD_ERR_OUTPUT_DRIVERCALL: FMOD_ErrorString = "A call to a standard soundcard driver failed, which could possibly mean a bug in the driver or resources were missing or exhausted. "
Case #FMOD_ERR_OUTPUT_FORMAT: FMOD_ErrorString = "Soundcard does not support the minimum features needed for this soundsystem (16bit stereo output). "
Case #FMOD_ERR_OUTPUT_INIT: FMOD_ErrorString = "Error initializing output device. "
Case #FMOD_ERR_OUTPUT_NOHARDWARE: FMOD_ErrorString = "FMOD_HARDWARE was specified but the sound card does not have the resources nescessary to play it. "
Case #FMOD_ERR_OUTPUT_NOSOFTWARE: FMOD_ErrorString = "Attempted to create a software sound but no software channels were specified in System::init. "
Case #FMOD_ERR_PAN: FMOD_ErrorString = "Panning only works with mono or stereo sound sources. "
Case #FMOD_ERR_PLUGIN: FMOD_ErrorString = "An unspecified error has been FMOD_ErrorString =ed from a 3rd party plugin. "
Case #FMOD_ERR_PLUGIN_MISSING: FMOD_ErrorString = "A requested output, dsp unit type or codec was not available. "
Case #FMOD_ERR_PLUGIN_RESOURCE: FMOD_ErrorString = "A resource that the plugin requires cannot be found. "
Case #FMOD_ERR_RECORD: FMOD_ErrorString = "An error occured trying to initialize the recording device. "
Case #FMOD_ERR_REVERB_INSTANCE: FMOD_ErrorString = "Specified Instance in FMOD_REVERB_PROPERTIES couldn't be set. Most likely because another application has locked the EAX4 FX slot. "
Case #FMOD_ERR_SUBSOUND_ALLOCATED: FMOD_ErrorString = "This subsound is already being used by another sound, you cannot have more than one parent to a sound. Null out the other parent's entry first. "
Case #FMOD_ERR_TAGNOTFOUND: FMOD_ErrorString = "The specified tag could not be found or there are no tags. "
Case #FMOD_ERR_TOOMANYCHANNELS: FMOD_ErrorString = "The sound created exceeds the allowable input channel count. This can be increased with System::setMaxInputChannels. "
Case #FMOD_ERR_UNIMPLEMENTED: FMOD_ErrorString = "Something in FMOD hasn't been implemented when it should be! contact support! "
Case #FMOD_ERR_UNINITIALIZED: FMOD_ErrorString = "This command failed because System::init or System::setDriver was not called. "
Case #FMOD_ERR_UNSUPPORTED: FMOD_ErrorString = "A commmand issued was not supported by this object. Possibly a plugin without certain callbacks specified. "
Case #FMOD_ERR_UPDATE: FMOD_ErrorString = "On PS2, System::update was called twice in a row when System::updateFinished must be called first. "
Case #FMOD_ERR_VERSION: FMOD_ErrorString = "The version number of this file format is not supported. "
Case #FMOD_OK: FMOD_ErrorString = "No errors."
Default: FMOD_ErrorString = "Unknown error."
EndSelect
ProcedureReturn FMOD_ErrorString
EndProcedure
; ExecutableFormat=
; EOF
If you want to know how to save to a wav file, here is the "recording" example in purebasic :
Code: Select all
; ===============================================================================================
; Record example
; Copyright (c), Firelight Technologies Pty, Ltd 2004-2005.
;
; This example shows how to record a sound, then write it To a wav file.
; It then shows how to play a sound While it is being recorded to. Because it is recording, the
; sound playback has to be delayed a little bit so that the playback doesn't play part of the
; buffer that is still being written To.
; ===============================================================================================
XIncludeFile "../../api/purebasic/fmod_errors.pbi"
Global System.l, Sound.l, Channel.l
Global result.l
Structure RIFF_HEADER
RIFF.l
riffBlockSize.l
riffBlockType.l
EndStructure
Structure WAVE_HEADER
dataBlockType.l
dataBlockSize.l
EndStructure
Structure WAVE_FORMAT
wfBlockType.l
wfBlockSize.l
wFormatTag.w
nChannels.w
nSamplesPerSec.l
nAvgBytesPerSec.l
nBlockAlign.w
wBitsPerSample.w
EndStructure
#OUTPUT_FILE = 0
Procedure ERRCHECK(the_result.l)
If the_result <> #FMOD_OK
PrintN("FMOD error ! " + Str(the_result) + FMOD_ErrorString(the_result) )
Delay(2000)
End
EndIf
EndProcedure
Procedure SaveToWav(ptrSound.l)
Protected ptr1.l, ptr2.l, len1.l, len2.l
Protected lenbytes.l, channels.l, bits.l, rate.f
Protected m_structRIFF.RIFF_HEADER
Protected m_structWAVEHdr.WAVE_HEADER
Protected m_structWAVEFmt.WAVE_FORMAT
If ptrSound = 0
ProcedureReturn
EndIf
FMOD_Sound_GetFormat_ (ptrSound, 0, 0, @channels, @bits)
FMOD_Sound_GetDefaults_(ptrSound, @rate, 0, 0, 0)
FMOD_Sound_GetLength_(ptrSound, @lenbytes, #FMOD_TIMEUNIT_PCMBYTES)
; Prepare the Wave Header
m_structWAVEFmt\wFormatTag = 1
m_structWAVEFmt\nChannels = channels
m_structWAVEFmt\nSamplesPerSec = rate
m_structWAVEFmt\wBitsPerSample = bits
m_structWAVEFmt\nBlockAlign = m_structWAVEFmt\nChannels * m_structWAVEFmt\wBitsPerSample / 8
m_structWAVEFmt\nAvgBytesPerSec = m_structWAVEFmt\nSamplesPerSec * m_structWAVEFmt\nBlockAlign
m_structWAVEFmt\wfBlockType = $20746D66 ; 'f' 'm' 't'
m_structWAVEFmt\wfBlockSize = 16 ; SizeOf(FmtChunk) - SizeOf(RiffChunk)
m_structRIFF\RIFF = $46464952 ; 'R' 'I' 'F' 'F'
m_structRIFF\riffBlockSize = lenbytes + 44 - 12
m_structRIFF\riffBlockType = $45564157 ; 'W' 'A' 'V' 'E'
m_structWAVEHdr\dataBlockType = $61746164
m_structWAVEHdr\dataBlockSize = lenbytes
m_hNewFile = CreateFile(#OUTPUT_FILE, "record.wav")
If m_hNewFile = 0
MessageRequester("Error", "An error occured while creating record.wav file", 0)
ProcedureReturn
EndIf
; Write out the WAV Header
WriteData(m_structRIFF, SizeOf(RIFF_HEADER))
WriteData(m_structWAVEFmt, SizeOf(WAVE_FORMAT))
WriteData(m_structWAVEHdr, SizeOf(WAVE_HEADER))
; Lock the sound to get access to the raw data.
FMOD_Sound_Lock_(ptrSound, 0, lenbytes, @ptr1, @ptr2, @len1, @len2)
;Write it to disk.
WriteData(ptr1, len1)
; Unlock the sound to allow FMOD to use it again.
FMOD_Sound_Unlock_(ptrSound, ptr1, ptr2, len1, len2)
; And close the output file
CloseFile(#OUTPUT_FILE)
EndProcedure
OpenConsole()
; Create a System object And initialize.
result = FMOD_System_Create_(@System)
ERRCHECK(result)
result = FMOD_System_GetVersion_(System, @version)
ERRCHECK(result)
If version < #FMOD_VERSION
MessageRequester("Error", "Error ! You are using an old version of FMOD " + Hex(version >> 16) + "." + Hex(version & $FF) + ". This program requires " + Hex(#FMOD_VERSION >> 16) + "." + Hex(#FMOD_VERSION & $FF) )
EndIf
; System initialization
PrintN("---------------------------------------------------------");
PrintN("Select OUTPUT type")
PrintN("---------------------------------------------------------")
PrintN("1 : DirectSound")
PrintN("2 : Windows Multimedia WaveOut")
PrintN("3 : ASIO")
PrintN("---------------------------------------------------------")
PrintN("Press a corresponding number or ESC to quit")
Repeat
ch.s = Inkey()
If Asc(ch) = 27
CloseConsole()
End
EndIf
value = Val(Left(ch, 1))
Delay(10)
Until (value >= 1 And value <= 3)
Select value
Case 1 : result = FMOD_System_SetOutput_(System, #FMOD_OUTPUTTYPE_DSOUND)
Case 2 : result = FMOD_System_SetOutput_(System, #FMOD_OUTPUTTYPE_WINMM)
Case 3 : result = FMOD_System_SetOutput_(System, #FMOD_OUTPUTTYPE_ASIO)
EndSelect
ERRCHECK(result)
; Enumerate playback devices
result = FMOD_System_GetNumDrivers_(System, @numdrivers)
ERRCHECK(result)
PrintN("---------------------------------------------------------")
PrintN("Choose a PLAYBACK driver")
PrintN("---------------------------------------------------------")
For count=0 To numdrivers - 1
name.s = Space(256)
result = FMOD_System_GetDriverName_(System, count, @name, 256)
ERRCHECK(result)
PrintN(Str(count+1) + " : " + name)
Next count
PrintN("---------------------------------------------------------")
PrintN("Press a corresponding number or ESC to quit\n")
Repeat
ch.s = Inkey()
value = Val(Left(ch, 1))
Delay(10)
Until value > 0 And value <= numdrivers
result = FMOD_System_SetDriver_(system,value-1)
ERRCHECK(result)
; Enumerate record devices
result = FMOD_System_GetRecordNumDrivers_(System, @numdrivers)
ERRCHECK(result)
PrintN("---------------------------------------------------------")
PrintN("Choose a RECORD driver")
PrintN("---------------------------------------------------------")
For count=0 To numdrivers - 1
name.s = Space(256)
result = FMOD_System_GetRecordDriverName_(System, count, @name, 256)
ERRCHECK(result)
PrintN(Str(count+1) + " : " + name)
Next count
PrintN("---------------------------------------------------------")
PrintN("Press a corresponding number or ESC to quit")
Repeat
ch.s = Inkey()
value = Val(Left(ch, 1))
If value = 27
CloseConsole()
End
EndIf
Delay(10)
Until value > 0 And value <= numdrivers
result = FMOD_System_SetRecordDriver_(System, value)
ERRCHECK(result)
result = FMOD_System_Init_(System, 32, #FMOD_INIT_NORMAL, 0)
ERRCHECK(result)
exinfo.FMOD_CREATESOUNDEXINFO
RtlZeroMemory_(exinfo, SizeOf(FMOD_CREATESOUNDEXINFO))
exinfo\cbsize = SizeOf(FMOD_CREATESOUNDEXINFO)
exinfo\numchannels = 1
exinfo\format = #FMOD_SOUND_FORMAT_PCM16
exinfo\defaultfrequency = 44100
exinfo\length = exinfo\defaultfrequency * 2 * exinfo\numchannels * 5
result = FMOD_System_CreateSound_(System, 0, #FMOD_2D | #FMOD_SOFTWARE | #FMOD_OPENUSER, @exinfo, @Sound)
ERRCHECK(result)
PrintN("===================================================================")
PrintN("Recording example. Copyright (c) Firelight Technologies 2004-2005.")
PrintN("===================================================================")
PrintN("")
PrintN("Press 'r' to record a 5 second segment of audio and write it to a wav file.")
PrintN("Press 'p' to play the 5 second segment of audio.")
PrintN("Press 'l' to turn looping on/off.")
PrintN("Press 's' to stop recording and playback.")
PrintN("Press 'w' to save the 5 second segment to a wav file.")
PrintN("Press 'Esc' to quit")
PrintN("")
Repeat
key.s = LCase(Left(Inkey(),1))
looping = 0
recording = 0
playing = 0
recordpos = 0
playpos = 0
Select key
Case "r"
result = FMOD_System_RecordStart_(System, Sound, looping)
ERRCHECK(result)
Case "p"
If (looping)
FMOD_Sound_SetMode_(Sound, #FMOD_LOOP_NORMAL)
Else
FMOD_Sound_SetMode_(Sound, #FMOD_LOOP_OFF)
EndIf
ERRCHECK(result)
result = FMOD_System_PlaySound_(System, #FMOD_CHANNEL_REUSE, Sound, 0, @Channel)
ERRCHECK(result)
Case "l"
looping ! 1
Case "s"
result = FMOD_System_RecordStop_(System)
If Channel
FMOD_Channel_Stop_(Channel)
channel = 0
EndIf
Case "w"
PrintN("Writing to record.wav ... ")
SaveToWav(Sound)
Delay(500)
EndSelect
FMOD_Sound_GetLength_(Sound, @length, #FMOD_TIMEUNIT_PCM)
ERRCHECK(result)
FMOD_System_IsRecording_(System, @recording)
ERRCHECK(result)
FMOD_System_GetRecordPosition_(System, @recordpos)
ERRCHECK(result)
If (Channel)
FMOD_Channel_IsPlaying_(Channel, @playing)
ERRCHECK(result)
FMOD_Channel_GetPosition_(Channel, @playpos, #FMOD_TIMEUNIT_PCM)
ERRCHECK(result)
EndIf
playback_status.s = Space(20)
playback_status = ""
If recording
If playing
playback_status = "Recording / Playing"
Else
playback_status = "Recording"
EndIf
ElseIf playing
playback_status = "Playing"
Else
playback_status = "Idle"
EndIf
loop.s = Space(3)
loop = " "
If looping
loop = "On"
Else
loop = "Off"
EndIf
ConsoleLocate(0, 23)
PrintN("State : " + playback_status + " Record pos = " + Str(recordpos) + " : Play pos = " + Str(playpos) + " : Loop = " + loop)
FMOD_System_Update_(System)
Delay(10)
Until Asc(key) = 27
PrintN("")
; Shut down
result = FMOD_Sound_Release_(sound)
ERRCHECK(result)
result = FMOD_System_Release_(system)
ERRCHECK(result)
CloseConsole()
End
Posted: Sun Jan 14, 2007 2:56 am
by ricardo
Hi KarLKoX
Thanks.
Im writing to disc as wav file using another method
Code: Select all
FMOD_System_Create(@fmodsystem)
result = FMOD_System_SetOutputByPlugin(fmodsystem,3)
ERRCHECK(result)
FMOD_System_Init(fmodsystem, 32, #FMOD_INIT_NORMAL, 0)
FMOD_System_CreateSound(fmodsystem, @str, #FMOD_SOFTWARE | #FMOD_CREATESTREAM, 0, @sound) ;#FMOD_HARDWARE
FMOD_System_PlaySound(fmodsystem, 0, sound, 0, @channel)
I tried to use the mp3 plugin without sucess, but as i really was lokking for write as wav im fine with it.
Whats the difference betwen this approach and yours (in results i mean)?
Posted: Mon Jan 22, 2007 9:00 am
by Froggerprogger
Just updated the include, there was a bug in:
FMOD_DSP_DESCRIPTION
Changed name.s to name.b[32]
Thanks for that to ricardo.
This bug already existed in the fmod.bas file I used for translation to PB.
Posted: Fri Feb 02, 2007 11:27 am
by Froggerprogger
I just updated the file for fmod 4.06.06 (current stable version)
There is only 1 change made to the previous version: the version-number in #FMOD_VERSION
I had a look at fmod 4.07.03 beta, and there's still exactly the same api (all but the version-number).
Posted: Tue Feb 27, 2007 8:22 pm
by Joakim Christiansen
I really love this include file, but can anyone tell me why this is not working?
(it doesn't write any info to the TAG structure...)
Code: Select all
IncludeFile "fmodex.pb"
Init_FMOD()
FMOD_System_Create(@System)
FMOD_System_Init(System,1,#FMOD_INIT_NORMAL,#Null)
File$ = OpenFileRequester("Open media:","","",0)
If File$
Define TagCount, i, Tag.FMOD_TAG
FMOD_System_CreateStream(System,@File$,#FMOD_DEFAULT,#Null,@Sound)
FMOD_Sound_GetNumTags(Sound,@TagCount,#Null)
Debug "Number of tags: " + Str(TagCount)
For i=0 To TagCount-1
FMOD_Sound_GetTag(Sound,#NULL$,i,@Tag)
Debug "TAG Struct:"
Debug Tag\type
Debug Tag\datatype
Debug Tag\name
Debug Tag\_data
Debug Tag\datalen
Debug Tag\udated
Debug ""
Next
EndIf
FMOD_Sound_Release(Sound)
FMOD_System_Release(System)