Finished Colors & Automatic Aggregate Device Creation!

AVTouchBar Update 2 Thumbnail

Colors & Menu Bar Adjustments

If you haven’t read the first two blogs, check them out here:

Blog #1: The Backstory of an Audio Visualizer for the Touch Bar

Blog #2: Big Update #1 (System Audio is Working)

Quick Overview of the Update

Now that the system audio and visuals are solidified, it was time to create the beautiful color spectrum gradient and add some solid base colors in as well. The touch bar is an OLED screen, so these screen shots of my virtual touch bar do not do them justice.

So you’re probably wondering how the color gets changed. I kept it simple with a menu bar option so that you could adjust the visuals without having to close out of the touch bar. This is what it currently looks like.

Automatically Creating an Aggregate Output Device

This part is arguably the most complicated aspect of making this app operate seamlessly, and it’s quite a complicated topic. I’m going to try to explain it in simple terms, which may or may not work haha.

The reason we have to create an aggregate audio device is so that audio can get sent to AVTouchBar and the Macbook Pro’s speakers/headphones. If we set the system output to just the system audio channel (ex. soundflower), then you won’t be able to hear the music. If the output is set to the speakers, AVTouchBar has no way to read the audio. The system audio must be sent to both the Macbook’s speakers and AVTouchBar.

Accessing the System Audio on MacOS

Apple does not provide a method to listen, record, or process the system audio. There is no api for this. However, third party creators have made audio drivers that do allow you to use the system audio. The most popular of these are:

Any one of these options is great and works on MacOS Big Sur. After testing all three of these significantly, I have to say Loopback has been the most stable. When creating and destroying aggregate devices programmatically, it is not always smooth (from what I’ve read this is Apple’s problem and there’s not much we can do here). So having a stable audio driver is important in making the app operate well.

All three of these options are free to use. Loopback says that they lower the quality of your audio being sent through the virtual channel on the free version. However, I genuinely could not hear a difference what-so-ever. So I wouldn’t worry about that at all. But you can check them all out and choose for yourself.

Software Behind the Aggregate Device

It is possible to create a virtual audio aggregate device programmatically. There are some great resources online here, here, and here. Basically, you can use CoreAudio which is a framework that allows you to interact with audio components in MacOS. This framework is written in c++ and guess what, I don’t know crap about c++.

Luckily, you can interact with CoreAudio with a nifty little framework called AMCoreAudio, which is written in swift. You cannot use AMCoreAudio to make/destroy an aggregate device, but you can use it to get the proper audio inputs/outputs you need to make the aggregate device.

For example: You can get the ID’s of the current audio output and the System Audio channel with AMCoreAudio, then send that to CoreAudio so that it knows which audio devices to put into the aggregate device.

Selecting Different Options from Soundflower

Originally, this project was designed to solely work with Soundflower. However, it’s not ideal to limit the user to one option, since some people love Loopback/BlackHole/etc.

Therefore, I created a menu that allows the user to determine which system audio driver they would like to use!

From there, all you have to do is click “Visualize” and the aggregate device will be created, the system input will be set to the selected system audio driver, the system output will be set to the newly created aggregate drive, and the visualizer will initialize (all automatically).

And that pretty much sums up this update! Be ready for an early access beta drop coming up on Patreon soon. That should be coming in a week or two. Hope you all are excited.

Signup to get updates on everything!

1 thought on “Finished Colors & Automatic Aggregate Device Creation!”

Leave a Comment

Your email address will not be published.