Results 1 to 3 of 3

Thread: [2005] Producing a Sin Wav - Sound .wav file

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    5

    [2005] Producing a Sin Wav - Sound .wav file

    I am making a function generator. As of right now, I am simply loading up pre-set .wav files.
    I have a file for 5Hz, a file for 10Hz...and so on.


    It would be nice If there was a way to actually generate these sounds on the fly, instead of loading them.


    My second problem is that when I switch between the files, or stop the sound, there is an audible "click" sound.

    Since this application will be used in a car audio environment, this "click" sound could damage a subwoofer at loud volumes.
    Any way to avoid this?

    Code here:

    Code:
    Public Class Form1
        Dim Freq As Int64
        Dim Off As Boolean
    
    
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Freq = 1
            Off = True
            Me.LCD.Text = "Frequency: " & Freq * 5 & "Hz"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Freq < 16 Then
                Freq += 1
                Me.LCD.Text = "Frequency: " & Freq * 5 & "Hz"
                PlayFreq()
            End If
        End Sub
    
    
       
    
    
    
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            If Freq > 1 Then
                Freq -= 1
                Me.LCD.Text = "Frequency: " & Freq * 5 & "Hz"
                PlayFreq()
            End If
        End Sub
    
        Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
            Off = False
            PlayFreq()
        End Sub
    
        Sub PlayFreq()
            If Off = False Then
                My.Computer.Audio.Stop()
                If Freq = 1 Then
                    My.Computer.Audio.Play(My.Resources._5_Hz, _
                        AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 2 Then
                    My.Computer.Audio.Play(My.Resources._10_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 3 Then
                    My.Computer.Audio.Play(My.Resources._15_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 4 Then
                    My.Computer.Audio.Play(My.Resources._20_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 5 Then
                   My.Computer.Audio.Play(My.Resources._25_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 6 Then
                   My.Computer.Audio.Play(My.Resources._30_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 7 Then
                    My.Computer.Audio.Play(My.Resources._35_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 8 Then
                    My.Computer.Audio.Play(My.Resources._40_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 9 Then
                   My.Computer.Audio.Play(My.Resources._45_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 10 Then
                    My.Computer.Audio.Play(My.Resources._50_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 11 Then
                 My.Computer.Audio.Play(My.Resources._55_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 12 Then
                   My.Computer.Audio.Play(My.Resources._60_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 13 Then
                    My.Computer.Audio.Play(My.Resources._65_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 14 Then
                    My.Computer.Audio.Play(My.Resources._70_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 15 Then
                   My.Computer.Audio.Play(My.Resources._75_Hz, _
                       AudioPlayMode.BackgroundLoop)
                ElseIf Freq = 16 Then
                 My.Computer.Audio.Play(My.Resources._80_Hz, _
                       AudioPlayMode.BackgroundLoop)
                End If
            End If
    
        End Sub
    
        Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
            Off = True
            My.Computer.Audio.Stop()
        End Sub
    End Class
    Last edited by ArcaneDreams; May 3rd, 2008 at 11:37 AM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Producing a Sin Wav - Sound .wav file

    Please don't post links to the executables. Post your source code if you wish to receive help with this

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    5

    Re: [2005] Producing a Sin Wav - Sound .wav file

    Quote Originally Posted by mendhak
    Please don't post links to the executables. Post your source code if you wish to receive help with this
    Removed the link.

    I have the source code posted in text form.

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