How can I control / play audio output in Java or C?

Recently, I have been experimenting with real-time visualization of audio that I play on my computer (through any arbitrary program like Spotify), but I used SoundFlower to connect the audio output to a fake line.

I am wondering if there is a method that is native to C / C ++ or Java that will allow me to record any sound sent to my computer (I use a Mac), in the same way as I can capture a string in (IE sample buffer, which is constantly populated with PCM data).

I have no desire to emulate other SoundFlower functions other than reading line output data.

+6
source share
1 answer

I suggest looking at the source code for WavTap , the SoundFlower plug, which focuses only on capturing the system’s default audio output.

Both SoundFlower and WavTap work by installing an extension that adds an additional audio device to which sound can be redirected. Then they capture sound from this device. WavTap makes this the default device when it starts, so that the system’s overall output is automatically captured if the user does not have to explicitly configure routing.

I believe that the WavTap code is licensed by MIT, and the system extension code is well abstracted, so you can adapt it for your own project.

To understand a little more about how this works, the OS X and iOS Kernel Programming books explain some of the methods in Chapter 12, as well as downloadable code for an example audio device and engine.

+1
source

Source: https://habr.com/ru/post/973143/


All Articles