0
0

Well, I don’t know if the subject is really correct, what I mean is recording and writing samples to a file using a (small) buffer with no length limitations.

After a little experimenting with FMOD I was trying to record from the microphone. Of course when recording it is hard to tell in advance how long the sample will be, so writing data in realt time would be a good idea.

I came out with a test program (anybody interested can have a look at the source at http://web.rossoalice.it/davidemania/QtFMOD_test.zip )
It is written on Mac OSX 10.3 using the Qt multiplatform C++ library from trolltech.

The program (besides being nothing more than a test) manages to record and write out a WAV file. The only way I have been able to find out is this:

  • Play the sample while it is recorded (from the “record” example)
  • Install a DSP callback at the end of the chain to save data to the HD and then clear the mixer buffer to avoid hearing the sound (causes larsen)

This works but sound is corrupted at the beginning (I believe there are problems writing out data in real time in the mixer callback) so I am trying to implement a circular buffer with a separate thread that reads from it and saves to disk.

The (nice) side effect of this technique is that I can get the VUMeter reading and even the spectrum, but it seems to be a little tricky.

A strange effect is that WAV file has a maximum volume that is about 3dB under maximum, while recording to a fixed buffer gives full volume. Setting FSOUND_STEREOPAN did not seem to help, but may be I am missing something.

Now to the question: Is there a better (simpler) way to do what I am trying to do, or it is meaningful to continue on this way and fix problems?

Anyone willing to look at my (very modest) code is really welcome, and so are any suggestions.

Please, be merciful, I have a very limited experience with FMOD (a week?), so don’t flame me :)

cheers, and thanks
Davide

  • You must to post comments
0
0

[quote:15aa6n7t]
A strange effect is that WAV file has a maximum volume that is about 3dB under maximum, while recording to a fixed buffer gives full volume. Setting FSOUND_STEREOPAN did not seem to help, but may be I am missing something.
[/quote:15aa6n7t]

That was (of course) my fault, I wrote somewhere FSOUND_STEREO instead of FSOUND_STEREOPAN. Fixing it gave back full volume :)

  • You must to post comments
0
0

[quote:3de9ddmn]
You could try increasing the fmod buffersize (FSOUND_SetBufferSize) to avoid that corruption you get at the start, which as you say, is probably caused by the initial file access or something.
[/quote:3de9ddmn]

I don’t know if this could be a solution, I’m afraid that writing data to disk in the DSP callback is dangerous anyway since it has to be done in realtime. A ring buffer could do the trick.

[quote:3de9ddmn]
Another method is to write the data out using FSOUND_Sample_Lock and FSOUND_Sample_Unlock (and FSOUND_Record_GetCurrentPosition) from the main thread, writing out chunks of the record buffer as it records. This way you wouldnt even need to play it.
[/quote:3de9ddmn]

Well now my code works, using this method. I let the sample play (silenced) so it is possible to have the level and its spectrum.
I will be happy to give it to anybody interested, now it can record an arbitrary length sample and write it to the disk in a wave file realtime.
It should be really multiplatform, since it is writteng with Qt, it would be nice to have some test run on other platforms (I only have a mac).

The only thing that gave me a little trouble is the conversion between samples and bytes, that’s easy enough once you got it, but at first is not so clear (mostly to understand if for sample is intended a sample on a channel or a couple of them for stereo).

By the way, asking for mixer type with FOUND_GetMixer() gives me a value of 11, that I am not able to relate to any of the ENUMs defined in header (there are 11 constants, that should go from 0 to 10).

Ciao
Davide

  • You must to post comments
0
0

Ah, sorry, the code at the address above is not up to date with last modifications, I’ll fix that as soon as I have a little time.
If you are in a hurry to see it :roll: mail me!

ciao
Davide

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.