private void LoadFile(string filename) { WaveFile wav = new WaveFile(filename); int chunkSize = (int)(chunkTimeLength.TotalSeconds * wav.SamplesPerSecond); SampleRetriever retr = new SampleRetriever(new WavefileSampleSource(wav), chunkSize); retr.SamplesRetrievingDone += new EventHandler(retr_SamplesRetrievingDone); long fromSample, toSample; if (numFromSample.Value < 0) { fromSample = 0; } else { fromSample = (long)numFromSample.Value * retr.SampleSource.SampleCount / retr.SampleSource.SamplesPerSecond; } if (numToSample.Value < 0) { toSample = -1; } else { toSample = (long)numToSample.Value * retr.SampleSource.SampleCount / retr.SampleSource.SamplesPerSecond; } sampleDisplayer1.Fill(retr, fromSample, toSample); }
/// <summary> /// Sets sample /// </summary> /// <param name="samples"></param> /// <param name="samplesPerSecond"></param> /// <param name="beginSample"> /// First sample to be shown. Default 0 /// </param> /// <param name="endSample"> /// Last+1 sample to be shown. /// -1 to be until last sample, /// default -1 /// (If set to 10, samples up to 9 will be considered. /// Concept stolen from C++ stl. ) /// </param> public void Fill(SampleRetriever sampleRetriever, long startPos, long endPos) { pictureGraph.DatalessColor = Color.PowderBlue; pictureFFT.Image = new Bitmap(pictureFFT.Width, pictureFFT.Height); using (Graphics g = Graphics.FromImage(pictureFFT.Image)) { g.FillRectangle(new SolidBrush(pictureGraph.DatalessColor), 0, 0, pictureFFT.Width, pictureFFT.Height); } // bufferedFFTImage = SetToColor(pictureFFT, Color.PowderBlue); this.sampleRetriever = sampleRetriever; this.samplePos = 0; this.sampleRetriever.BeginSample = startPos; this.sampleRetriever.EndSample = endPos; this.maxSampleValue = 0.0; this.sampleCollector = new SampleCollector(this.sampleRetriever); this.aggregator = new SampleAggregator(this.sampleCollector); pictureGraph.Count = (int)this.sampleCollector.ExpectedCount; this.aggregator.SamplesRetreived += new SampleRetriever.SamplesRetrievedDelegate(samplesAggregated); this.sampleCollector.SamplesRetreived += new SampleRetriever.SamplesRetrievedDelegate(samplesCollector_Retrieved); this.sampleCollector.SamplesRetrievingDone += new EventHandler(sampleCollector_SamplesRetrievingDone); this.sampleRetriever.Start(); }
public SampleCollector(SampleRetriever retriever) { this.retriever = retriever; this.sampleSize = 5 * retriever.SampleSource.SamplesPerSecond; this.retriever.SamplesRetrieved += new SampleRetriever.SamplesRetrievedDelegate(retriever_SamplesRetrieved); this.retriever.SamplesRetrievingDone += new EventHandler(retriever_SamplesRetrievingDone); this.sampleBuilder = new SampleBuilder(); }
private void load_fft(SampleRetriever sender, double[] samples, long samplePos) { while (fftJobs.Count > 5 && !fftThreadTerminate) { System.Threading.Thread.Sleep(500); } if (fftThreadTerminate) { return; } fftBuilder.Add(samples); long limit = sender.SampleSource.SampleCount / splitIntoNumberOfParts; if (fftBuilder.Count < limit) { return; } int timeslotNumber = (int)((samplePos + samples.Length) / limit); double[] data = fftBuilder.ToArray(); fftBuilder.Clear(); double y_limit = FFTAmplitudeMin * sampleRetriever.SampleSource.MaxSampleValue; int sampleRate = sampleRetriever.SampleSource.SamplesPerSecond; fftJobs.Push(new FFTJob(data, y_limit, timeslotNumber, sampleRate)); if (fftThread == null) { fftThread = new System.Threading.Thread(new System.Threading.ThreadStart(FFTTheadMain)); fftThread.Start(); } //System.Threading.ThreadPool.QueueUserWorkItem( new System.Threading.WaitCallback(PerformFFT), new Object[] { data, y_limit, timeslotNumber, sampleRate } ); }