Take a look at the open-source WavTap, which is a simplified fork of the open-source SoundFlower virtual sound card driver. It is a .kext that I believe does substantially what you want. For reference, here is how some popular commercial closed-source options work: Rogue Amoeba's Audio Hijack Pro -Captures system audio via code based off of the open-source SoundFlower .kext -Captures an applicatio
![Mac OS X virtual audio driver](https://cdn-ak-scissors.b.st-hatena.com/image/square/98d6f053a97a87156775f60757c60865d0f2c47d/height=288;version=1;width=512/https%3A%2F%2Fcdn.sstatic.net%2FSites%2Fstackoverflow%2FImg%2Fapple-touch-icon%402.png%3Fv%3D73d79a89bded)