That’s a pretty simplistic description of a complex requirement. Playing a 400 Hz sine wave in front of a microphone for one second is one thing, but if I sing or say “something” into a microphone, you might have a complex, 500 ms waveform that includes a mixture of many changing frequencies and harmonics. How do you pick out the frequency that you plan to measure?
There is no short and simple answer here. If you are getting a sound sample from a microphone, and want to determine the fundamental frequency, you will need to use a Fourier Transform. There are many implementations of a Fast Fourier Transform (FFT) available, which is the most common transform in use. Wikipedia has a good article on FFTs, at <a href=”http://en.wikipedia.org/wiki/Fast_Fourier_transform”>http://en.wikipedia.org/wiki/Fast_Fourier_transform</a>. This also has links at the bottom to various FFT code and examples.
A good tutorial, with some nice code samples, of how to capture and convert code is available at <a href=”http://www.relisoft.com/freeware/recorder.html”>http://www.relisoft.com/freeware/recorder.html</a>
In highly simplistic terms, an FFT can take a sound sample and return a list of frequencies with associated “counts” (or magnitudes). The frequency with the highest value is the fundamental frequency of the sample.
There are of course already many devices for tuning musical instruments that display the frequency. Professional guitarists I know use devices like the Intellitouch or Korg clamp-on units that display the fundamental frequency in a small lcd window as they pluck a string. There are also quite a few software applications that sound like they do what you are contemplating – search for “guitar tuner online” to see a bunch.