How to grab audio from windows? [duplicate] - c++

I want to capture all audio that is played to the user (all sounds together). Currently I'm working on Windows but it would be nice if the code was cross-platform (but not necessarily). Is it possible to do it with OpenAL? How? Code examples would be great.
Language: C++

The only way to do this I believe is to create a replacement audio device driver that receives all audio requests, and then forwards them to the original device driver. There are a number of existing applications that work in this way including Freecorder, MP3myMP3 Recorder, SoundTap and Wondershare to name but a few (Google "Streaming Audio Recorder").
As for cross-platform, I would say not a chance since it is OS driver model dependent.

Depending on what you have in your system, some (not all) sound cards offer a "Stereo Mix" feature, which can be used like any other recording device. This is basically exactly what you want, as it is literally a mix of all stereo sounds being played.

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.

Video capture from USB webcam using C++ and USB library

I just want to know if its possible to write a program in c++ on Windows which can grab frames of video from a web cam by making use of a USB library like libusb.
I have looked at http://www.dreamincode.net/forums/topic/148707-introduction-to-using-libusb-10/ . They define a basic sequence of the steps one must follow while using libusb to work with usb devices. To summarize:
1) Find and connect to the USB device
2) Send and receive data
3) Release the USB device
libusb handles part 1) and 3). So, the question comes down to part 2). I wonder if it is possible/feasible to send commands to the camera and receive data via USB by adhering to some type of standard (UVC 1.5 for example). I'm thinking that not knowing some proprietary, device specific information might be a problem though.
If this is possible but super hard, I would appreciate any insights into what the biggest challenge would be.
The hardware I have in mind are low-end logitech USB cameras.
Also, I am fully aware that OpenCV, Video for Windows (VFW), DirectShow, and FFMPEG can do web-cam video capture. I am interested in this project as a learning experience.
Thanks in advance!
Since you're obviously a bit inexperienced, I'll give an answer in high-level terms.
To talk to someone, or something, you need to speak a common language, or have a translator. Now, there are many different USB devices, and they speak many different languages, but OpenCV can act as a translator for many of those. If you don't want to use that, you will need to find another translator, or possibly learn to speak the camera's native language.
The first option (another translator) is no option for you, because you don't want a translator.
The second option is something we can't help you with, because we don't know which camera you have.

Multichannel audio input using Qt/Phonon

My company is currently working on what could be called an audio analysis program which needs to process to multiple audio inputs (8 or so) in real time. This means that we need a framework that can handle multichannel audio interface devices that have up to 8 input channels. On top of this, the framework should be as portable as possible. We actually started our development using Java but it ran into issues with the sound API.
When looking for alternate ways to do what we need, I started thinking about using C++ and Qt. I have some experience with both, but I've never done anything remotely similar (in any language for that matter)
Now, the question is, can Qt/Phonon handle audio interfaces/sound cards with over 2 input channels (assuming that the OS can see the devices just fine)? Would it dependent on the backend being used?
Phonon as no input function. it's for playback only if i'm right. but if you want to process input audio you can use QAudioInput. I've used it with just one audio input but I think this constructor with the right QAudioDeviceInfo could do what you want.

Capturing Audio Out

I want to capture all audio that is played to the user (all sounds together). Currently I'm working on Windows but it would be nice if the code was cross-platform (but not necessarily). Is it possible to do it with OpenAL? How? Code examples would be great.
Language: C++
The only way to do this I believe is to create a replacement audio device driver that receives all audio requests, and then forwards them to the original device driver. There are a number of existing applications that work in this way including Freecorder, MP3myMP3 Recorder, SoundTap and Wondershare to name but a few (Google "Streaming Audio Recorder").
As for cross-platform, I would say not a chance since it is OS driver model dependent.
Depending on what you have in your system, some (not all) sound cards offer a "Stereo Mix" feature, which can be used like any other recording device. This is basically exactly what you want, as it is literally a mix of all stereo sounds being played.