This project has moved. For the latest updates, please go here.

Synthesis of a basic wave , and change the frequency

Nov 12, 2012 at 11:27 AM
Edited Nov 12, 2012 at 11:30 AM

Hello everyone ,

I'm a beginner with NAudio and I want to create a basic sinus wave and modify its frequency with the move of the mouse . I followed this tutorial .And in my MainWindow , I've just added

And my sinus wave changed its frequency but the changes are not fluid , anyone has some ideas how that can be more fluid ?


double GetFrequency(Rectangle sender, MouseEventArgs e)
// This function is just to convert the position of the mouse to a frequency { ... } private void Rectangle_MouseMove_2(object sender, MouseEventArgs e) { if(Mouse.LeftButton == MouseButtonState.Pressed) { sineWaveProvider.Frequency = (float)GetFrequency((Rectangle)sender, e);
// Here I change the frequency while playing
} } private void Rectangle_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e) { sineWaveProvider.Frequency = (float)GetFrequency((Rectangle)sender, e); sineWaveProvider.Amplitude = 0.25f; waveOut = new WaveOut(); waveOut.Init(sineWaveProvider); waveOut.Play();
// When you click , the sound starts playing
  } private void Rectangle_MouseLeftButtonUp_1(object sender, MouseButtonEventArgs e) { waveOut.Stop(); waveOut.Dispose(); waveOut = null;
// When you released, the sound stops } }
Nov 12, 2012 at 11:54 AM

for smooth frequency changes you need to implement a portamento algorithm. One way to do this is with a wavetable, where you slowly change the offset intot the wavetable you are operating with. It's a tricky algorithm if you are a beginner to DSP, but hopefully that points you in the right direction.

Nov 12, 2012 at 2:58 PM

I've found this that's totally solved my problem -->