Results 1 to 15 of 15

Thread: VB6 - Detecting frequencies from microphone sounds

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    VB6 - Detecting frequencies from microphone sounds

    I'm coding a program to detect frequencies from a given sample of sound, in this case from the microphone.
    I don't fully visualize how to do that. It will very helpful some answers about this topic.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: VB6 - Detecting frequencies from microphone sounds

    I suggest you do some research on Fast Fourier Transform (FFT)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: VB6 - Detecting frequencies from microphone sounds

    I've done some research on FFT. The first thing I've to do is to store in a variable the information from the microphone that is the thing I'm reading how to do. Once I've the information then I can do FFT to determine 1) Frequency 2)decibels.

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    24

    Re: VB6 - Detecting frequencies from microphone sounds

    Bass.dll examples do it. The whole spectrum is divided into a given number of parts (eg, 4096), in each of them can be found the force.
    Last edited by Filyus; Dec 11th, 2012 at 05:35 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: VB6 - Detecting frequencies from microphone sounds

    But my main question is what kind of data I've to analyze to get the frequencies. I know the method I've to use is FFT. But my question is what kind of variable that contains the data I've to analyze.
    As far I know, I think it should be the buffer that contains the variables of microphone audio input. Using FFT I can analyze it, right?

    My other question is about the mechanism involved since I produce a sound in the microphone until that sound information is stored in a variable. I don't know how to do that because I've no idea about the mechanism involved.

  6. #6
    Junior Member
    Join Date
    Jul 2011
    Posts
    24

    Re: VB6 - Detecting frequencies from microphone sounds

    Right, but it is already done by bass.dll.
    But using the FFT may be very interesting.. Look at http://www.planetsourcecode.com/vb/s...xtCriteria=FFT

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: VB6 - Detecting frequencies from microphone sounds

    Have you any link to the website of bass.dll? I've found some links, but as you know some can offer an old version.
    I'm learning now to do the same using DirectSound.
    I've found a piece of code in planetsourcecode.com that comes inside a vb program:
    Code:
    Private Sub DirectSoundRecord_GotWaveData(Buffer() As Byte, BitsPerSample As Integer, Channels As Integer)
    I think in those lines I can examine the microphone buffer and pass the data to the FFT function. Right?

  8. #8
    Junior Member
    Join Date
    Jul 2011
    Posts
    24

    Re: VB6 - Detecting frequencies from microphone sounds

    http://www.un4seen.com/ There are many examples on the VB...

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: VB6 - Detecting frequencies from microphone sounds

    Thanks for the link.
    Apparently, I've obtained the data from the microphone buffer using the code I posted above.
    Private Sub DirectSoundRecord_GotWaveData

    The problem is that the Buffer is Byte type and when I do...
    Dim MyVariable as string
    MyVariable = Byte
    Text1.text = text1.text & MyVariable

    The 90% of the text is "???????????????????????"
    My question is if I can pass that Byte data to the FFT function to get the frequencies.

    I'm also learning about Bass.dll

  10. #10
    Junior Member
    Join Date
    Jul 2011
    Posts
    24

    Re: VB6 - Detecting frequencies from microphone sounds

    I think you can add FFT in the DisplayWaveData16 and the DisplayWaveData8 procedures.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: VB6 - Detecting frequencies from microphone sounds

    Thanks, I've found this in the code:

    Code:
    ' the sound is 16 bit, but it comes in Bytes, not Integer
    Private Sub DisplayWaveData16_8(DataBuff() As Byte, Pic As PictureBox, Stereo As Boolean)
        Dim Buff() As Integer
        
        ReDim Buff(UBound(DataBuff) \ 2 - 1)
        
        CopyMemory Buff(0), DataBuff(0), UBound(DataBuff) + 1
        
        DisplayWaveData16 Buff, Pic, Stereo
    End Sub
    I think DataBuff is the variable that stores the values that are read from the microphone input. I've also found inside the code DisplayWaveData8. I tried before to put the DataBuff in a textbox but an error message appears. So I think I've to transform the variable type from Byte to String.
    I do:
    dim MyVariable as string
    MyVariable = DataBuff
    Text1.text = Text1.text & MyVariable

    Is this way correct or there is a specific function to change from Byte type to String type variable?

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: VB6 - Detecting frequencies from microphone sounds

    I've made the conversion using StrConv but something similar happens. The textbox shows a lot of "????????????????????".
    I've read in microsoft website that when you transform the data from Byte to String the data can be damaged because they're different format (Ansi and Unicode).

    Just a Question.... the information in the Byte type variable is writting data to the file using values from 0 to 255. The frequency of audible sounds can be up to 4,000 Hertz or even more in some cases. So, if I want to measure the tones using FFT... I think some kind of transformation between Byte to Hertzs is made but I've to check the source code of the FFT.

  13. #13
    Junior Member
    Join Date
    Jul 2011
    Posts
    24

    Re: VB6 - Detecting frequencies from microphone sounds

    Why do you want to use a strings when this is only the numbers required?

    8 bits per sample - it is unsigned values (from 0 to 255)
    16 bits and more - it is signed values (from -32768 to 32767 for the 16 bits)
    In the stereo wave, samples are interleaved:
    Left value, than right value etc.

    Values in the samples is not Hertzs, it is volts. You must find a sine/cosine functions from volts with the FFT.

    I think this information is enough.
    Last edited by Filyus; Dec 16th, 2012 at 07:02 AM.

  14. #14
    Junior Member
    Join Date
    Jul 2011
    Posts
    24

    Re: VB6 - Detecting frequencies from microphone sounds

    You can try this... VBFFT.bas
    more samples: http://s.pudn.com/search_hot_en.asp?k=FFt+VB#
    Last edited by Filyus; Dec 16th, 2012 at 07:39 AM.

  15. #15
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: VB6 - Detecting frequencies from microphone sounds

    Quote Originally Posted by Jose_VB View Post
    Just a Question.... the information in the Byte type variable is writting data to the file using values from 0 to 255. The frequency of audible sounds can be up to 4,000 Hertz or even more in some cases. So, if I want to measure the tones using FFT... I think some kind of transformation between Byte to Hertzs is made but I've to check the source code of the FFT.
    I guess you have to study first what FFT is. It is certainly not a frequecy meter. It is converting from the time domain to the frequency domain. Its resolution (freq steps) depends of the sample rate (soundcard) and the samples you have. Read this (chapter 10 and on) as a start:
    http://www.dspguide.com/pdfbook.htm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width