TheNewOne TheNewOne - 1 month ago 14
C Question

[portaudio]Transmit and Detect frequency - Windows

I'm new to portaudio and i looked at "How to extract frequency..." question but still i would like to have some help.
i need to transmit a frequency (using the speakers) and then i would like to check if this frequency was transmitted (catching it in the microphone), of course that i would like to use portaudio for the sending and detecting.
also,i have no idea how to use the fft for detection because i saw the record example and they use a SAMPLE data type and with this data type they can find the max amplitude can i use it for finding the frequency?

tnx in advance.


Playing a simple tone is given as sample code in PortAudio.

Although the pitch there is not calculated from a specific number, it's easy to figure out:

amplitude[n] = sin( n * desiredFreq * 2 * pi / samplerate )

As in the PortAudio example code, you may want to consider using a lookup table rather than counting on sin() for each call, both for performance (and accuracy of sin at large numbers, which might be fine, but I'm not sure about).

Detecting what frequency is being played is a question that has been asked here on SO. Here is an answer I gave recently.

The upshot is that there are many ways depending on your skill level, and issues such as background noise. If you are just detecting a simple sin wav and don't expect a lot of noise, you might do well to just count zero crossings after making sure that the signal is above a certain threshold. If you do expect noise, you'll have to get fancier.