The NotifyingSampleProvider class notifies also on non read samples because it uses the "sampleCount" variable which is the size of the incoming buffer. However the amount of bytes read may be smaller than the destination buffer! So the samplesRead variable should be used.
Wrong code:
public int Read(float[] buffer, int offset, int sampleCount)
{
int samplesRead = source.Read(buffer, offset, sampleCount);
if (Sample != null)
{
for (int n = 0; n < sampleCount; n += channels)
{
sampleArgs.Left = buffer[offset + n];
sampleArgs.Right = channels > 1 ? buffer[offset + n + 1] : sampleArgs.Left;
Sample(this, sampleArgs);
}
}
return samplesRead;
}
Right code:
public int Read(float[] buffer, int offset, int sampleCount)
{
int samplesRead = source.Read(buffer, offset, sampleCount);
if (Sample != null)
{
for (int n = 0; n < samplesRead ; n += channels)
{
sampleArgs.Left = buffer[offset + n];
sampleArgs.Right = channels > 1 ? buffer[offset + n + 1] : sampleArgs.Left;
Sample(this, sampleArgs);
}
}
return samplesRead;
}
Comments: good spot, have checked in a fix
Wrong code:
public int Read(float[] buffer, int offset, int sampleCount)
{
int samplesRead = source.Read(buffer, offset, sampleCount);
if (Sample != null)
{
for (int n = 0; n < sampleCount; n += channels)
{
sampleArgs.Left = buffer[offset + n];
sampleArgs.Right = channels > 1 ? buffer[offset + n + 1] : sampleArgs.Left;
Sample(this, sampleArgs);
}
}
return samplesRead;
}
Right code:
public int Read(float[] buffer, int offset, int sampleCount)
{
int samplesRead = source.Read(buffer, offset, sampleCount);
if (Sample != null)
{
for (int n = 0; n < samplesRead ; n += channels)
{
sampleArgs.Left = buffer[offset + n];
sampleArgs.Right = channels > 1 ? buffer[offset + n + 1] : sampleArgs.Left;
Sample(this, sampleArgs);
}
}
return samplesRead;
}
Comments: good spot, have checked in a fix