public static StereoWaveFile OpenWave(string filename) { var wav = new StereoWaveFile(); var buffer = new byte[HEADER_SIZE]; wav.fs = File.OpenRead(filename); // Read the WAV header. wav.fs.Read(buffer, 0, 44); int offset = 0; byte[] arr2b = new byte[2]; byte[] arr4b = new byte[4]; wav.ChunkId = Encoding.ASCII.GetString(buffer, offset, 4); wav.ChunkSize = BitConverter.ToInt32(buffer, offset += 4); wav.Format = Encoding.ASCII.GetString(buffer, offset += 4, 4); wav.Subchunk1ID = Encoding.ASCII.GetString(buffer, offset += 4, 4); wav.Subchunk1Size = BitConverter.ToInt32(buffer, offset += 4); // 16 for PCM wav.AudioFormat = BitConverter.ToInt16(buffer, offset += 4); // PCM = 1 (Linear Quantization); wav.NumChannels = BitConverter.ToInt16(buffer, offset += 2); wav.SampleRate = BitConverter.ToInt32(buffer, offset += 2); wav.ByteRate = BitConverter.ToInt32(buffer, offset += 4); // SampleRate * NumChannels * BitsPerSample/8 wav.BlockAlign = BitConverter.ToInt16(buffer, offset += 4); // NumChannels * BitsPerSample/8 wav.BitsPerSample = BitConverter.ToInt16(buffer, offset += 2); wav.Subchunk2ID = Encoding.ASCII.GetString(buffer, offset += 2, 4); offset += 4; wav.Subchunk2Size = BitConverter.ToInt32(buffer, offset); wav.sampleBuffer = new byte[wav.BlockAlign]; return(wav); }
static void SampleAverageMain(string[] args) { int sleft, sright; var wav = StereoWaveFile.OpenWave(@"SDR_Sharp\SDRSharp_20160607_155903Z_315030000Hz_IQ.wav"); //var state = new SignalState(); int maxLeft = int.MinValue, maxRight = int.MinValue; float avgLeft = 0, avgRight = 0; int avgCount = 0; long cnt = 0; while (!wav.EOF) { wav.readSample(out sleft, out sright); if (sleft > maxLeft) { maxLeft = sleft; } if (sright > maxRight) { maxRight = sright; } avgCount++; avgLeft = ((avgLeft * avgCount - 1) + sleft) / avgCount; avgRight = ((avgRight * avgCount) + sright) / avgCount; //if(state.AddSample(sleft)) { //Console.WriteLine("State Changed @ Sample {0} - Time: {1} - {2} - {3}", cnt, (float)cnt / (float)wav.SampleRate, Math.Round(state.lastRMS,4), Math.Round(state.lastAvgRMS,4)); //Console.WriteLine("State Changed @ Sample {0} - Time: {1} - {2} - {3} - {4}- {5} - {6}", cnt, (float)cnt / (float)wav.SampleRate, Math.Round(state.maxSample,4), Math.Round(state.minSample,4), state.waveMaxAverage, state.waveMinAverage, state.waveSampleCount); } cnt++; if (cnt % 1000000 == 0) { Console.WriteLine("{0}/{1} - {2}%", wav.getFilePosition(), wav.getFileLength(), Math.Round(((float)wav.getFilePosition() / (float)wav.getFileLength()) * 100, 2)); } } Console.WriteLine("L: Max: {0}, Avg: {1}", maxLeft, avgLeft); Console.WriteLine("R: Max: {0}, Avg: {1}", maxRight, avgRight); Console.ReadLine(); }
static void Main(string[] args) { int sleft, sright; var wav = StereoWaveFile.OpenWave(@"E:\SDR_Sharp\SDRSharp_20160607_155817Z_315030000Hz_IQ.wav"); //var state = new SignalState(); Filters.AnalogRMS <int> filterRMS = new Filters.AnalogRMS <int>() { RMSListSize = 500 }; Filters.ThresholdTrigger <double> filterTrigger = new Filters.ThresholdTrigger <double>() { Threshold = 5000, Tolerance = 500 }; long scount = 0; while (!wav.EOF) { wav.readSample(out sleft, out sright); filterRMS.SampleInput(sleft, scount); if (filterRMS.HasOutput) { var rmsOut = filterRMS.SampleOutput(); if (scount % 1000000 == 0) { Console.WriteLine("Sample {0} - RMS Out: {1}", scount, rmsOut.value); } filterTrigger.SampleInput(rmsOut); if (filterTrigger.HasOutput) { //Console.WriteLine("Sample {0} - TRIGGER ALERT: {1} - {2}", scount, filterTrigger.SampleOutput().value, rmsOut.value); } } scount++; } Sample <bool> firstOfSet = null; int stateCount = 0; Sample <bool> s1 = null, s2 = null; while (filterTrigger.HasOutput) { s2 = filterTrigger.SampleOutput(); if (firstOfSet == null) { firstOfSet = s2; } if (s1 != null) { if (s2.TimeOffset - s1.TimeOffset > 5000) { Console.WriteLine("Burst Time Span: {0}", (double)(s2.TimeOffset - firstOfSet.TimeOffset) / (double)wav.SampleRate); Console.WriteLine("Time Span: {0} - {1}", (double)firstOfSet.TimeOffset / (double)wav.SampleRate, (double)s2.TimeOffset / (double)wav.SampleRate); Console.WriteLine("Pulse Count: {0}", stateCount); firstOfSet = null; stateCount = 0; } else { stateCount++; } } s1 = s2; } Console.ReadLine(); }