FMOD Soundcard-test

Share your advanced PureBasic knowledge/code with the community.
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

FMOD Soundcard-test

Post by Froggerprogger »

The following code shows how to test the available soundcard-drivers using DSound / WinMM / ASIO and others from within the fmod.dll.

Code: Select all

; FMOD soundcard - test
;
; An example of how to check the capabilities of your soundcard.
; All data is stored inside a LinkedList for further processing.
;
; written for FMOD 3.71 and needs the FMOD-Wrapper for PureBasic to compile
;
; by Froggerprogger, 25.02.04

Structure SFX_DriverData
  outputmodeID.l
  outputmode.s
  driverID.l
  drivername.s
  flag_hardware.l
  flag_eax2.l
  flag_eax3.l
EndStructure

NewList Sounddrivers.SFX_DriverData()

Procedure FSOUND_TestOutputmode(outputmodeID.l, outputmode.s)
  
  If FSOUND_SetOutput(outputmodeID) = #False
    MessageRequester("","Cannot initialize output... FSOUND_Init() must not be called before FSOUND_SetOutput()",#MB_ICONERROR)
    ProcedureReturn #False
  EndIf
  
  Protected numDrivers.l  : numDrivers = FSOUND_GetNumDrivers()
  Protected i.l, caps.l
  
  If numDrivers = 0
    AddElement(Sounddrivers())
    Sounddrivers()\outputmodeID = outputmodeID
    Sounddrivers()\outputmode = outputmode
    Sounddrivers()\drivername = "none available"
  
  Else
    For i = 0 To numDrivers - 1
      AddElement(Sounddrivers())  
      
      Sounddrivers()\outputmodeID = outputmodeID
      Sounddrivers()\outputmode = outputmode
      Sounddrivers()\driverID = i
      If FSOUND_GetDriverName(i) <> 0
        Sounddrivers()\drivername = PeekS(FSOUND_GetDriverName(i))
      Else
        Sounddrivers()\drivername = "no name"
      EndIf
      
      FSOUND_GetDriverCaps(i, @caps)
      Sounddrivers()\flag_hardware = caps & #FSOUND_CAPS_HARDWARE
      Sounddrivers()\flag_eax2 = caps & #FSOUND_CAPS_EAX2
      Sounddrivers()\flag_eax3 = caps & #FSOUND_CAPS_EAX3
    Next
  EndIf
  
  ProcedureReturn numDrivers
EndProcedure

Procedure FSOUND_TestSoundcard()
  
  ; just for fun all of the types
  ; normally WINMM, DSOUND and perhaps ASIO is enough for Windows
  
  SetGadgetText(0, "Testing soundcard, please wait...")

  FSOUND_TestOutputmode(#FSOUND_OUTPUT_WINMM, "WinMM")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_DSOUND, "DirectSound")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_A3D, "A3D")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_OSS, "OSS Open Sound System")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_ESD, "ESD")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_ALSA, "Alsa")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_ASIO, "ASIO")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_XBOX, "XBOX")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_PS2, "Playstation 2")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_MAC, "MAC")
  FSOUND_TestOutputmode(#FSOUND_OUTPUT_GC, "GameCube")

  SetGadgetText(0, "")
EndProcedure

; Open a window and put some gadgets onto in
OpenWindow(0,0,0,400,600, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "FMOD soundcard-test by Froggerprogger")
  CreateGadgetList(WindowID())
  TextGadget(0, 4, 4, 392, 20, "")
  ListIconGadget(1, 4, 24, 392, 572, "results:", 392)

; We must not have called FSOND_Init() before !
FSOUND_TestSoundcard()

; Output
ForEach Sounddrivers()
  AddGadgetItem(1, -1, "_________________________________________________")
  AddGadgetItem(1, -1, "OutputID: " + Str(Sounddrivers()\outputmodeID) + "   ( " + Sounddrivers()\outputmode + " )")
  AddGadgetItem(1, -1, "DriverID: " + Str(Sounddrivers()\driverID) + "   ( " + Sounddrivers()\drivername + " )")
  
  If Sounddrivers()\drivername = "No Sound Driver"
    Continue
  EndIf
  
  If Sounddrivers()\flag_hardware
    AddGadgetItem(1, -1, "- Hardwarechannels supported")
  Else
    AddGadgetItem(1, -1, "- no Hardwarechannels")
  EndIf

  If Sounddrivers()\flag_eax2
    AddGadgetItem(1, -1, "- EAX 2 supported")
  Else
    AddGadgetItem(1, -1, "- no EAX 2")
  EndIf

  If Sounddrivers()\flag_eax3
    AddGadgetItem(1, -1, "- EAX 3 supported")
  Else
    AddGadgetItem(1, -1, "- no EAX 3")
  EndIf
Next

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Last edited by Froggerprogger on Wed Feb 25, 2004 9:03 pm, edited 1 time in total.
%1>>1+1*1/1-1!1|1&1<<$1=1
merendo
Enthusiast
Enthusiast
Posts: 449
Joined: Sat Apr 26, 2003 7:24 pm
Location: Germany
Contact:

Post by merendo »

Image
Is that good?
The truth is never confined to a single number - especially scientific truth!
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

What do you want to know ?
You have a 2-channel (stereo) soundcard that supports the 'normal' WinMM-driver and DSound-hardwarechannels, so you are able to do some fast DirectX-FX on them.
Together with the possibility of using EAX 3 it has all the features, that a sfx-card for e.g. modern games needs.
If there wouldn't be any DSound-hardware-channel, you couldn't use the FSOUND_FX_* - commands for reverb/chorus/echo/eq, etc.
Further hardwarechannels do spare CPU-time, so they should be used instead of softwarechannels whenever possible.

Further you have drivers for ASIO installed. ASIO-drivers have a very low Input/Output-latency, so you could do some homerecording or playing software-sampler using them instead of the slower (latency) DSound-driver. ASIO is the standard for audio-editing-software.
It is normal, that they have no other features, because they are used with professional host-based-FX-plugIns. Some sfx-cards do have own DSP-chips that can be achieved by special software to calculate PlugIns written espacially for them without using the CPU. But this feature, as well as multitrack I/O-ASIO, cannot be used by fmod.

That's all I know about it, but I might be wrong in some points.
%1>>1+1*1/1-1!1|1&1<<$1=1
merendo
Enthusiast
Enthusiast
Posts: 449
Joined: Sat Apr 26, 2003 7:24 pm
Location: Germany
Contact:

Post by merendo »

Well, i hope my snd card is a good one. I payed a lot for it and it's a very modern one. However i think your tool is very useful, especially for games which use FMOD for the snd output. Good work :)
The truth is never confined to a single number - especially scientific truth!
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

First of all, sorry for being a bit off-topic here...

merendo wrote:Well, i hope my snd card is a good one. I payed a lot for it and it's a very modern one.
I don't think you wanted an answer to this, but I can't resist: It always depends on what you're up to...

Soundblaster Audigy:
games? yes!
semi-professional or even professional usage: No way!
Froggerprogger wrote: Some sfx-cards do have own DSP-chips that can be achieved by special software to calculate PlugIns written espacially for them without using the CPU.
AFAIK there's no card that has both D/A A/D conversion _and_ dsp-power,
but in case someones interested, here're the links the two most succesful audio-dsp-cards available for PC:


Universal Audio UAD-1 : http://www.uaudio.com/products/digital/UAD-1/index.html
TC Powercore : http://www.tcelectronic.com/PowerCore

I have them both (2x UAD, 1x Powercore) and they both are really great!

Note: You still need a soundcard in order to hear something, these cards only do the cpu-intensive calculation.


Getting back to the topic: Nice example Froggerprogger! :D
Good programmers don't comment their code. It was hard to write, should be hard to read.
kns
User
User
Posts: 54
Joined: Sat Apr 26, 2003 2:06 am

Post by kns »

Hello,

Where is the most recent install of fmod for purebasic? I have unzipped the archive posted on Nov 29 of last year. What I have found is that most of the examples in samplesPureBasic do not work. Off the top of my head the 3D and "simplest" examples do work. Compiling and running the above code generates an application error of the form that a referenced memory could not be written?

Any ideas?

Thanks.
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

@traumatic
AFAIK there's no card that has both D/A A/D conversion _and_ dsp-power
There are some soundcards with I/O and DSPs, e.g. the creamware Luna II(has stereo I/O that can be expanded with extra-kits, and a DSP for the SCOPE-DSP-plugIns. There are also some others of this type from creamware) e.g. for use with tripledat.

Further there are some soundcards out there that use the DSP-power only for internal mixing, e.g. the RME Multiface (that's the one I have) does use the DSP-power exclusively for an internal mixer (placed directly on the soundcard with nearly zero latency, very cool for realtime-monitor-mixes) and a realtime-analyser.
I think Hoontec DSP is of the same type.
The ProTools TDM-system does do all of this, too, but ok - it's not just a soundcard anymore.

But of course this type of cards do make no sense for the 'normal' usage. They're for e.g. digital soundstudios.



@kns
You should redownload the PureBasic-interface by KarLKoX from fmod.org. He included the fmod-Wrapper a few week ago. Or you can download only the fmod-wrapper from here: http://fmod.2mal2mal.de (There are some examples and the Wrapper-ZIP) or from the PureArea, of course, look here: http://www.purearea.net/pb/english/userlibs.php

To 'install' just replace the fmod.dll in your 'compiler'-dir by version 3.71 and copy the wrapper to the 'userlib'-dir and the .res-file to the 'resident'-dir. - See the Readme.txt

For understanding:
There are two ways of using fmod: You could include the two .pbi files coming with the 'interface' into each of your project to access all of the fmod-functions. But there exist some problems receiving Floats when doing it this way and it's not the fasted way, because they are PB-Procedure-wrapped functioncalls.
Using the wrapper instead links directly from your code to the fmod-functions in speed of callfunctionfast, and returning floats is no problem.
But there are two functions that are not part of the DLL that you have to include again, see the fmod-addon-file of the wrapper-zip.

The PB-examples inside the package are for use with fmod 3.71 and the include-file-version. To run these examples with the wrapper instead, you have to comment out the Load_FMOD and Close_FMOD - calls (they're just for the Open/CloseLibrary()) and to comment out the FMOD_GetErrorString-calls or include the FMOD_ADDON-file. (See the wrapper-package for more details)

I hope I didn't confuse you with my description.
I will write a short 'Getting started with fmod and PB' in near future, because there are some other things to mention, e.g. the changes from fmod 3.70 to 3.71.
%1>>1+1*1/1-1!1|1&1<<$1=1
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Froggerprogger wrote: There are some soundcards with I/O and DSPs, e.g. the creamware Luna II(has stereo I/O that can be expanded with extra-kits, and a DSP for the SCOPE-DSP-plugIns. [/url].
Yes you're right, I totally forgot about the Creamware-Stuff...
Further there are some soundcards out there that use the DSP-power only for internal mixing, [...]
Yes of course, but you said something about rendering plugins on the hardware, that's not possible with these cards.
[...]RME Multiface (that's the one I have[...]
Good card! What are you doing with it? Do you also record 'real' instruments or just using VSTi s ?
The ProTools TDM-system
Yes, good ol' ProTools... Too expensive and pretty overrated IMHO... :oops:
Good programmers don't comment their code. It was hard to write, should be hard to read.
Post Reply