Sound Monitoring in C++/Python
I'm looking for an API (or some information as to where to look/start) that will ultimately allow me to monitor sound being played by the computer.
My end goal (well, c开发者_如何学Certain to eventually be a stepping-stone) is an oscilloscope.
Where should I begin to look (aside from Google, which has yielded unsatisfactory results) to learn more about sound as processed by computers (particularly, Macs) and how to get to it.
Thanks!
As @cobbal noted, on Mac OS X you would need to use PortAudio in some way to get the audio as it plays. The only other way to do it would be to use an audio player that has a plugin API, then write your code as a plugin for that one player. But a CoreAudio solution should make it possible for you to monitor all sounds played on the Mac.
Your CoreAudio code will not be portable at all to Windows and Linux. There is no portable solution at this time. On Windows you would probably want to use the WaveIn/WaveOut API, unless you have pro gear, in which case you would probably want to use ASIO. On Linux, I'm not sure; I think you could probably hook in to ALSA/PulseAudio to grab audio. Unless you have pro gear, in which case you would probably want to use JACK.
If you wanted a portable solution, you might want to look seriously at the plugin option. Find a portable free software media player that works on all your platforms, and make a scope plugin for that.
For an oscilloscope, you are going to want to get a book on Digital Signal Processing ("DSP"). You will probably want to use a Discrete Fourier Transform ("DFT") to get frequency information out of your discrete audio samples; a DFT library will likely be called an "FFT" library ("FFT" being short for "Fast Fourier Transform").
My favorite single book on DSP is: Understanding Digital Signal Processing by Richard G. Lyons.
EDIT: And by the way, most media players have "visualization" plugins, and some of them are displays based on frequencies. (Some even have names like "scope".) Is it possible that there is a media player that already does exactly the display you want?
I have in the past used a combination of Soundflower and PyAudio for a similar purpose.
Soundflower allows you to route all audio output into an input that can then be read by PyAudio.
If you wish to use c++ instead of python, use PortAudio, the library PyAudio is based on.
精彩评论