Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Measuring sound frequency from mic...
#1
Is there any way to calculate the wave length of a sound going throught the mic in hz? I want to make a guitar tuner. Here's some simple code to use for the mic:

'*UnTested!*

CONST BaseAddr = &H220 'Replace with your base address
CONST CommAddr = BaseAddr + &HC
CONST DataAddr = BaseAddr + &HA
CONST XMax = 320

DIM Byte(XMax) AS INTEGER
SCREEN 13:CLS

DO

FOR i% = 0 to XMax-1
PRESET(i%, Byte(i%))
OUT CommAddr, &H20
Byte(i%) = INP(DataAddr)
PSET(i%, Byte(i%))
NEXT i%

LOOP

This should display a wave pattern on the screen when using your mic. The x origin seems to be between y pixel 110 and 112. There also seems to be three distinct wave patterns at every moment. If you took the DO:LOOP off, humed a constant tone, and started the program while humming that tone, it would display 320 samples. If you try this, you'll see what I mean by three seperate waves. I'm not sure why that is. Anyways, I thought about how I would calculate the amount of hz going into the mic, and I couldn't come up with any efficient ways of getting an accurate reading, well, not good enough to tune my guitar that is. Any suggestions?
Reply
#2
:o



I have no idea what you're doing. But if you get it working, please post back, because I wouldn't mind having a guitar tuner on the PC either. I always just use CoolEdit to generate tones and then match them... I couldn't be bothered actually shelling the $20 for a little box.
Reply
#3
At first glance you are reading separate samples in a for loop.( I did'nt know you could do that maybe i have not read enough about the SB).
I think this is a wrong way to start, any variation of the PC speed will change the speed of the loop so any frequency calculation will be wrongl.
Maybe you should learn how to set up a DMA buffer ,and a sampling rate in the SB. By fixing the sample rate you have the posibility of measuring the frequence. Check the SB oscilloscope at
http://www.ocf.berkeley.edu/~horie/project.html
Then, how to measure frequence?. No idea, just a guess: you could find two contiguous minimum values of the wave and count the number of samples between them. By knowing the length of a sample, yoy can calculate the period, so you have the frequency. I think it should work if the wawe has few harmonics...
Antoni
Reply
#4
Great, I'll take a look at that . Anybody else?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)