public void Analyze(ChannelData data) { if (data == null || data.Samples.Length == 0) { return; } maxValue = data.RefValue; totalSamples = data.Samples.Length; nonZeroSamples = 0; Int32 s; for (Int32 i = 0; i < totalSamples; i++) { s = data.Samples[i]; avg = ((avg * i) + s) / (i + 1); rms += (((double)s) * s); if (s == 0) { zeroSamples++; continue; } avgNonZero = ((avgNonZero * nonZeroSamples) + s) / (nonZeroSamples + 1); nonZeroSamples++; if (s < 0) { if (min == 0 || (s < min)) { min = s; } } else { if (max == 0 || (s > max)) { max = s; } } } rms = Math.Sqrt(rms / totalSamples); zeroSamplesPct = ((double)zeroSamples) / totalSamples; nonZeroSamplesPct = ((double)nonZeroSamples) / totalSamples; }
private void ReadDataChunk(BinaryReader br, Int32 size) { BytesPerSample = Format.AvgBytesPerSec / (Format.Channels * Format.SamplesPerSec); Samples = size / (BytesPerSample * Format.Channels); Duration = (double)Samples / Format.SamplesPerSec; Channels = new ChannelData[Format.Channels]; negativeMask = 0; for (int i = 0; i < (32 - Format.BitsPerSample); i++) { negativeMask = (negativeMask << 1) | 1; } for (int i = 0; i < Format.BitsPerSample; i++) { negativeMask = (negativeMask << 1) | 0; } for (int c = 0; c < Format.Channels; c++) { Channels[c] = new ChannelData(Format, Samples); Channels[c].Name = "Channel " + c; } PctRead = 0; CastPctReadUpdate(); int deltaPctUpd = Samples / 100; for (int s = 0; s < Samples; s++) { if (s % deltaPctUpd == 0) { PctRead = s / deltaPctUpd; CastPctReadUpdate(); } for (int channel = 0; channel < Format.Channels; channel++) { Channels[channel].Samples[s] = ReadSample(br); } } }