I’m not really sure how I managed this but I have a 8 second delay from the time I talk in the microphone and the time it’s data appears in my spectrum window, or is heard over the speakers…

It’s the first time I attempt to use the mic with FMOD… I used the Pitch Detection example to figure out how to start it up… the main difference with it and my code is that I alread defined how I would init my system for the rest of my game so I not want to fiddle with this part…

So here is my mic code… It’s still in the preliminary stage of development…

Calling code
if(image_index == 1)
sound = FMODCreateSoundFromMicInput();
if (!sound) exit;
instance = FMODRecordStart(sound);
//instance = FMODSoundLoop(sound)
image_index = 1;
else if(image_index == 1)

DLL code

define OUTPUTRATE 48000

export double FMODCreateSoundFromMicInput()

memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels      = 1;
exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = OUTPUTRATE;
exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;
FMOD_SOUND * sound = NULL;

FMODASSERT(FMOD_System_CreateSound(mainsystem, 0, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound));
return (double) (DWORD) sound;


export double FMODRecordStart(double sound)
FMOD_CHANNEL * channel;
FMODASSERT(FMOD_System_RecordStart(mainsystem, 0, (FMOD_SOUND *)(DWORD) sound, TRUE));
FMODASSERT(FMOD_System_PlaySound(mainsystem, FMOD_CHANNEL_REUSE, (FMOD_SOUND *)(DWORD) sound, FALSE, &channel));
return (double) (DWORD) channel;

export double FMODRecordStop()

FMODASSERT(FMOD_System_RecordStop(mainsystem, 0));
return 1;


and here is my init
export double FMODinit(double maxsounds, double supportwebfiles)

pds_list_add = (GMPROC*) GetProcAddress("ds_list_add");


 unsigned int     version;
FMOD_CAPS        caps;
int              numdrivers; 

    Create a System object and initialize.

FMODASSERT(FMOD_System_Create(&mainsystem));        // Create the main system object.


if (version < FMOD_VERSION)
    MessageBoxA(GetActiveWindow(),"initFMOD-Incompatible fmodex.dll found. It's possible another game or product is running using and older version of this dll or the supplied fmod dll is incompatible.", "FMOD Error", MB_ICONSTOP);

if (numdrivers == 0) 
    FMODASSERT(FMOD_System_GetDriverCaps(mainsystem, 0, &caps, 0, 0, &speakermode));
    FMODASSERT(FMOD_System_SetSpeakerMode(mainsystem,speakermode));       /* Set the user selected speaker mode. */

    if (caps & FMOD_CAPS_HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
    {                                                   /* You might want to warn the user about this. */
        MessageBoxA(GetActiveWindow(),"You've turned windows 'Acceleration' too low and will experience major slow downs. You can fix this in the control panel's hardware acceleration options. Location varies depending your Windows version.", "FMOD Warning", MB_ICONWARNING);
        //Dont care if this fails
        FMOD_System_SetDSPBufferSize(mainsystem,1024, 10);    /* At 48khz, the latency between issuing an fmod command and hearing it will now be about 213ms. */
    //Dont care if this fails
    FMOD_System_SetHardwareChannels(mainsystem, 32, 64, 32, 64);
result = FMOD_System_Init(mainsystem,(int)maxsounds, FMOD_INIT_NORMAL /*|FMOD_INIT_VOL0_BECOMES_VIRTUAL*/ , 0); // Initialize FMOD.
   result = FMOD_System_Init(mainsystem,(int)maxsounds, FMOD_INIT_NORMAL /*| FMOD_INIT_VOL0_BECOMES_VIRTUAL*/ , 0);

    FMODASSERT(FMOD_System_SetStreamBufferSize(mainsystem,64*1024, FMOD_TIMEUNIT_RAWBYTES));

FMODASSERT(FMOD_System_CreateChannelGroup(mainsystem, "priority", &priority));
FMODASSERT(FMOD_System_CreateChannelGroup(mainsystem, "effects", &effects));
FMODASSERT(FMOD_System_CreateChannelGroup(mainsystem, "ambientmusic", &ambientmusic));
FMODASSERT(FMOD_System_CreateChannelGroup(mainsystem, "ambienteffects", &ambienteffects));
FMODASSERT(FMOD_System_GetMasterChannelGroup(mainsystem, &maingrp));

    FMODASSERT(FMOD_System_SetFileSystem(mainsystem,myopen, myclose, myread, myseek,2048));

inited = true;
return (double) 1;


  • You must to post comments

your problem seems to be that you have a 5 second sleep in there.

The point of a sleep is to wait a little bit before so that the recorder can record some data, then you can start playing it. Try changing the sleep 5000 to 100ms instead, then tweak from there.

  • You must to post comments

[quote="brett":f2ck7666]your problem seems to be that you have a 5 second sleep in there.

The point of a sleep is to wait a little bit before so that the recorder can record some data, then you can start playing it. Try changing the sleep 5000 to 100ms instead, then tweak from there.[/quote:f2ck7666]

I’m not exactly sure how that sleep(5000) got there…

Oh yes, that is due to another problem I just hit… It looks like the mic state gets corrupted somehow…

1) Start with no sleep, 8 second delay
2) close the app
3) Change to use sleep 200
4) Start with sleep 200, 8 second delay
5) Change to use sleep 5000
6) Start with sleep 5000, 8 second delay


1) Start with sleep 200, 200ms second delay
2) decrease to 100, … no recording, I hear pink noise
3) increase to 200, no recording still

Without the sleep, I had the delay… And, because of that corrupted state, fixing by adding the sleep to 200 did nothing so I then set it to 5000…

When you pointed out my sleep being the culprit just now, I changed it back to 200 and it worked and my jaw dropped… I then decreased it to 100 and then I only heard static… Re increasing it had not effect. I need to reboot and retry now before I end this post.

So I have a dual problem here…

I need to figure the best way to have little delay as possible… But if I go under a range it screws up and I need to reboot…

Looks like I’m stuck in a very narrow window here. And would that window vary from pc to pc?

Is there a way to wait for a resonably safe period then reset the positon… A way the user can define the amount of delay safely?

  • You must to post comments

OK, I’m getting a little desperate here

I’m getting rather sick of trial and error. If someone would care to explain to me how to achieve the following

Start the mic cleanly so I don’t get static and noise pulses
Setup the mic channel so it plays live or close enough to live. Because having a 200 ms delay is not acceptable

1) I have to wait at least 200 millisecond like the example shows or the system “garbages” out on me (No recorded sounds, only noise).

2) After I have waited, I can set the position to near the currently recorded sound, setting the position to about 150 ms is the best I could do. Anything closer to real time and I get a lot of static and noise pulses.

3) The channel is noisy. I still get the occasional loud pops.

4) I was able to reduce the noise by adding a low pass filter on the channel but now I have to delay for a longer period otherwise I get more noise pulses

5) I have ghost recording. If I close my application and restart it. When I click my record button, I have old ghost of my previous recording faintly playing in the back.

The only way I was able to get an acceptable channel was to
1) Start the recording
2) Wait for 5 seconds before attaching a channel to it
3) Set the channel volume to 0
4) Add the low pass filter
5) System Update until the position is at the end of the buffer (Another 5 second delay because that’s the size of the buffer)
6) Set the position to the end of the buffer – 50 millisecs
7) Set the volume to 1 to hear it (I have my head phones ON to prevent feedback)

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.