Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's much more advisable to use NAudio's <code>BufferedWaveProvider</code> instead of the whole reset event / queue. It was designed for scenarios like these. </p> <p>You will encounter breaks when the player's buffer runs out abruptly - the data is not streamed fast enough.</p> <p>Secondly, let me clear up the function signature:</p> <p><code>int Read(float[] buffer, int offset, int sampleCount)</code></p> <p>You will be supplied with a buffer, an offset in the buffer, and a chunk size. The value you returned indicates the number of items you could supply for this Read operation. You are <strong>not required</strong> to supply an exact number of bytes as corresponds to the samples requested.</p> <p>So if you wanted to supply silence, don't construct and return a buffer of zeros, and instead simply return 0 as the read length.</p> <p>Finally, if you don't want an abrupt cut off, you can slowly decrease the amplitude of the last set of samples - it can be as simple as multiplying by <code>(N - n) / N</code> (n ϵ [0, N]). Cut off due to a buffer underrun is an entirely different issue. </p> <p><strong>N.B.</strong></p> <p>Let me add that your present solution is a not a good way to do this in production. Using a lot of objects in between will eventually lead to a lot of latency issues when garbage collection comes knocking. Mark Heath, the author of NAudio, has used a lot of tricks to minimize Garbage collection, like reusing buffers, EventArgs and the like, so it would be unjust if it went to waste.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload