Creating level meters in Quartz Composer, part 2

This tutorial assumes that you have completed all the steps in part 1, or that you begin with the SimpleLevelMeter.qtz file.

So far we have created a single LED style level meter which reacts to the audio input on your Mac. The next part of this tutorial gets a bit complex. We need to get input from the spectrum of audio frequencies, and create a number of duplicate Meter patches to interpret that data.

The first requirement is straight forward, the Audio Input patch provides an outlet named "Spectrum", which supplies a struct. So, what is a struct? A struct in QC is a way of dealing with any kind of data that is not a number, string, colour or image. In this case, the struct is a list of 16 values, from 0 to 15, each of which contains a real number. Each real number represents the current audio level of one of the bands that the audio spectrum is divided into, or some other data about the audio stream. Actually, only the first 12 values relate to the frequency bands. I was unable to determine the meaning of last 4 values. Others have done some research, and came to pretty much the same conclusion.

Based on that research, it seems that the values in the struct correspond to the following frequencies:

  • 0 - 30Hz, 200Hz
  • 1 - 800Hz
  • 2 - 1.15KHz
  • 3 - 1.6KHz
  • 4 - 1.75KHz
  • 5 - 2.6-3KHz
  • 6 - 5.15KHz?
  • 7 - 7.2KHz
  • 8 - 9.6KHz
  • 9 - 12KHz
  • 10 - 14KHz
  • 11 - 16.5KHz
  • 12 - 18.8KHz
  • 13 - ?
  • 14 - ?
  • 15 - ?

Our level meters will need to read each of these values and display a separate column of LEDs for each of the values 0 to 11.

Getting values from a struct

First, open the Meter macro patch. We need a way of separating the values in the struct. We can do this by dragging a Structure Index Member into the Editor. next to the Amplifier patch. Connect the Member outlet to the Initial Value inlet of the Amplifier Math patch. This disconnects the currently published Initial value, and the level meter in the Viewer will stop working. Don't worry - we'll fix this shortly.

The next step is to publish two inlets from our Structure Index Member patch to the Root level so we can connect them to the Audio Input patch. Right Click on the Structure Index Member patch and choose Published Inputs -> Structure. A text field will appear, asking you to name the Input. Type "Spectrum". Now repeat this step for Index, but don't rename the input, simply hit enter to accept the name "Index". The two inlets should show as grey dots indicating they are now published.

Click on Edit Parent in the toolbar to return to the Root level. Connect the Spectrum outlet of the Audio Input patch to the Spectrum inlet of the Meter. You should see our meter begin reacting to input again. However, the reaction is quite weak.

It seems that the Spectrum values are an order of magnitude lower than the Volume Peak value we were using previously. So let's add another stage to our amplifier. Double click on the Meter macro patch to open it again. Then click on the Amplifier math patch, and go to its Settings inspector (Cmd-2). Set Number of operations to 2. Go back to the Input Parameters inspector (Cmd-1). Set the Amplifier up as follows:

  • Initial Value: [From Structure Index Member]
  • Operation #1: Multiply
  • Operand #1: 10
  • Operation #2: Multiply
  • Operand #2: 10

This might seem odd: why didn't we just multiply by 100? Well, you'll see in the next step.

Right click on the patch and choose Published Inputs -> Operand #2. A text field will appear, asking you to name the Input. Type "Sensitivity" and then hit enter. Why did we do this? Well, it turns out that the levels in the spectrum bands actually vary in amplitude, and some of them will need to be boosted more than others. Sensitivity will allow us to tune each band to get an appropriate level.

Position position position

The next piece of the puzzle is devising a way to position 12 individual columns of LEDs, times the 2 channels (left and right) of audio, for a total of 24 columns of LEDs. This means we need to set the X Position of both the Sprite and the Cube for 24 columns. So let's add the infrastructure for that.

Right click on the Structure Index Member and choose Insert Index Splitter -> Index. Click on the new Index splitter, and in the Settings inspector, set the Type to Number, Minimal value to -12 and Maximal value to 12. Finally, right click on the Index patch and Publish Inputs -> Input, name it "Index".

