# How to Obtain the frequency of a sample using JUCE?

I am new to audio programming/JUCE and I wanted to know how i could obtain the frequency of one sample if thats possible.
I tried looking through the documentation to see if there was an function for it but I couldnt find anything.

You canāt do that, you need to consider the samples around it as well (and there are many ways you can do it then).

To clarify, this is not a limitation of JUCE, but a physical one. A sample is a discrete value in time, and the frequency is defined from changes over time (and periodic behaviour).

The uncertainty principle limits the resolution of frequency and time (damn you, heisenberg!). So you canāt get a good resolution in time (sample per sample) and a good resolution in frequency. Thereās always a trade-off between the two.

You might wanāt to take a look at the discrete Fourier-transform, which takes a number of samples and analysis the frequencies which occur within that time-window. An efficient implementation of it is the fast-fourier-transform (FFT), thereās also a JUCE class which performs the fft.

Thereās also a long discussion on the JUCE forum with some information about special windows you can apply to the time-signal, and overlapping the transformed blocks, to get a better frequency representation of your input signals: FFT Amplitude

What if the OP meant āshort piece of audio materialā for āsampleā? Thatās the term that most music software uses.

1 Like

If he was only interested in the frequency of one short piece of audio material then he likely would use other tools at his disposal for pitch detection, rather than seeking a general purpose approach using Juce.

What if the OP is actually in diary business and is refering to the cheese he pulled yesterday from the production line for quality control?

SCNR

1 Like

I would also assume that OP meant a short piece of audio recording. Because otherwise the question doesnāt make sense.

TLDR: Juce doesnāt have pitch detection built in, but a quick search on Github will give you some code that you can paste in your app.

1 Like