Audio, read decibel for specific bin in MonitorSpectralNode

Hello. I am building a project using the InputAnalyzer (@rich.e) sample. I’m interested in reading specific decibel levels of individual bins in MonitorSpectralNode. For example, I want to see if a range of frequencies between 100 and 110 are being picked up through the microphone. Here:


This will report that Bin 5 is reading a frequency of roughly 107.666hz.
I am not sure how to go about reading amplitude or decibel levels for bin 5 (or any other bins).
Thank you for any input.

A Mention that detecting pitch is something Cinder might be rather challenged to make happen.

Hi there,

You’d use auto spectrum mMonitorSpectralNode->getMagSpectrum();, and then look at the fifth bin in that for your magnitude. You’d then convert that from linear to decibel how you see fit - there is a helper audio::linearToDecibel() that uses the Pure Data convention of normalizing decibels in the range of 0:100 for ease, but you could do it the traditional way where the value ranges from -60 or so to 0. You can see the way I did it in the InputAnalyzer sample here.

Concerning pitch detection, as I wrote in that forum post 6 years ago, it is completely doable just difficult to generalize into a built-in node. I suggested that you do it in an audio::Node subclass. Though I do think if someone came up with one that worked well in common cases and didn’t have external dependencies then we could include it. For example, Pure Data includes a pitch detector external (signmund~), but you’ll find it in the ‘extra’ folder.


1 Like

Thank you for your insight. The more I looked into some of the subclasses, I started to see what was going on there.