views:

37

answers:

2

I want to get sound level, so I can display it in my SDL application (the platform is Linux) when recording sound. How can I do that? I use FMOD API in my app, but for recording, I'm using SoX (forking and using exec() to set it up - probably this could be done better but I don't know how :( ). Should I use some function of SoX, FMOD API, or maybe directly access /dev/dsp to get sound data?

+1  A: 

No, at the very least you should use the "safe" ALSA API. But you should consider using something higher up such as Gstreamer or PulseAudio.

Ignacio Vazquez-Abrams
+1  A: 

You can do recording in FMOD if you like. FMOD APIs such as System::recordStart and System::getRecordDriverInfo can be used. FMOD ships examples of recording which you can use as a basis for your solution.

Specifically for getting the sound level, if you wanted to do it as a runtime thing you could use Channel::getWaveData which will give you a snapshot of the current playing audio, for this you would need to play the recording data.

Or alternatively you could use Sound::lock / Sound::unlock to get access to the recording sound data if it isn't playing.

Once you have access to the sound data through either method you can read through the values to get sound level / peak information.

Mathew Block
I've tried to use FMOD, but I want to get MP3 encoding on the fly, and as far as I understand, it doesn't work in FMOD on Linux flatform.
mav
FMOD cannot help with the encoding side, by using Sound::lock and unlock you can get access to the raw PCM. If you want to feed those chunks of data into something like lame then that is definitely possible to produce an MP3, but FMOD has no built into encoding support.
Mathew Block