Results 1 to 30 of 30

Thread: Console.Beep Application

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    32

    Console.Beep Application

    Please forgive me as it has been years since I have messed with any of this stuff.

    I have made a simple application with one button. A press of the button generates a tone of 500hz for 1 second, and 1000 hz for 1 second. The only issue I have is how come when the program changes from the first tone to the second there is a short gap between them. Is there anyway to resolve this or at least make it "smoother"?

    Code:
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Console.Beep(500, 1000)
            Console.Beep(1000, 1000)
        End Sub
    End Class
    Also how would I go about making two text boxes(tone1 and tone2) on the form and substituting their values into the frequency?

    Code:
    Console.Beep(textbox1, 1000)
    Console.Beep(textbox2, 1000)
    Again forgive me for the ignorance as it has been ages since I have messed with programming at all. I just need to catch on again.

  2. #2

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    32

    Re: Console.Beep Application

    And also, how would I handle playing the tone as long as the mouse is clicked?

    Code:
    Private Sub Button2_mousedown(sender As Object, e As EventArgs) Handles Button2.MouseDown
            Console.Beep(1000, timepresseddown)
    
        End Sub
        Private Sub Button2_mouseup(sender As Object, e As EventArgs) Handles Button2.MouseUp
           
        End Sub

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Console.Beep Application

    You're about right on the second part of this. I'd use a NumericUpDown rather than a textbox, though. A textbox ONLY has text, which means it may be a number...or it may not be a number. If you changed the code to this:

    Console.Beep(textbox1.Text,1000)

    then the code will run as long as Option Strict is OFF, and the value in the textbox really is a number. If the textbox is empty, or the text isn't a number, then the code will crash. If Option Strict is ON (which it should be, since it prevents you from encountering that crash), then the code won't even compile, because of the invalid conversion of a string to an integer. There are ways to solve that, but the best and easiest is to use NumericUpDown controls, which ONLY have numbers. That would look like this:

    Console.Beep(CInt(yourNUD1.Value),1000)

    With Option Strict OFF, you wouldn't need the CInt(), but Option Strict is always a good idea except for the rare case where it doesn't work at all.

    As for the first question, I have no answer. Beep is ANCIENT!! I have no idea how it works under the hood.
    My usual boring signature: Nothing

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Console.Beep Application

    You probably can't use Beep to play as long as the mouse button is pressed. You could figure out how long the button was pressed, and play it after the mouse was released, but having it play as the button is pressed is probably not possible. Beep predates the mouse.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    32

    Re: Console.Beep Application

    Being that it is ancient, is there a more modern way to generate a sound wave? I just need the program to generate a tone for the frequency and duration I determine. I just found console.beep from quick research. If there is a better way I am open to it.

  6. #6
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Console.Beep Application

    Most any audio library out there can generate tones. NAudio works really well for this.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  7. #7
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Console.Beep Application

    ...in fact, since it's been ages since I last used it. I decided to whip up a quick tone-generator with NAudio.

    Make a new Windows Forms project.
    Add the NuGet package "NAudio" from "Project->Manage NuGet Packages" then Browse for NAudio.

    First, add a new Class to your project. Call it "SineWaveProvider"
    Open it.
    Copy in this code:
    Code:
    'The class below is my tone generator.  It makes SINE waves
    Public Class SineWaveProvider
        Inherits NAudio.Wave.WaveProvider32
    
        Private sample As Integer
    
        Public Frequency As Single
        Public Amplitude As Single
    
        Public Overrides Function Read(buffer() As Single, offset As Integer, sampleCount As Integer) As Integer
            Dim sampleRate As Integer = WaveFormat.SampleRate
            For i As Integer = 0 To sampleCount
                buffer(i + offset) = Convert.ToSingle(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate)) 'The formula for a sine wave.
                sample += 1
                If sample >= sampleRate Then sample = 0
            Next
            Return sampleCount
        End Function
    End Class
    Go to your main form, drop in the following:

    Code:
    Public Class Form1
        Private provider As New SineWaveProvider With {.Amplitude = 1, .Frequency = 2600} 'This is my tone generator, I'm setting it at 2600 hz
        Private out As New NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback) 'This is the thing that plays the tones
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            out.Init(provider) 'Set up my audio tone so it's ready to be triggered
        End Sub
    
        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
            out.Volume = 0.25 'Set Volume between 0 and 1 - 0.25 is so I don't blow my eardrums!
            out.Play() 'Play as long as the mouse button is held down
        End Sub
    
        Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
            out.Stop() 'Stop playing when it is let up
        End Sub
    End Class
    Run the project. You should hear a 2600hz tone when you press the mouse button on your form.

    No Imports were used so you can see where each object is coming from, though using them will clean up the code a bit.
    Enjoy!
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    32

    Re: Console.Beep Application

    Jenner, thanks a lot this works wonderfully.

    How would I incorporate multiple different tone frequencies? Like above the press of a button generated two tones one 500hz the next 1000hz. In other words, can NAudio be written to generate a tone sequence like Console.Beep did?

    Code:
       Console.Beep(500, 1000)
       Console.Beep(1000, 1000

  9. #9
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Console.Beep Application

    Of course. There's many ways to do it. You could write it into the SineGenerator for example:
    Close Encounters of the Third Kind anyone? (really sloppy example, but it's for demonstration)
    Code:
    Public Class SineWaveProvider
        Inherits NAudio.Wave.WaveProvider32
    
        Private sample As Integer
        Private totaltime As Integer
        Private seconds As Integer
    
        Public Frequency As Single
        Public Amplitude As Single
    
        Public Overrides Function Read(buffer() As Single, offset As Integer, sampleCount As Integer) As Integer
            Dim sampleRate As Integer = WaveFormat.SampleRate
    
            For i As Integer = 0 To sampleCount
                totaltime = Convert.ToInt32((seconds + (sample / sampleRate)) * 1000)
                Select Case totaltime
                    Case > 4200
                        seconds = 0
                        Frequency = 466.16
                    Case > 3200
                        Frequency = 311.13
                    Case > 2200
                        Frequency = 207.65
                    Case > 1200
                        Frequency = 415.3
                    Case > 600
                        Frequency = 523.25
                    Case Else
                        Frequency = 466.16
                End Select
                buffer(i + offset) = Convert.ToSingle(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate)) 'The formula for a sine wave.
                sample += 1
    
                If sample >= sampleRate Then
                    seconds += 1
                    sample = 0
                End If
            Next
            Return sampleCount
        End Function
    End Class
    Or... you can just make a bunch of provider objects and trigger them off on the main form (again, sloppy, but just an example)
    Code:
    Public Class Form1
        Private provider As New SineWaveProvider With {.Amplitude = 1, .Frequency = 500} 'This is my tone generator, I'm setting it at 500 hz
        Private provider2 As New SineWaveProvider With {.Amplitude = 1, .Frequency = 1000} 'This is my tone generator, I'm setting it at 1000 hz
        Private provider3 As New SineWaveProvider With {.Amplitude = 1, .Frequency = 2000} 'This is my tone generator, I'm setting it at 2000 hz
    
        Private out As New NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback) 'This is the thing that plays the tones
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'Set up my audio tone so it's ready to be triggered
        End Sub
    
        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
            out.Init(provider)
            out.Volume = 0.25 'Set Volume between 0 and 1 - 0.25 is so I don't blow my eardrums!
            out.Play() 'Play as long as the mouse button is held down
            Threading.Thread.Sleep(1000)
            out.Stop()
            out.Init(provider2)
            out.Play() 'Play as long as the mouse button is held down
            Threading.Thread.Sleep(1000)
            out.Stop()
            out.Init(provider3)
            out.Play() 'Play as long as the mouse button is held down
            Threading.Thread.Sleep(1000)
            out.Stop()
        End Sub
    
        Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
            out.Stop() 'Stop playing when it is let up
        End Sub
    End Class
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Console.Beep Application

    This line:
    Code:
     Private provider As New SineWaveProvider With {.Amplitude = 1, .Frequency = 2600} 'This is my tone generator, I'm setting it at 2600 hz
    creates the provider with a frequency (and an Amplitude). You should be able to create as many as you want with as many tones as you want by creating more Naudio.Wave.WaveOut objects (the 'out' variable). So, you might create a Dictionary(of Integer, NAudio.Wave.WaveOut), then build up the dictionary with a frequency as the key and the output as the value. Might look something like this:
    Code:
    Private myTones As New Dictionary(of Integer, NAudio.Wave.WaveOut)
    
    'Then, down in load you might do this.
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            out.Init(provider) 'Set up my audio tone so it's ready to be triggered
    dim out As SineWaveProvider 
    dim wavOut as NAudio.Wave.WaveOut
    for x=500 to 3000 Step 500
     out = New SineWaveProvider  With {.Amplitude = 1, .Frequency = 2600}
     wavOunt = New NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback)
     myTones.Add(x, wavOut)
     wavOut.Init(out)
    Next
    End Sub
    
    'Then to play one it may be:
        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
            out.Volume = 0.25 'Set Volume between 0 and 1 - 0.25 is so I don't blow my eardrums!
            myTones(500).Play() 'Play as long as the mouse button is held down
        End Sub
    In theory, this will create a dictionary of tones from 500 to 3000 for every 500 Hz difference. In practice, this may gobble up resources if the dictionary got too large. As it is, it's only six tones, so it probably would work fine. Of course, it can be refined. For one thing, this is just freehand code. Another point is that the only tone I'm playing is 500 Hz. You'd probably want to have some means to input a frequency. Also, this only generates the tones found in the dictionary. If you wanted to create a more dynamic tone generator, then you'd have to be creating and disposing the objects on some event, rather than creating them all on form load.

    EDIT: I was too slow.
    My usual boring signature: Nothing

  11. #11
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Console.Beep Application

    Haha, in all fairness, I looked up the tones and messed around with editing the SineWaveProvider to hum the 5 tones from Close Encounters not long after I posted my first reply...

    Probably to give my brain some subconscious time to process my own problem in the thread I made.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  12. #12

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    32

    Re: Console.Beep Application

    Thank you both for the help.

    This will sort of go along with what y’all are trying to explain but like above can I use the NumericUpDown as an input for the frequency? Sorry to make it even more complicated, as if it wasn’t complicated enough.

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Console.Beep Application

    You SHOULD use NumericUpDown as the entry control for any number.

    You can re-write the initial example such that it is taking the value from the NUD and putting it in frequency. Of course, the code can't be in the Load event any longer, so you'd probably want to add it to either the ValueChanged event for the NUD, or have a button that you click whenever you change the frequency. You might also want one for the volume, while you're at it.

    What I can't say is how much overhead you will get from the objects being created. If these objects are trivial as far as resources, then you can just make up as many of them as you want. If they are expensive in terms of resources, then you'd want to be explicitly disposing of the ones you are done with whenever you make new ones for the new frequency.
    My usual boring signature: Nothing

  14. #14

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    32

    Re: Console.Beep Application

    You mean this :

    Code:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            out.Init(provider) 'Set up my audio tone so it's ready to be triggered
        End Sub
    I tried putting it in the value changed event however I do not always need to change the frequency from the default.

    I tried this but I get an error: System.NullReferenceException: 'Object reference not set to an instance of an object.'

    Code:
     Private provider As New SineWaveProvider With {.Amplitude = 1, .Frequency = CInt(NumericUpDown1.Value)}

  15. #15
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Console.Beep Application

    Where did you try that? Since you use Private, it looks like you tried that at form scope, which won't work. No controls are created by the time that code runs. All controls are created in the InitializeComponents method, which is the first line in the constructor, which has yet to run by the time a form level variable is filled in, hence the exception.

    You may want one provider for the default, but it looks like you'll need to create a new provider and new WaveOut every time you change the NUD value.

    I started writing this an hour ago, then got called away. I wonder if it is still relevant?
    My usual boring signature: Nothing

  16. #16
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Console.Beep Application

    You can use one provider and just change the Frequency

    In your NumericUpDown_Changed event handler, just put:
    provider.Frequency = NumericUpDown1.Value
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  17. #17
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Console.Beep Application

    That's even easier.
    My usual boring signature: Nothing

  18. #18
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Console.Beep Application

    Quote Originally Posted by Shaggy Hiker View Post
    That's even easier.
    Hello
    I need help

    I am using Visual Studio.
    I am still learning to program and I have an exercise to do that I am not getting.
    I'm gonna explain.

    I have to create a simple frequency generator (tone). Only emit tones.
    If I use system.console.beep, everything that is asked to execute on the same button is stuck, I mean if I ask for an image to appear before the tone, this image only appears after the tone is executed.
    In addition, I also cannot emit frequencies of the type 7.83 or 20.50. I don't know how to do this.
    With the code I have, it only reads whole numbers.

    I'll pass the code I have:

    Public Sub generator (As String protocol)

    Dim frequencias () As String = protocol.Split (",")

    For i As Integer = 0 To frequencias.Length - 1 Step 1

    Dim freq () As String = frequencies (i). Split (":")

    If freq.Length <> 2 Then
    Exit Sub
    End If

    System.Console.Beep (CInt (freq (0)), CInt (freq (1)) * 1000)

    Next

    End Sub
    ..........
    Private Sub ToolStripMenuItem1_Click (sender As Object, and As EventArgs) Handles ToolStripMenuItem1.Click

    PictureBox2.Visible = True

    generator ("240: 60")

    End Sub

    Well, I need help with the following:

    That can generate frequencies of the type 7.83 or 20.50 example and not just whole frequencies (tones). and that whatever is asked to be done before it is done.

    Thank you all and sorry for my english

  19. #19
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Console.Beep Application

    Try this...

    Code:
    Public Class Form1
    
        Declare Function NtBeep Lib "kernel32.dll" Alias "Beep" (ByVal FreqHz As Integer, ByVal DurationMs As Integer) As Integer
        Declare Function Beep Lib "kernel32.dll" (ByVal dwFreq As Integer, ByVal dwDuration As Integer) As Boolean
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            NtBeep(247, 200)
            NtBeep(523, 200)
            NtBeep(494, 1200)
            NtBeep(587, 200)
            NtBeep(440, 200)
            NtBeep(494, 1100)
            NtBeep(494, 200)
            NtBeep(392, 200)
            NtBeep(247, 200)
            NtBeep(294, 250)
            NtBeep(262, 150)
            NtBeep(247, 1000)
    
            ''     frequencies are:
            ''   ________ _____________ 
            ''  |--------|-------------|
            ''  |  Note  |Frequency(Hz)|
            ''  |--------|-------------|
            ''  |   C0   | 16.35       | 
            ''  |--------|-------------|
            ''  |C#0/Db0 | 17.32       | 
            ''  |--------|-------------|
            ''  |   D0   | 18.35       |  
            ''  |--------|-------------|
            ''  |D#0/Eb0 | 19.45       |  
            ''  |--------|-------------|
            ''  |   E0   | 20.60       |  
            ''  |--------|-------------|
            ''  |   F0   | 21.83       |   
            ''  |--------|-------------|
            ''  |F#0/Gb0 | 23.12       |  
            ''  |--------|-------------|
            ''  |   G0   | 24.50       |  
            ''  |--------|-------------|
            ''  |G#0/Ab0 | 25.96       |  
            ''  |--------|-------------|
            ''  |   A0   | 27.50       |  
            ''  |--------|-------------|
            ''  |A#0/Bb0 | 29.14       |  
            ''  |--------|-------------|
            ''  |   B0   | 30.87       |  
            ''  |--------|-------------|
            ''  |   C1   | 32.70       |   
            ''  |--------|-------------|
            ''  |C#1/Db1 | 34.65       |  
            ''  |--------|-------------|
            ''  |   D1   | 36.71       |  
            ''  |--------|-------------|
            ''  |D#1/Eb1 | 38.89       |  
            ''  |--------|-------------|
            ''  |   E1   | 41.20       |  
            ''  |--------|-------------|
            ''  |   F1   | 43.65       |  
            ''  |--------|-------------|
            ''  |F#1/Gb1 | 46.25       |  
            ''  |--------|-------------|
            ''  |   G1   | 49.00       |  
            ''  |--------|-------------|
            ''  |G#1/Ab1 | 51.91       |  
            ''  |--------|-------------|
            ''  |   A1   | 55.00       |  
            ''  |--------|-------------|
            ''  |A#1/Bb1 | 58.27       |  
            ''  |--------|-------------|
            ''  |   B1   | 61.74       |  
            ''  |--------|-------------|
            ''  |   C2   | 65.41       |   
            ''  |--------|-------------|
            ''  |C#2/Db2 | 69.30       |   
            ''  |--------|-------------|
            ''  |   D2   | 73.42       |  
            ''  |--------|-------------|
            ''  |D#2/Eb2 | 77.78       |  
            ''  |--------|-------------|
            ''  |   E2   | 82.41       |  
            ''  |--------|-------------|
            ''  |   F2   | 87.31       |   
            ''  |--------|-------------|
            ''  |F#2/Gb2 | 92.50       |  
            ''  |--------|-------------|
            ''  |   G2   | 98.00       |   
            ''  |--------|-------------|
            ''  |G#2/Ab2 | 103.83      |  
            ''  |--------|-------------|
            ''  |   A2   | 110.00      | 
            ''  |--------|-------------|
            ''  |A#2/Bb2 | 116.54      |  
            ''  |--------|-------------|
            ''  |   B2   | 123.47      |  
            ''  |--------|-------------|
            ''  |   C3   | 130.81      | 
            ''  |--------|-------------|
            ''  |C#3/Db3 | 138.59      | 
            ''  |--------|-------------|
            ''  |   D3   | 146.83      | 
            ''  |--------|-------------|
            ''  |D#3/Eb3 | 155.56      | 
            ''  |--------|-------------|
            ''  |   E3   | 164.81      | 
            ''  |--------|-------------|
            ''  |   F3   | 174.61      | 
            ''  |--------|-------------|
            ''  |F#3/Gb3 | 185.00      | 
            ''  |--------|-------------|
            ''  |   G3   | 196.00      | 
            ''  |--------|-------------|
            ''  |G#3/Ab3 | 207.65      | 
            ''  |--------|-------------|
            ''  |   A3   | 220.00      | 
            ''  |--------|-------------|
            ''  |A#3/Bb3 | 233.08      |  
            ''  |--------|-------------|
            ''  |   B3   | 246.94      |  
            ''  |--------|-------------|
            ''  |   C4   | 261.63      | 
            ''  |--------|-------------|
            ''  |C#4/Db4 | 277.18      |  
            ''  |--------|-------------|
            ''  |   D4   | 293.66      | 
            ''  |--------|-------------|
            ''  |D#4/Eb4 | 311.13      | 
            ''  |--------|-------------|
            ''  |   E4   | 329.63      | 
            ''  |--------|-------------|
            ''  |   F4   | 349.23      | 
            ''  |--------|-------------|
            ''  |F#4/Gb4 | 369.99      |
            ''  |--------|-------------|
            ''  |   G4   | 392.00      | 
            ''  |--------|-------------|
            ''  |G#4/Ab4 | 415.30      | 
            ''  |--------|-------------|
            ''  |   A4   | 440.00      | 
            ''  |--------|-------------|
            ''  |A#4/Bb4 | 466.16      | 
            ''  |--------|-------------|
            ''  |   B4   | 493.88      | 
            ''  |--------|-------------|
            ''  |   C5   | 523.25      |  
            ''  |--------|-------------|
            ''  |C#5/Db5 | 554.37      | 
            ''  |--------|-------------|
            ''  |   D5   | 587.33      | 
            ''  |--------|-------------|
            ''  |D#5/Eb5 | 622.25      | 
            ''  |--------|-------------|
            ''  |   E5   | 659.26      | 
            ''  |--------|-------------|
            ''  |   F5   | 698.46      | 
            ''  |--------|-------------|
            ''  |F#5/Gb5 | 739.99      | 
            ''  |--------|-------------|
            ''  |   G5   | 783.99      |  
            ''  |--------|-------------|
            ''  |G#5/Ab5 | 830.61      | 
            ''  |--------|-------------|
            ''  |   A5   | 880.00      |  
            ''  |--------|-------------|
            ''  |A#5/Bb5 | 932.33      |  
            ''  |--------|-------------|
            ''  |   B5   | 987.77      | 
            ''  |--------|-------------|
            ''  |   C6   | 1046.50     | 
            ''  |--------|-------------|
            ''  |C#6/Db6 | 1108.73     | 
            ''  |--------|-------------|
            ''  |   D6   | 1174.66     | 
            ''  |--------|-------------|
            ''  |D#6/Eb6 | 1244.51     | 
            ''  |--------|-------------|
            ''  |   E6   | 1318.51     |  
            ''  |--------|-------------|
            ''  |   F6   | 1396.91     |
            ''  |--------|-------------|
            ''  |F#6/Gb6 | 1479.98     |
            ''  |--------|-------------|
            ''  |   G6   | 1567.98     | 
            ''  |--------|-------------|
            ''  |G#6/Ab6 | 1661.22     |  
            ''  |--------|-------------|
            ''  |   A6   | 1760.00     | 
            ''  |--------|-------------|
            ''  |A#6/Bb6 | 1864.66     | 
            ''  |--------|-------------|
            ''  |   B6   | 1975.53     |  
            ''  |--------|-------------|
            ''  |   C7   | 2093.00     | 
            ''  |--------|-------------|
            ''  |C#7/Db7 | 2217.46     | 
            ''  |--------|-------------|
            ''  |   D7   | 2349.32     | 
            ''  |--------|-------------|
            ''  |D#7/Eb7 | 2489.02     | 
            ''  |--------|-------------|
            ''  |   E7   | 2637.02     | 
            ''  |--------|-------------|
            ''  |   F7   | 2793.83     | 
            ''  |--------|-------------|
            ''  |F#7/Gb7 | 2959.96     | 
            ''  |--------|-------------|
            ''  |   G7   | 3135.96     | 
            ''  |--------|-------------|
            ''  |G#7/Ab7 | 3322.44     |
            ''  |--------|-------------|
            ''  |   A7   | 3520.00     |
            ''  |--------|-------------|
            ''  |A#7/Bb7 | 3729.31     | 
            ''  |--------|-------------|
            ''  |   B7   | 3951.07     | 
            ''  |--------|-------------|
            ''  |   C8   | 4186.01     | 
            ''  |--------|-------------|
            ''  |C#8/Db8 | 4434.92     | 
            ''  |--------|-------------|
            ''  |   D8   | 4698.64     |  
            ''  |--------|-------------|
            ''  |D#8/Eb8 | 4978.03     |  
            ''  |--------|-------------|
    
        End Sub
    
    End Class

  20. #20
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Console.Beep Application

    Thank you for your help.

    I've tried it and I can already have lower frequencies like 7.83 even if they are inaudible.
    the PictureBox continues to play only at the end of the tone

  21. #21
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Console.Beep Application

    OK thank you

  22. #22
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Console.Beep Application

    Hello,

    try to put
    Code:
     PictureBox2.Refresh()
    after
    Code:
     PictureBox2.Visible = True
    regards
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  23. #23
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Console.Beep Application

    Are you trying to run an animation in your PictureBox while playing console beeps? If your answer is yes, you'll need a secondary thread, to play your console beeps while playing your animation simultaneously...

  24. #24
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Console.Beep Application

    Thank you all for your help
    The animation does not work when the tone is running.
    I went around creating 2 independent activations. but frankly I don't like it.
    Can you give me a code example?
    I'm also trying to create a square sign.
    I have an old program here that the low tones are audible.
    so I will try.

  25. #25
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Console.Beep Application

    a square sign??? You mean ² ???

  26. #26
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Console.Beep Application

    Yes with a square sign.

    I still have problems because low frequencies with 5.5 are not heard.

    Beyond this,
    any animation is blocked when the beep sounds.

    i will pass the code maybe you can help me.
    I remember that I am an apprentice.

  27. #27
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Console.Beep Application

    Name:  1.PNG
