You will first need to tap into the output device stream to get the audio data.
Unfortunately this can’t be done easily, but has been achieved by others.
A program called "WireTap Studio” does this using a kernel extension and helper daemon.
More specifically, the kernel extension (kext) uses IOAudioEngine.
Basically, this won’t be an easy task.
Maybe someone else on the CoreAudio-API mailing list can help more with Kexts and IOAudioEngine.
Regards,
Anthony