Audio Spectrum CHOP to TOP

UPDATE: A script-free alternative provided in the comment section.

Hey all,

for my project I needed to view the Audio Spectrum CHOP in TOP as an image. But when you do this with Chopto TOP, you don’t get the Audio Spectrum CHOP graph (amplitude against frequency). When you do this with OP Viewer TOP, you get a spectrum graph as TOP but the max amplitude keeps shifting up and down and the graph lines are still present. I needed to get rid of these problems and get a pure spectrum graph with fixed max amplitude.

So I wrote a short python script which achieves this. I’m not expecting anything, but I thought I could make this available in case someone needed a similar thing. You can of course change stuff. I included a description of the code inside the Text DAT which might help you in understanding and changing the script.

I hope it proves helpful to someone. Let me know if you’ve got any questions.

Audio spectrum TOP.toe (32.6 KB)

Hey @OnBoc,

that’s a neat way to do this and thank you for the thorough explanation in the file.
For an approach without any python scripting, check out the CHOPTo TOP which converts a channel into pixel values and, in conjunction with a Displace TOP, come to a similar result.

Really helpful for discovering how these operators work can be the OPSnippets.

Curious what you are using this for.

thanks for posting your example @OnBoc !

Another tip: the CHOP Class has a method numpyArray() which gives you all CHOP samples already in a numpy array. This way you don’t need the CHOP to DAT and it saves about half the cooktime of your Script TOP:
read_chop_numpyArray.tox (8.7 KB)

Hey Markus,

thanks for the reply. I’ll be the first one to admit I went with the python code simply because I didn’t know how to do it otherwise. I tried to play around with the CHOP2TOP, but it wasn’t really what I imagined. I needed the audio spectrum graph as TOP to be used as a matte for combining two images (see img).

At the same time however, I have very little doubt that there is a way to do this with no script. I just didn’t find it. I posted this partially with the intention of starting a discussion that would potentially lead to finding the script-free solution. So, if I may, a question for you: can you think of a way to get the spectrum-shaped TOP matte without using script? Should I take a closer look at the Displace TOP?

Thanks ^^

1 Like

Thank you for your tip @nettoyeur! I must admit I tried using numpyArray() but it kept throwing errors at me. It seems I gave up too early. I’ll definitely include your suggestion. It is way more elegant and faster as well.

Talking about speed, the script, although being rather simple, slows down the whole thing quite considerably. This is something I noticed with Touchdesigner overall - as long as I stick to components, it’s all smooth and fast. The moment I include a script, it all seems to slow down a lot, even if the script operation is technically way simpler than the operations in other components. Is this an observed issue or is it just me and my badly written scripts?

In regards to speed: yes that is to be expected, as all native TD operators/nodes are each made from compiled C++ code, which will always be way way faster then the Python script interpreter.

Having said that, the functions you call from the NumPy library are also compiled C++, and therefore many NumPy operations can reach C++ speed, but this requires careful coding.
In particular when working with large arrays of data, the trick is to try never using Python loops (which are slow) to handle each value in that array, but instead make use of these three concepts using NumPy: Vectorisation, Broadcasting and Indexing. The speed difference this will provide, is massive.
The example you uploaded is using Python loops to iterate over NumPy arrays, and therefore it is slow, and the script could probable be heavily optimised to use the three concepts mentioned above instead of the python loops, to be much faster.

Read more here:

I see, that’s how it is. Thanks for the clarification. I’ve assumed TD is mostly Python, but if it’s CPP, it makes sense the scripts would slow it down. I’ll absolutely take a look at the links. Python’s speed is a problem I’ve struggled with for some time (yes, I really should learn cpp, I know).

Anyways, thanks a lot for the informative replies.

Hi OnBoc,

attached is a small component that displays the spectrum as a texture.

base_spectrum.tox (3.8 KB)


That is wonderfully elegant (and computationally efficient). Thanks a lot. The problem with shifting amplitude cap seems to be eliminated as well, the cap being fixed at 1. This is exactly what I needed. I’m always surprised how many things are hidden in TD.

I’ll make sure to edit the post so people read the comment section.


Hi @OnBoc,

the amplitude cap is also just a CHOP viewer option. After activating the viewer in the right bottom corner or the operator and then rclicking into it, the menu will give you options to automatically adjust the horizontal and vertical range (Horizontal- and Vertical Adapt)

alternatively you can also set a vertical range:


1 Like