Jump to content
Sign in to follow this  

Use fmod to play sounds at volume

Recommended Posts


After looking far and wide on the site for playing sounds at volume on all platforms, I figured they is not solution but to take control of the sound system as you would in a game.... Not to rely on the OS GUI to setup the volume as in the app volume in WIN:8, but in the application itself, like most games on Windows.. I decided to use my fmod experience for overcoming the SoundPlay and SoundSetWaveVolume limitation in AutoIT.

As you may have found out loooking in the docs, SoundSetWaveVolume sets the volume of the wav mixer in older window's OS. it means you change the wav out (for every app) to the volume specified. In short, you screwed up the user's settings. So the user will be wondering why his app or game sound is lower than usuall because your app screwed with his setttings... ,confusion.

The best thing to do is to control the volume of each sound your app plays. I have writen a fmod wrapper for gamemaker so I figure I would insight you into using fmod for this type of need.

You need to make a fmod wrapper dll and you need fmod. fmod plays all types of sounds on all windows platforms. And the licensing is interesting if you play your cards right...

Basic dumb ass setup for AutoIT and FMOD:


get FMOD at http://fmod.org/fmod-downloads.html

download the API and install it.

Copy the fmod dll in your autoit project...

AutoIT code

func myplaysound($filename, $vol)
;filename is the full path and name.ext
;vol is a 0 to 1 value
return DllCall(@ScriptDir & "\myFMODwrap.DLL", "int:cdecl", "myplaysound", "str", $filename, "float",$vol)

create a wrapper dll myFMODwrap with code::blocks or ms dev studio with this file: new dll project: myFMODwrap



#include "main.h"
#include <windows.h>
#include <fmod.h>
#include <fmod_errors.h>
#include <string>
#include <stdio.h>
#define MYEXPORT __declspec (dllexport)

if (result != FMOD_OK)
     MessageBoxA(NULL, FMOD_ErrorString(result), MB_IConerror);
     return 0;

return 1;
extern "C"

// a sample exported function
DLL_EXPORT int myplaysound(LPCSTR filename, float vol)

FMOD_SYSTEM  *system;
FMOD_SOUND   *sound1;
FMOD_CHANNEL     *channel = 0;
FMOD_RESULT  result;
unsigned int     version;
int          playing = 0;
//MessageBoxA(NULL,"Debug", "1", MB_IConerror);
//char *filename = strtok((lpszArgument),",\"");
//MessageBoxA(NULL, filename,"myPlaySound", MB_IConerror);
// std::string msg = "Hello";
// char msg2[20];
// float my_float = 10.0f;
// sprintf((char*)msg2, "%f", vol);
// msg = msg + msg2;// + ftoa(my_float);
// MessageBox(NULL,"In the dll", msg2,0);
result = FMOD_System_Create(&system);
//MessageBoxA(NULL,"Play Called", "FMOD_System_Create", MB_IConerror);
     result = FMOD_System_GetVersion(system, &version);
         if (version == FMOD_VERSION)
             result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
             //MessageBoxA(NULL,"gpPlaySound - by Gilles Page", "FMOD_System_Init", MB_IConerror);
                 result = FMOD_System_CreateSound(system, filename, FMOD_HARDWARE | FMOD_LOOP_OFF, 0, &sound1);
                 //MessageBoxA(NULL,"gpPlaySound - by Gilles Page", "FMOD_System_CreateSound", MB_IConerror);
                     result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel);
                     //MessageBoxA(NULL,"gpPlaySound - by Gilles Page", "FMOD_System_PlaySound", MB_IConerror);
                         result = FMOD_Channel_SetVolume(channel,vol);
/// sprintf((char*)msg2, "%f", vol);
/// msg = msg + msg2;// + ftoa(my_float);
/// MessageBox(NULL,"In the playing", msg2,0);
                                 result = FMOD_Channel_IsPlaying(channel, &playing);


                             } while (playing);

                 result = FMOD_System_Close(system);
return 1;

} //EXTERN "C"
extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
switch (fdwReason)
         // attach to process
         // return FALSE to fail DLL load

         // detach from process

         // attach to thread

         // detach from thread
return TRUE; // succesful

1) create a new dll project with ms dev studio or code::blocks

2) replace the generated main code with the suplied code

3) add fmod 's inc folder to your additional include in ms dev or code;;blocks

4) add fmodexp_vc.lib (ms studio) or fmodex.a (code::blocks) to your additional lib options

5) compile and copy the dll to your au3 directory, and also copy fmodex.dll to the same location

I tried to acess fmod directly from the autoit script but it had trouble with the double ref **system. so a wrapper did the job for me. I have a method to play the sound, though locking the GUI... you can add the fmod update call to your api and call it from your main GUI loop for asynchronus playing... or in a timed function call... FMODUptate()....

Edited by icuurd12b42

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.