title: (NAudio) How to use a buffer to play individual samples of changing audio waves in C#?
body: <p>I am writing a program that is supposed to imitate the "DCF77" signal to change the time of radio clocks.
  For that to work, I have to play a sound continuously (without cracking sounds; seamlessly) using changing waves (changing volume levels).</p>
  
  <p>I was told to use NAudio and a Buffer, which stores samples/1 sample, sends them/it to the sound card and requests more samples as needed.</p>
  
  <p>But how do I implement this?</p>
  
  <p>My current code has an array with 60 elements called bits, which is used to determine how the sound changes in every second.
  This array is recalculated once a minute.</p>
  
  <p>If you didn't know, the DCF77 Signal encodes binary information like this:
  A 0 means that the first 0.1 seconds of every second are at about 15% volume of the normal level.
  A 1 means the same, but for 0.2 seconds.</p>
  
  <p>Now, I have a SineWaveProvider32 class:</p>
  
  <pre><code>class SineWaveProvider32 : WaveProvider32
  {
      int sample;
  
      public SineWaveProvider32()
      {
          Frequency = 1000;
          Amplitude = 0.25f;
      }
  
      public float Frequency { get; set; }
      public float Amplitude { get; set; }
  
      public override int Read(float[] buffer, int offset, int sampleCount)
      {
          int sampleRate = WaveFormat.SampleRate;
  
          for(int i = 0; i &lt; sampleCount; i++)
          {
              buffer[i + offset] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate));
              sample++;
              if(sample &gt;= sampleRate)
              {
                  sample = 0;
              }
          }
  
          return sampleCount;
      }
  }
  </code></pre>
  
  <p>As well as a WaveOut object</p>
  
  <pre><code>WaveOut waveOut;
  </code></pre>
  
  <p>and the main code has this method:</p>
  
  <pre><code>void StartStopSineWave()
  {
      if (waveOut == null)
      {
          var sineWaveProvider = new SineWaveProvider32();
          sineWaveProvider.SetWaveFormat(192000, 1);
          sineWaveProvider.Frequency = 1000;
          sineWaveProvider.Amplitude = 0.25f;
          waveOut = new WaveOut();
          waveOut.Init(sineWaveProvider);
          waveOut.Play();
      }
      else
      {
          waveOut.Stop();
          waveOut.Dispose();
          waveOut = null;
      }
  }
  </code></pre>
  
  <p>Please note that I am relatively new to C#, and sorry if this is a duplicate question, but I couldn't find any useful information, or at least didn't understand it.</p>
  
  <p>Edit: For anyone who may have this same problem, I solved it by having a constant sine wave be output and changing the volume in real time using </p>
  
  <pre><code>waveOut.Volume
  </code></pre>
  
  <p>I know this is not perfect, but it works for what I'm doing.</p>