views:

178

answers:

2

I am trying to port my screensaver from windows to mac and one of its features was reacting on system sound output. On windows it was easy using Direct Sound, but I can't find any example of capturing sound output on mac. Is it possible even possible without writing something like kernel extension? Using flash it is also very easy — it even gives computeSpectrum method to get raw data or even fft transformed data.

All programs that I have already found use Soundflower or their own kernel extension. But I don't think that asking to install separate program or using kernel extension is a good way.

A: 

I'm not on my Mac right now, but I'm pretty sure that Quartz Composer has a patch for just this thing. Depending on what language you're writing your screen saver in, it may be fairly easy for you to port your code into a QC patch. Well... it probably won't be easy, but it may be doable.

kubi
I think you can do anything you could do with a QC patch in code, can't you?
Carl Norum
In Quartz Composer I found only way to work with input sound, not output. Also my screensaver is not very lightweight, so I prefer to use Objective-C++ with OpenGL.
tig
+2  A: 

One thing you can do, considering that Soundflower is open source, is take a look at how they did it. You can't copy & paste GPL code, but you can surely study the techniques used and create your own solution (point you in the right direction).

You won't find Apple being very helpful here. Sound capturing, in this manner, can be used for all kinds of nefarious purposes. I'm not even sure if Core Audio lets you do this without hacks. In any case, you have a working implementation of what you're trying to accomplish. I'd take advantage of it.

Pestilence
Do you know any place to see code using Soundflower?
tig
I'm not recommending using it. I'm recommending reverse engineering it. The example you seek is the source code to Soundflower itself. BTW, installing a kernel extension is transparent if you package it up properly.
Pestilence
I don't like that it will require admin privileges to install. But I think that you are right.
tig
Your answer is not what i hoped for, but as I understand it is the only way.
tig
Kernel extensions are not as painful to write as you might think. It'll be fun! You'll get to muck around in the dungeons of the operating system, crash your box a few times, and learn a ton about things you never wanted to know about. Sorry, but that kind of coding excites me. :)
Pestilence