Get sound level from device while recording in C++ - c++

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?

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.

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.

Related

Getting audio output stream in C++ [duplicate]

Does anyone know how to programmatically capture the sound that is being played (that is, everything that is coming from the sound card, not the input devices such as a microphone).
Assuming that you are talking about Windows, there are essentially three ways to do this.
The first is to open the audio device's main output as a recording source. This is only possible when the driver supports it, although most do these days. Common names for the virtual device are "What You Hear" or "Wave Out". You will need to use a suitable API (see WaveIn or DirectSound in MSDN) to do the capturing.
The second way is to write a filter driver that can intercept the audio stream before it reaches the physical device. Again, this technique will only work for devices that have a suitable driver topology and it's certainly not for the faint-hearted.
This means that neither of these options will be guaranteed to work on a PC with arbitrary hardware.
The last alternative is to use a virtual audio device, such as Virtual Audio Cable. If this device is set as the defualt playback device in Windows then all well-behaved apps will play through it. You can then record from the same device to capture the summed output. As long as you have control over the device that the application you want to record uses then this option will always work.
All of these techniques have their pros and cons - it's up to you to decide which would be the most suitable for your needs.
You can use the Waveform Audio Interface, there is an MSDN article on how to access it per PInvoke.
In order to capture the sound that is being played, you just need to open the playback device instead of the microphone. Open for input, of course, not for output ;-)
If you were using OSX, Audio Hijack Pro from Rogue Amoeba probably is the easiest way to go.
Anyway, why not just looping your audio back into your line in and recording that? This is a very simple solution. Just plug a cable in your audio output jack and your line in jack and start recordung.
You have to enable device stero mix. if you do this, direct sound find this device.

Is it possible to play a sound though the audio driver with Rtmidi?

I am currently on linux and I am playing around with rtmidi. Now I was able to play a sound though my digital piano but I am wondering if I can also output the sound though my speakers?
When my digital piano is not connected I still get one device with getPortCount(); I assumed that is my audio driver. The device name is Midi Through:0 which is somewhat strange.
But I don't hear any sound and I am not sure if that is the intended behavior. Can I play midi sounds though my audio driver with rtmidi? Or do I need another library for this?
To convert MIDI commands into real sounds, you need a synthesizer.
Sound cards stopped having a built-in hardware synthesizer in the last millenium.
You need a software synthesizer, such as Fluidsynth or Timidity.
RtMidi is, as quoted from this website, a realtime midi input/output API. It does not say it is an audio API or library therefore it probably isn't. So yes, you will need another library or API for this, I recommend OpenAL.

Audio Streaming in C

I am working on this project in which we've got to implement real time audio streaming. Think of it as more or less a phone conversation, so the audio data that is fed in needs to be played while being fed.
I want to know if there are any libraries (Linux) that would enable me to do this. If this can be done via SDL it would be great because we are already using SDL for many other purposes.
This is doable using SDL. SDL_OpenAudio provides lowish level access to the audio device, registering a callback function that is called from a separate thread that will fill the audio buffer with sound data whenever it is ready for more.

Audiooutput problem in Qt using qmultimedia low level API

I'm trying to get mpg123 audio decoder to work with QT on windows. How do i play the decoded audio data at the right speed with Qmultimedia module in push mode. Currently i'm using simple timer to get it to play audio but it's not very efficient way to do it, if I do anything else at the same time audio get all distorted. Is there any better way to send the decoded data to audio output? It would be nice if anyone could point me to any nice examples using Qmultimedia module and Qaudiooutput class. I've tried to figure out QT example project "audiooutput" but it seems that it's also using timer to send audio to output in push mode.. Hope that I'm not too confusing.
I also had to figure that out and I would also suggest using the Phonon framework to do this.
It uses Windows Media Player as host on Windows, QuickTime on Mac and some KDE stuff on Linux.
So it's pretty platform independent.
If you need more low-level functionality, you should take a look into an open-source project called portaudio. It's very easy to use and you can manipulate or even fill buffers from code.
I used it to build an oscillator.
Hope that helps!
Best,
guitarflow

Playing sounds over the microphone in c++

I am making a program in C++ for Windows XP that requires sound to be played so that any program that is currently recording the microphone can hear it, but it will not come out of the speakers. There seems to be no "real" way of doing it, but it is possible to go into "sndvol32 -R" and set the Wave out mix or similar as the current input device. Then you can turn the master volume to 0, play the sound, turn it back up, and reset the input device to the microphone. Is there a way of doing this transparently, or setting the current input device using functions, so that you dont have to see sndvol32 pop up?
Thanks
Doing this would require a complicated kernel-level driver.
Fortunately for you, someone has already done this (it's not free, but it's a fantastic program).