none
Beep Beep Hearing Test RRS feed

  • General discussion

  • Someone asked about using John Wein's Beep Beep as a Hearing test. Here's a Console App to have a look at:
    Imports System.IO
    Imports System.Media
    
    Module Module1
        Private Amplitude As Integer = 0
        Private StartFreq As Integer = 0
        Private EndFreq As Integer = 0
        Private FreqStep As Integer = 0
        Private Duration As Integer = 0
        Private Sub ShowFancy(TextToShow As String)
            If TextToShow.IndexOf(" - ") = -1 Then
                Console.WriteLine(TextToShow)
                Exit Sub
            End If
            Dim Section1 As String = TextToShow.Substring(0, TextToShow.IndexOf(" - "))
            Dim Section2 As String = TextToShow.Substring(TextToShow.IndexOf(" - "))
            Dim currentForeground As ConsoleColor = Console.ForegroundColor
            'Console.CursorVisible = False
            Console.Write(Section1)
            Console.ForegroundColor = ConsoleColor.Red
            Console.WriteLine(Section2)
            Console.ForegroundColor = currentForeground
        End Sub
        Private Sub ShowUsage()
            Console.Clear()
            Console.WriteLine("Usage for HearingTest")
            Console.WriteLine("HearingTest.exe Amplitude StartFrequency EndFrequency FrequencyStep Duration")
            ShowFancy("Amplitude - Volume (0 to 1000)")
            ShowFancy("StartFrequency - First Frequency to generate")
            ShowFancy("EndFrequency   - First Frequency to generate")
            ShowFancy("Frequency Step - Hz to add each time")
            ShowFancy("Duration - Milliseconds to play each tone")
            Console.WriteLine()
            Console.WriteLine("Example: HearingTest.exe 1000 2000 24000 500 1000")
            Console.WriteLine("Generate full volume frequencies from:")
            Console.WriteLine("2000 Hz to 24000 Hz in intervals of 500 for 1 second each")
            ShowFancy("Press any key to exit")
            Console.ReadKey()
            End
        End Sub
        Sub Main()
            Dim Args() As String = Environment.GetCommandLineArgs()
            If Args.Length <> 6 Then
                ShowUsage()
            End If
            If Not Integer.TryParse(Args(1), Amplitude) Then ShowUsage()
            If Not Integer.TryParse(Args(2), StartFreq) Then ShowUsage()
            If Not Integer.TryParse(Args(3), EndFreq) Then ShowUsage()
            If Not Integer.TryParse(Args(4), FreqStep) Then ShowUsage()
            If Not Integer.TryParse(Args(5), Duration) Then ShowUsage()
            Console.Clear()
            Console.WriteLine("Volume " & Amplitude.ToString & " from " & StartFreq.ToString & " Hz to " & EndFreq.ToString & _
                              " Hz, Skipping " & FreqStep & " Hz each time for " & Duration.ToString & " ms.")
            Console.WriteLine("press ENTER to begin the test or CTRL-C to exit")
            Console.ReadLine()
            For Freq As Integer = StartFreq To EndFreq Step FreqStep
                Console.Write("Frequency = " & Freq.ToString & " ")
                Beep.Beep(Amplitude, Freq, Duration)
                Console.Write("Done - press ENTER for next frequency or CTRL-C to exit")
                Console.ReadLine()
            Next
        End Sub
    
    End Module
    Public Class Beep
        Shared Sub Beep(ByVal Amplitude As Integer, _
                 ByVal Frequency As Integer, _
                 ByVal Duration As Integer)
            Dim A As Double = ((Amplitude * 2 ^ 15) / 1000) - 1
            Dim DeltaFT As Double = 2 * Math.PI * Frequency / 44100
    
            Dim Samples As Integer = 441 * Duration \ 10
            Dim Bytes As Integer = Samples * 4
            Dim Hdr() As Integer = {&H46464952, 36 + Bytes, &H45564157, _
                                    &H20746D66, 16, &H20001, 44100, _
                                     176400, &H100004, &H61746164, Bytes}
            Using MS As New MemoryStream(44 + Bytes)
                Using BW As New BinaryWriter(MS)
                    For I As Integer = 0 To Hdr.Length - 1
                        BW.Write(Hdr(I))
                    Next
                    For T As Integer = 0 To Samples - 1
                        Dim Sample As Short = CShort(A * Math.Sin(DeltaFT * T))
                        BW.Write(Sample)
                        BW.Write(Sample)
                    Next
                    BW.Flush()
                    MS.Seek(0, SeekOrigin.Begin)
                    Using SP As New SoundPlayer(MS)
                        SP.PlaySync()
                    End Using
                End Using
            End Using
        End Sub
    End Class
    
    Not sure if it is just me and my old ears, but as the frequency rises, the volume goes down quite a bit and at 14000, it's gone.

    Saturday, January 6, 2018 11:01 PM

