0
0

I’m trying to get a version of the record example working that playbacks the sound almost as soon as it is recorded.

I first set up the sound with the following code:
[code:2gkeabb1]
FMOD_RESULT res = FMOD_OK;

//set up sound info
memset(&g_soundexInfo,0,sizeof(g_soundexInfo));
g_soundexInfo.cbsize = sizeof(g_soundexInfo);
g_soundexInfo.numchannels = 2;
g_soundexInfo.format = FMOD_SOUND_FORMAT_PCM16;
g_soundexInfo.defaultfrequency = 44100;
g_soundexInfo.length = g_soundexInfo.defaultfrequency * sizeof(short) * g_soundexInfo.numchannels * 5;

res = g_pFMODSystem->createSound(0, FMOD_LOOP_NORMAL | FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &g_soundexInfo, &g_pSound);
if ( res != FMOD_OK )   goto e0;

res = g_pFMODSystem->recordStart(g_pSound,true);
if ( res != FMOD_OK )   goto e1;

g_pFMODSystem->playSound(FMOD_CHANNEL_REUSE,g_pSound,false,&g_pChannel);

return res;

e1:
g_pSound->release();
g_pSound = NULL;
e0:
return res;
[/code:2gkeabb1]

then my main loop looks like this

[code:2gkeabb1]
while(!bQuit)
{
static unsigned int lastrecordpos = 0;
unsigned int recordpos = 0;

    if ( kbhit() )
    {
        bQuit = true;
    }
    else
    {
        res = g_pFMODSystem->getRecordPosition(&recordpos);
        if ( recordpos != lastrecordpos )
        {
        void    *ptr1=NULL;
        void    *ptr2=NULL;
        unsigned int len1=0;
        unsigned int len2=0;
        int blocklen=0;

            blocklen = (int)recordpos - (int)lastrecordpos;
            if ( blocklen < 0 )
            {
                blocklen += soundlength;
            }

            //lock recorded sound and write it to disk
            g_pSound->lock(lastrecordpos * g_soundexInfo.numchannels * 2,
                            blocklen * g_soundexInfo.numchannels * 2,
                            &ptr1,
                            &ptr2,
                            &len1,
                            &len2);

            WritePCM(g_fout,ptr1,len1,ptr2,len2);

            g_pSound->unlock(ptr1, ptr2, len1, len2);


        }
        lastrecordpos = recordpos;

        g_pFMODSystem->update();
    }
}

[/code:2gkeabb1]

However playback seems to overrun the record position resulting in distortion. How can I introduce a delay so it does’nt. The recorded sound is OK.

Mark

  • You must to post comments
0
0

Hi Brett,

Are you saying that FMOD 4 can also have this drift problem (which you address in the FMOD 3 recording example)? We have a reported problem currently where the delay between recording and playback gets much worse. Perhaps the playback pointer is outrunning the record pointer?

Thanks.

 - Rick
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.