Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cocoa to detect when a running application plays audio

I'm looking into writing an app that runs as a background process and detects when an app (say, Safari) is playing audio. I can use NSWorkspace to get the process ID's of the currently running applications but I'm at a loss when it comes to detecting what those processes are doing. I assume that there is a way to listen in on a process and detect what public messages the objects are sending. I apologize for my ignorance on the subject.

Has anyone attempted anything like this or are aware of any resources that can help?

like image 360
rock711 Avatar asked Oct 26 '22 05:10

rock711


2 Answers

I don't think that your "answer" is an answer at all...

and there IS an answer (which is not "42")

your best bet for doing this would be to write a pass-through audio output device. Much like soundflower, actually. so your audio output device would then load the actual (physical) audio output device and pass the audio data along to it directly (after first having a look at the audio stream, of course!). then you only need to convince your users to configure your audio device as the default audio output device so that the majority of applications which play sound will use it automatically. and voila...

your audio processing function will probably just do a quick RMS on the buffer before passing it along to the actual output device. and when the audio power crosses a certain threshold (probably something like -54dB with apple audio hardware), then you know that some app is making sound.

|K<

like image 76
kent Avatar answered Nov 15 '22 10:11

kent


SoundFlower is an open-source project that allows Mac OS X applications to pass audio to each other. It almost certainly does something similar to what you describe.

like image 42
Matt K Avatar answered Nov 15 '22 08:11

Matt K