Is it possible to generate a constant sound in C# and manipulate its frequency as it goes?
I tried something like this:
for (int i = 500; i < 15000; i += 1)
{
Console.Beep(i, 500));
}
But being synchronous, the loop waits for each beep to finish. So I tried this:
for (int i = 500; i < 15000; i += 1)
{
new Thread(x => Console.Beep(i, 500)).Start();
}
I would think this would be a start toward generating a constant sound that is ever increasing in frequency. However, it still stutters as it goes. Is there a way to accomplish this but more smoothly?
If you want to do this in real-time (i.e. change the frequency dynamically in response to user input), this would be incredibly difficult and would entail your writing a software synthesizer. In that case, you might want to try using a library like NAudio (although I’m not 100% sure NAudio does realtime synthesis).
On the other hand, if you just want to pre-generate a WAV file with a continuously ascending tone and then play it, that’s incredibly easy.
Edit: a third alternative is to play a MIDI sound and send control change messages to the MIDI device to gradually apply portmanteau to a playing note. This is also easy, but has the disadvantage that you can’t be sure exactly how it will sound on somebody else’s computer.