NAudio
NAudio copied to clipboard
Generating a tone above hearing range.
trafficstars
hey y'all. The code below is supposed to generate a tone above the threashold of a human hearing, but no.
Is this even supported? I see no upper limit. Or this lib doesn't support such tone?
var sine20Seconds = new SignalGenerator()
{
Gain = 0.3,
Frequency = 28500,
Type = SignalGeneratorType.Square
}
.Take(TimeSpan.FromSeconds(20));
using (var wo = new WaveOutEvent())
{
wo.Init(sine20Seconds);
wo.Play();
while (wo.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep(500);
}
}
You can't go above the Nyquist limit, which is half of the sample rate. So for example if you are using a sample rate of 44.1kHz, then you can't go above 22kHz. The signal generator won't stop you entering higher values, but you can expect "aliasing" to occur if you try to use them.