Next, add a new Mathematical Expression patch. In the Settings inspector (Cmd-2), type "abs(a)-1". This will return the non-negative (unsigned) value of the input value (subtracting one, for reasons which will become clear shortly). Now connect the Output of the Index splitter to the "a" input of the Mathematical Expression patch. Then connect the Result to the Index of the Structure Index Member patch.

Now create another Math patch and name it "X Positioner". Set it up as follows:

  • Initial Value: [From Index Output]
  • Operation #1: Multiply
  • Operand #1: 0.075

The value of 0.075 will be multiplied by an Index (in a range of -12 to 12) to produce an X Position - this gives us nice spacing and distribution of the columns, as you shall soon see. Connect the Resulting Value of the X Positioner to the X Position of the Cube patch. Also connect the same value to the X Position of the Sprite.

The Index also tells our patch which of the bands in the Spectrum to get its value from. However in that case it needs to be in the range of 0 to 11. This is why we subtracted one from it in the Mathematical Expression patch.

Our Meter patch is getting fairly complex, but it is now capable of being positioned in the X (left right) dimension and selecting a frequency band from the Spectrum. All we have left to do to complete our composition is to duplicate the Meter and then set the index for each column position and frequency band.

Click on Edit Parent in the Toolbar to return to the Root patch. Let's test that the X Positioner is working. Click on the Meter patch and enter a value of -12 in the Index field in the Input parameters inspector. The meter in the Viewer should jump all the way over to the left of the window. If it does, we're ready to move on to the final step.

Hold down option on the keyboard and drag a duplicate of the Meter. Connect the Spectrum outlet of the Audio Input patch to the Spectrum inlet of the duplicate Meter patch. Set the Index of the duplicate to -11. You should now see a second column next to the first one. Repeat these steps until you have 24 Meter objects with Indexes from -12 to -1, then 1 to 12, sequentially.

The next step is pretty tedious. Connect the Spectrum outlet of the Audio Input patch to the Spectrum inlet of each of the 24 Meter patches. It should look like a bowl of spaghetti when you're done.

Once that's done, you should have fully working 24 band LED level meters!

Finishing touches

One finishing touch is to publish some inputs at the Root level so that hosts have the ability to tweak the composition at run time. By using input splitters, we can allow our hosts to see nice sliders for the Sensitivity setting for each pair of Meters.

Right click on the Meter with Index -12, and choose Insert Input Splitter -> Sensitivity. Go to the Settings inspector (Cmd-2) and change the Minimal value to 0 and the Maximal value to 100. This step allows the host application to display nice sliders for our patch.

Connect the Output outlet to the Sensitivity inlet of the -12 and 12 Meters.

Option drag a duplicate of the Sensitivity input splitter, and connect it to the Sensitivity input of the Meters with -11 and 11. Repeat this step for each pair of meters.

Right click on the splitter and choose Publish Input -> Sensitivity. Name the input "12 Sensitivity" and hit Enter. Repeat this step for each pair of meters, naming them appropriately from "12 Sensitivity" to "1 Sensitivity".

Whew! If you've followed along this far, you should know everything you need to start creating your own audio active compositions in Quartz composer for use in AudioCodex. Thanks for reading!

Download

Download the sample project: SimpleLevelMeters.qtz.zip (4KB).

Requires Mac OS X 10.4+ and Quartz Composer.

I have been using Quartz for

I have been using Quartz for a long time and never really even thought that I could get any where near the full potential of it..these tutorials though..the screen shots..make it so much easier to understand and get a grasp on. Best Regards, Jason

f'in awesome!

I really enjoyed this tutorial. Thank you very much.

totally excellent

This is such a great QC tutorial. I'd been looking to go a little deeper into QC, and this is just what the doc ordered. Thanks!!! -Danny

Left and right speakers

Hey

Nice Tutorial. Very simple to follow.

One question though. Am i right in believing that this doesn't really show the left and right speakers of the spectrum, its just mono being split?

Cheers

David

Hi David, Yes, you're

Hi David,

Yes, you're correct. Quartz Composer's Audio Input patch only supports mono signals at this point.Very observant of you : )

Cheers

Alex

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
6 + 5 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Navigation

User login

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Recent