epicbob57 epicbob57 - 3 years ago 99
C# Question

Sine wave clicking with Beep.BeepBeep

Originally, my project to make a song in the windows console using C# used

Console.Beep(freq,time);
, but the unreliability of it caused desyncs.

I changed to using the Beep Beep class. The problem is that when playing a baseline, there was an audible click at the end of every note. Here's an example. With a single note it's not bad, but with many consecutive notes it's unbearable.

Even when I opened it in a wave editor, no matter where I cropped it it always clicked.

How can I get rid of this clicking, without installing any bulky libraries into my C# Console Project?

Answer Source

Have you tried ramping the amplitude up at the start of the sound and then down again at the end. So, modify the inner loop of that beep beep class, that reads...

    for (int T = 0; T < Samples; T++)
    {
      short Sample = System.Convert.ToInt16(A * Math.Sin(DeltaFT * T));
      BW.Write(Sample);
      BW.Write(Sample);
    }

could be modified to this

 for (int T=0; T < Samples; T++)
 {
     double AmpRamp = 1.0D;
     if (T<1000) {
         AmpRamp = ((double) T) / 1000.0D;
     } else if (T > Samples - 1000) {
         AmpRamp = ((double) (Samples - T)) / 1000.0D;
     }
     short Sample = System.Convert.ToInt16(A*AmpRamp*Math.Sin(DeltaFT * T));
     BW.Write(Sample);
     BW.Write(Sample);
 }

This ramps up the amplitude for the first 1000 samples, and then ramps it down for the last 1000, but you may have to change that number of samples for the ramp.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download