Yana D. Nugraha
Yana D. Nugraha

Reputation: 5309

fmod: How to use FMOD_OUTPUTTYPE_WAVWRITER_NRT?

this is a follow up to my earlier question: Rendering some sound data into one new sound data?

I'm creating a program that will process a file containing a sound bank and time offsets to mark when the sound must be played and generate a wave file from it.

So I suppose FMOD_OUTPUTTYPE_WAVWRITER is perfect for the job.

For the sound bank, imagine something like this in a file:

0 kick.wav
1 hit.wav
2 flute.wav

where the number on the left describes the sound ID of the sound file name on the right, and the time offsets:

1000 0
2000 1
3000 2

where the number on the left tells the program when the sound must be played in milliseconds, and number on the right is the sound ID.

Therefore, when I start the program, FMOD will generate a wave file which contains a kick (from kick.wav) in the first second, a hit in the second second, and a flute in the third second, and I will have to wait for at least 3 seconds for the task to complete.

However, if I want to render a longer music, say, 5 minutes, then I must have to wait for at least 5 minutes for the task to complete, since I make it depend on the system timer to play the sound at the specified offset in the file and a while(true) loop to update FMOD::System. I think there must be a way to render faster without waiting for the program to actually render the sound at the specified time, since I saw in a DAW program like, say, Sony ACID, can render the tracks really fast.

Then I take a bit look into the API reference, there's FMOD_OUTPUTTYPE_WAVWRITER_NRT, then I thought this maybe the solution, so I tried changing the output device right away without modifying anything else, and the generated wave file sounds messed up! I hear many repetitive sound, long delays, etc.

So, how to use the non-realtime version properly? What is the correct way to update the fmod system when using NRT in my case?

I couldn't find a clear explanation about the usage of NRT ouput type in the fmod documentation itself.

Anyway, I use C++ in a Windows environment.

Thanks.

Upvotes: 1

Views: 1195

Answers (1)

Mathew Block
Mathew Block

Reputation: 1643

The way FMOD_OUTPUTTYPE_WAVEWRITER_NRT works is it generates audio every time System::update is called. The amount of data generated per 'update' is governed by the bufferlength parameter of System::setDSPBufferSize.

So the faster you call System::update the faster the data is generated. Now the important part for your job is to convert 'x' number of calls to System::update into something you can match to your timeline.

By default FMOD operates at a sample rate of 48000 samples per second (configurable via System::setSoftwareFormat). So if you set 'bufferlength' to 1024, each time you call System::update 1024 samples will be generated (written to the wav file). So... 1024 / 48000 = 0.021333 seconds ~ 21.3 milliseconds of data is generated per call. Now you can calculate how many times you need to call System::update to get to the timestamps you have.

Upvotes: 1

Related Questions