public int Read(float[] data, int offset, int count) { int samplesRemaining = count; while (samplesRemaining > 0) { int samplesRequested = Math.Min(BUFFER_SIZE, samplesRemaining); int samplesRead = stream.Read(buffer, 0, samplesRequested); if (samplesRead <= 0) { break; } for (int i = 0; i < samplesRead; i++) { data[offset + i] = (float)buffer[i].Real; } samplesRemaining -= samplesRead; offset += samplesRead; } return(count - samplesRemaining); }
/// <summary> Slowest Backup Alternative for calculating RMS </summary> public static double CalculateRMS(this IAnalyticStream stream) { if (stream.Samples == 0) { return(0.0); } if (stream.Samples == int.MaxValue) { return(double.NaN); } double rms = 0.0; int readSamples; const int BUFFER_SIZE = 512; Complex64[] buffer = new Complex64[BUFFER_SIZE]; stream.Reset(); do { readSamples = stream.Read(buffer, 0, BUFFER_SIZE); for (int i = 0; i < readSamples; i++) { rms += buffer[i].Real * buffer[i].Real; } }while (readSamples > 0); stream.Reset(); return(Math.Sqrt(rms / stream.Samples)); }