Answer the question
In order to leave comments, you need to log in
Is it possible to update the form after changing the data?
Hello !
I have a working code
Imports NAudio.Wave
Public Class MainForm
Dim Str As String
Public Sub New()
InitializeComponent()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Str = TextBox1.Text
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim waveOut = New WaveOut()
Dim osc = New SineWaveOscillator(44100)
osc.Frequency = Str
osc.Amplitude = 8192
waveOut.Init(osc)
waveOut.Play()
End Sub
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Public Class SineWaveOscillator
Inherits WaveProvider16
Dim phaseAngle As Double
Public Sub New(sampleRate As Int32)
MyBase.New(sampleRate, 1)
End Sub
Public Property Frequency As Double
Public Property Amplitude As Short
Public Overrides Function Read(buffer() As Short, _
offset As Integer, sampleCount As Integer) As Integer
For index = 0 To sampleCount
buffer(offset + index) = Amplitude * Math.Sin(phaseAngle)
phaseAngle += 2 * Math.PI * Frequency / WaveFormat.SampleRate
If phaseAngle > 2 * Math.PI Then
phaseAngle -= 2 * Math.PI
End If
Next
Return sampleCount
End Function
End Class
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question