I am using NAudio to reproduce the sine frequency of a given frequency, as in the blog post Play Sine Wave in NAudio . I just want the sound to play () in milliseconds and then stop.
I tried thread.sleep, but the sound stops immediately. I tried a timer, but when WaveOut is located, there is a cross-thread exception.
I tried this code, but when I call a beep, the program freezes.
public class Beep { public Beep(int freq, int ms) { SineWaveProvider32 sineWaveProvider = new SineWaveProvider32(); sineWaveProvider.Amplitude = 0.25f; sineWaveProvider.Frequency = freq; NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(WaveCallbackInfo.FunctionCallback()); waveOut.Init(sineWaveProvider); waveOut.Play(); Thread.Sleep(ms); waveOut.Stop(); waveOut.Dispose(); } } public class SineWaveProvider32 : NAudio.Wave.WaveProvider32 { int sample; public SineWaveProvider32() { Frequency = 1000; Amplitude = 0.25f;
c # sine wave naudio
amcashcow
source share