All replies

  • Not sure if it is just me and my old ears, but as the frequency rises, the volume goes down quite a bit and at 14000, it's gone.

     This would have a lot to do with the quality of your speakers/headphones and the actual amplifier used internally in them to power the speakers.  Not all speakers/headphones will handle different frequencies the same,  and some audio amplifiers will not amplify higher and/or lower frequencies the same as the mid frequencies.  For example,  my laptop has little rinky-dink built-in speakers that will not produce lower end frequencies as good as the mid frequencies even though they are played at the same amplitude.

     So,  it might not be your old ears after all.  Hopefully that makes you feel a little better about your ears.  haha  8) 


    If you say it can`t be done then i`ll try it

    Saturday, January 6, 2018 11:15 PM
  • Not sure if it is just me and my old ears, but as the frequency rises, the volume goes down quite a bit and at 14000, it's gone.

     This would have a lot to do with the quality of your speakers/headphones and the actual amplifier used internally in them to power the speakers.  Not all speakers/headphones will handle different frequencies the same,  and some audio amplifiers will not amplify higher and/or lower frequencies the same as the mid frequencies.  For example,  my laptop has little rinky-dink built-in speakers that will not produce lower end frequencies as good as the mid frequencies even though they are played at the same amplitude.

     So,  it might not be your old ears after all.  Hopefully that makes you feel a little better about your ears.  haha  8) 


    If you say it can`t be done then i`ll try it

    Yeah. I hear 14000 with the amp set on 100 through my crummy monitor speakers. My ears a fairly damaged from too much loud in the past. On a more complicated beep it I was doing I had to use my headphones.

    I think headphones would be used for a real hearing test. Have you had one? They just play little faint notes and you point to the ear you hear it in (with headphones). At least that's how it was 40 years ago when I had one.

    And finally I don't know what beepit is capable of but careful with the headphones I suppose it might be possible to make loud noise that might be hard on the ears or something.

     

    Sunday, January 7, 2018 12:46 PM
  • How does it work?  All it says is to press any key to exit.

    Solitaire

    Sunday, January 7, 2018 7:31 PM
  • Here is a forms version I had already that I was using that I may have modified. Just click the button you hear one beep with the settings in form load.

    'plays sound interval
    'by John Wein
    Option Strict On
    Public Class SoundBeepIt
    
        Dim MSTick As IO.MemoryStream
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
            BeepIt(300, 1000, 200) ' Duration is 100th's of a second.
        End Sub
    
        Private Sub BeepIt(ByVal Amplitude As Integer, ByVal Frequency As Integer, ByVal Duration As Integer)
            Dim A As Double = ((Amplitude * 2 ^ 15) / 1000) - 1
            Dim DeltaFT As Double = 2 * Math.PI * Frequency / 44100
    
            Dim Samples As Integer = 441 * Duration \ 10
            Dim Bytes As Integer = Samples * 4
            Dim Hdr() As Integer = {&H46464952, 36 + Bytes, &H45564157,
                                    &H20746D66, 16, &H20001, 44100,
                                     176400, &H100004, &H61746164, Bytes}
            Using MS As New IO.MemoryStream(44 + Bytes)
                Using BW As New IO.BinaryWriter(MS)
                    For I As Integer = 0 To Hdr.Length - 1
                        BW.Write(Hdr(I))
                    Next
                    For T As Integer = 0 To Samples - 1
                        Dim Sample As Short = CShort(A * Math.Sin(DeltaFT * T))
                        BW.Write(Sample)
                        BW.Write(Sample)
                    Next
                    MS.Position = 0
                    MSTick = New IO.MemoryStream(MS.ToArray)
                End Using
            End Using
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            MSTick.Position = 0
            Dim SP As New Media.SoundPlayer(MSTick)
            SP.Play()
            SP.Dispose()
        End Sub
    
    End Class
    

    Sunday, January 7, 2018 7:49 PM
  •  So,  it might not be your old ears after all.  Hopefully that makes you feel a little better about your ears.  haha  8) 


    If you say it can`t be done then i`ll try it

    Or it could be attributed to the inner ear disease that I have.

    It is what it is though. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    • Edited by Frank L. Smith Sunday, January 7, 2018 7:57 PM ...formatting
    Sunday, January 7, 2018 7:57 PM
  • Solitaire,

     You need to pass it a few Arguments to specify the AmplitudeStartFrequencyEndFrequency FrequencyStep,  and the Duration length of the tone.  If you run it as is with no arguments,  it will only show you the Usage in the console window.

     You can specify the Arguments while debugging by going to the application's Properties and clicking on the Debug tab.  There you will find a textbox you can type the Arguments into to test it while debugging.

     Other than that,  you would need to run it with the Process class and specifying the Arguments to start the exe with,  or open a CMD prompt window and type the exe name and arguments.

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, January 7, 2018 8:06 PM
    Sunday, January 7, 2018 8:02 PM
  •  If pass these arguments to it,  it will play a tone at full amplitude starting at 100Hz and go to 9000Hz at 200Hz steps,  playing each tone for 1 second (1000ms).

    1000 100 9000 200 1000


    If you say it can`t be done then i`ll try it

    Sunday, January 7, 2018 8:20 PM
  • Or it could be attributed to the inner ear disease that I have.

    It is what it is though. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering


     That must suck.  I could not imagine having to deal with those symptoms all the time.  8(

    If you say it can`t be done then i`ll try it

    Monday, January 8, 2018 1:32 AM
  •  That must suck.  I could not imagine having to deal with those symptoms all the time.  8(

    If you say it can`t be done then i`ll try it

    I'll explain more some other time but work is a real challenge (and increasingly so as I get older).

    Still though ... you deal with what's handed to you.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, January 8, 2018 2:29 AM
  • Still though ... you deal with what's handed to you.

    "A problem well stated is a problem half solved.” - Charles F. Kettering

     Yes,  i understand that one.  I have dealt with type 1 diabetes for about 46 years now and i have lots of problems with that.  Been pretty lucky so far though. **knock on wood**  But, I figure there are people worse off than me though.  8)

     I'm out of here for the night....


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, January 8, 2018 2:39 AM
    Monday, January 8, 2018 2:38 AM
  • How does it work?  All it says is to press any key to exit.

    Solitaire

    You have to furnish 5 parameters:

    HearingTest.exe Amplitude StartFrequency EndFrequency FrequencyStep Duration
    If you don't, or any of the parameters is not a number it should show the usage screen.
    There is an error in one usage line, it was:
    ShowFancy("EndFrequency   - First Frequency to generate")
    should be:
    ShowFancy("EndFrequency   - Last Frequency to generate")


    Monday, January 8, 2018 3:35 AM
  •  So,  it might not be your old ears after all.  Hopefully that makes you feel a little better about your ears.  haha  8) 


    If you say it can`t be done then i`ll try it

    Or it could be attributed to the inner ear disease that I have.

    It is what it is though. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Frank - have a look at this
    Tuesday, January 9, 2018 5:18 AM
  • Frank - have a look at this

    Thanks Devon,

    Sorry for taking this thread off-topic. I shouldn't have mentioned it.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, January 9, 2018 1:53 PM
  • I am trying to use the same code for hdr() (the wave file format) in C#. But I am unable to implement it. Can anyone help me here for the same code in C#?

    I tried to use the array 

    int[] hdr = {&H46464952, 36 + Bytes, &H45564157,&H20746D66, 16, &H20001, 44100,176400, &H100004, &H61746164, Bytes}

     But it's not accepting the values. 
    Thursday, March 1, 2018 5:43 PM
  • I am trying to use the same code for hdr() (the wave file format) in C#. But I am unable to implement it. Can anyone help me here for the same code in C#?

    I tried to use the array 

    int[] hdr = {&H46464952, 36 + Bytes, &H45564157,&H20746D66, 16, &H20001, 44100,176400, &H100004, &H61746164, Bytes}

     But it's not accepting the values. 

    You just have to change the &H to 0x:

    int[] hdr = {0x46464952, 36 + Bytes, 0x45564157,
                        0x20746D66, 16, 0x20001, 44100,
                         176400, 0x100004, 0x61746164, Bytes};
    


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Thursday, March 1, 2018 7:49 PM
    Moderator