Search code examples
objective-cmacoscocoaaudiounitiokit

How to create a Audio Device driver to capture sound Mac is playing?


I have created some code to do a screen capture to mov file using AV Foundation and my next step is to also record what sounds Mac is playing for later adding to the recorded video. I have done some digging and appears I might need to implement some kind of Audio Driver to capture the audio. Any pointers on how to achieve this?

I assume AudioUnit and IOKit will be needed in some manner...

Thanks in advance.


Solution

  • The book OS X and iOS Kernel Programming by Ole Henry Halvorsen and Douglas Clarke has an example that does pretty much exactly this. You can download the example from the book's website, the book itself of course explains how it works.

    Disclosure: I was one of the tech reviewers for this book. (I don't receive royalties etc.)

    Update/Note 2024:

    This answer has recently gained a few upvotes, which I think are unjustified as the answer is no longer correct or helpful on modern macOS versions. The best-supported way to do it on modern OS versions is using ScreenCaptureKit.