Intercepting all system level audio in Mac os - macos

I have been working with CoreAudio last couple of days and I'm able to access all the AudioDevices, their properties and receive notifications when something changes. However, I'm now struggling to "intercept" the audio (ideally before it is played) from any application in the mac. I wasn't sure it was possible but this app actually does it.
So I'm in search of some guidance. Thank you in advance.

Unfortunately macOS provides no facility to do this.
The only way to achieve this is to patch lower level frameworks and/or drivers like Audio Hijack does. I will be a messy process.
Depending on the use case however it might suffice to have an audio loopback virtual audio device so application A can send audio into it while application B can receive the audio from it. This can be done by creating a Core Audio AudioServerPlugin which is a user space audio driver mechanism. For an example please have a look at:
https://github.com/ExistentialAudio/BlackHole
https://github.com/kyleneideck/BackgroundMusic
In regards to the limitations, you can read more about it here:
https://stackoverflow.com/a/18595698/2576876
From there you can go in a lot of directions by following the links provided.

Related

A proper way of handling audio I/O devices attache and detach on Mac

I have been looking for something similar for
AVCaptureDeviceWasConnectedNotification or AVCaptureDeviceWasDisconnectedNotification
but for audio playback and record device. I have done a quick google search, but I haven't found any quite relevant answer for this question. There is a sample code from Apple AVCaptureToAudioUnitOSX. but it does not handle multiple audio route.
I wonder if anyone has idea about it?
You can do this at IOKit level by adding IOKit matching notifications for audio devices being hot-plugged or unplugged. [Caveat - I've not done this in about a decade: higher level APIs might exist]
Apple's documentation for this is here - particularly the section
Getting Notifications of Device Arrival and Departure
This is quite hard work. I advise you to get the IORegistryExplorer tool - which I believe is now in the Hardware IO Tools for Xcode download package (Xcode->Open Developer Tool->More Developer Tools). You can use this to work out the matching criteria.

live Video streamming

Can any one tell me how to stream video using mac osX , i need to write an application in mac os for video conferencing please let me know any prerequisites for making this application and what shud i learn for this .
Thanks in advance .
Do you need to do streaming or two-way videoconferencing? The latter is orders of magnitude harder than the former. If you just need streaming (one server, many clients), then QuickTime Broadcaster will do what you want.
Some time ago I used libcurl to stream a video from youtube, libavcodec (from ffmpeg) to decode and parse the data into frames and finally SDL to display it on my Mac OS X.
If you are looking for ffmpeg/SDL code examples, you must check this out:
http://dranger.com/ffmpeg/tutorial02.html
Based on your comment to Josh Wolf, you might want to consider developing an Adobe AIR application (inherently flash, but via whichever OSes you choose), as it already has built-in components for capturing and streaming video.
There's a great alternative for using this kind of service: tinychat.com
You can create a private room there and tell the password only for the people you need to talk to. The best reason for using tinychat.com is that you don't need to install anything.. It does works very well and quickly, and suports 9 broadcasts at the same time, with webcam, audio and/or text chat.

programmatically recording sound sent to Built-in Output, Mac OS X

I have a conundrum:
I need to find a way to capture the raw audio data that is being piped to the Built-in Output on Mac OS X. Core Audio, HAL, etc.
I can "listen" in on the Built-in Output and the mic, but neither of these appear to offer the correct data stream - the exact stream (all combined data from all input sources) that goes to the speakers/built-in output.
Any advice is welcomed with appreciation.
maybe you should have a look at the Jack source code...
http://sourceforge.net/projects/jackosx
Do you need to access to that stream from your program, or do you just want to rip audio from it? In the second case, a quick Google search turned up http://www.ambrosiasw.com/utilities/wiretap/ and http://www.rogueamoeba.com/audiohijackpro/. None of those are open-source or free though.
Edit -- whoops, you want to access to programmatically, that answers my own question, sorry. I think I'll keep my answer here in case some folks stumbles upon this page wanting to record audio non-programmatically.
You need will need your app to install a system extension.
Soundflower is an open-source implementation of such an extension.

How to capture PCM data from Wave Out

How would it be possible to capture the audio programmatically? I am implementing an application that streams in real time the desktop on the network. The video part is finished. I need to implement the audio part. I need a way to get PCM data from the sound card to feed to my encoder (implemented using Windows Media Format).
I think the answer is related to the openMixer(), waveInOpen() functions in Win32 API, but I am not sure exactly what should I do.
How to open the necessary channel and how to read PCM data from it?
Thanks in advance.
The new Windows Vista Core Audio APIs have support for this explicitly (called Loopback Recording), so if you can live with a Vista only application this is the way to go.
See the Loopback Recording article on MSDN for instructions on how to do this.
I don't think there is a direct way to do this using the OS - it's a feature that may (or may not) be present on the sound card. Some sound cards have a loopback interface - Creative calls it "What U Hear". You simply select this as the input rather than the microphone, and record from it using the normal waveInOpen() that you already know about.
If the sound card doesn't have this feature then I think you're out of luck other than by doing something crazy like making your own driver. Or you could convince your users to run a cable from the speaker output to the line input :)

How do I capture the audio that is being played?

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.

Resources