Views: 442
Size:  9.4 KB

    These are the frequencies to emit.

    if I click, for example at 0.50 Ntbeep does not let any image or animation appear.
    They are visible only after being executed.
    So I had to create a button and beep from here.
    but I think there has to be an alternative, to be executed right away from ToolStripMenuItem
    Name:  2.jpg
Views: 425
Size:  7.3 KB
    Name:  3.jpg
Views: 470
Size:  12.7 KB
    Name:  4.jpg
Views: 528
Size:  15.2 KB

  28. #28
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Console.Beep Application

    Quote Originally Posted by Zigor View Post
    I still have problems because low frequencies with 5.5 are not heard.
    That's because the human ear can't hear frequencies that low.

  29. #29
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Console.Beep Application

    Thanks for the answer.
    But, I have here a very simple program, from 2001 by Fred Water that you can hear the frequencies, which makes me think it will be with a square signal.
    Name:  5.PNG
Views: 495
Size:  6.2 KB

  30. #30
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Console.Beep Application

    A square wave will have a lot of harmonics (technically an infinite series of odd harmonics).
    With a square wave that is that low in frequency, you are not hearing the wave, but some of the harmonic components of the wave.
    I would imaging the strongest harmonic that you could hear with a 5.5 hz square wave would be the 5th harmonic, 27.5 hz.

    If you're playing a sine wave, then that is a "pure" wave, so no harmonics, and you wouldn't likely hear below 20hz, depending on how good your hearing is.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

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