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.

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

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.