0
0

Hello,

I’ve been playing around with writing audio to a file using a DSP (like philouuuu). My source of inspiration was the following thread:

http://52.88.2.202/forum/viewtopic.php?p=34609

I am using this method because FMOD_OUTPUTTYPE_WAVWRITER does not play the audio as it writes the file. I am looking to play a sound and output it to a file at the same time, in real time.

Anyway, for the most part, it works, except I am experiencing periodic jumps in CPU usage by the DSP. During these jumps, the audio being heard stutters, even in the simulator! I am assuming that this is happening as the write buffer dumps to the file system, but I am not sure. I am just using a plain fwrite within the DSP. The interesting thing is that when I play back the audio file that I recorded, there is no stuttering.

Is there a better way to output what I am hearing to a file? Is there a better file write call than fwrite for iPhone / Objective C?

I am using FMOD Ex build 00042709.

Thanks in advance for your help, as always.

  • George
  • You must to post comments
0
0

The reason that the file doesn’t stutter and the real time output does is that the sound going through the FMOD mixer isn’t stuttering, it’s just that the FMOD mixer cant feed the system output fast enough.

You’re probably right that the file system is causing the stuttering. Maybe you could try adding your own layer of buffering to the file writing to reduce the amount of disk access? Mathew will probably be able to shed more light on that.

-Pete

  • You must to post comments
0
0

I am surprised you are hearing stuttering with the simulator, it’s basically the equivalent of running on your mac native. Can you show us the code for your custom DSP.

Since the DSP code will be run by the mixer, if your code takes too long to execute it will stutter the mixer. The file output will be correct however because it doesn’t rely on time.

  • You must to post comments
0
0

Thanks Mathew,

Here’s my code. Pretty much the same as what was posted in the post I mentioned:

[code:1l8lw70c] unsigned int userdata = 0;
char name[256] = {0};
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;

/* 
 This redundant call just shows using the instance parameter of FMOD_DSP_STATE and using it to 
 call a DSP information function. 
     NOT SURE IF THESE ARE ACTUALLY NEEDED
 */
thisdsp->getInfo(name, 0, 0, 0, 0);

thisdsp->getUserData((void **)&userdata);

/*
 This loop assumes inchannels = outchannels, which it will be if the DSP is created with '0' 
 as the number of channels in FMOD_DSP_DESCRIPTION.  
 Specifying an actual channel count will mean you have to take care of any number of channels coming in,
 but outputting the number of channels specified.  Generally it is best to keep the channel 
 count at 0 for maximum compatibility.
 */
int dpp = 0;

unsigned int count, count2;

for (count = 0; count < length; count++)
{

    for (count2 = 0; count2 < outchannels; count2++)
    {             
        // Just copy the data to the outbuffer, no matter what it is
        outbuffer[(count * outchannels) + count2] = inbuffer[(count * inchannels) + count2];
    // This is what we calculate to output to the file
    float valu = inbuffer[(count * inchannels) + count2] * 32767.0;

    //make sure it doesnt round off to a over-max value
    if (valu > 32767)
        valu = 32767;
    if (valu < -32768)
        valu = -32768;

    short writ = (short)valu;

    fwrite((const char *)&writ, sizeof(writ), 1, outFile);

    dataLength += dpp;
    }


} 
return FMOD_OK; 

[/code:1l8lw70c]

One thing that might help is if instead of fwriting for every instance of the loop, I just build a string of bytes in the loop and output it after the loop. Anything you can think of would help!

Edit: Yes, I was surprised too. When I ran it through the profiler, the DSP CPU usage jumps to over 12% on occassion and then goes back down to 1-2%, which made me think that there could be something with the writing to file.
– George

  • You must to post comments
0
0

Yes, I would definitely buffer those writes, if you have 1024 sample dsp buffer size, stereo you have 2048 fwrites per mix, and the mix is roughly every 24ms by default so that would be a lot of overhead.

  • You must to post comments
0
0

Thanks Mathew,

So I replaced the fwrites with:

[code:3tx8o7go]
memcpy(outdata+outlength, (const char *)&writ,2);
outlength+=2;
[/code:3tx8o7go]

And put an fwrite at the end of the loop to write out outdata.

The DSP CPU usage still jumps to about 10% now every 10-20 seconds and though it seems to stutter less frequently, it still stutters.

On the device it still stutters as well, though again, it may be stuttering less frequently.

Any thoughts on how I might be able to solve this? Do you think the change I’ve mentioned should have worked?

Thanks!

  • George
  • You must to post comments
0
0

Nothing in FMOD would be operating on a cycle of 10 to 20 seconds, perhaps there is something in you app that is causing the problem?

If you can send us a simple repro application to support@fmod.org I can take a look if you like?

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.