// Handles the subscriber's NewMeasurements event. private void DataSubscriber_NewMeasurements(object sender, EventArgs <ICollection <IMeasurement> > e) { // Gather statistics. Interlocked.Add(ref m_measurementCount, e.Argument.Count); // Queue the measurements up in the buffer. foreach (IMeasurement measurement in e.Argument) { if (m_channelIndexes.ContainsKey(measurement.ID)) { // Perform a rough per signal upsample if minimum sample rate is not met if (m_sampleRate < MINIMUM_SAMPLE_RATE) { IMeasurement upsampledMeasurement; double frequency = measurement.Value; for (int i = 0; i < MINIMUM_SAMPLE_RATE / m_sampleRate; i++) { upsampledMeasurement = Measurement.Clone(measurement); upsampledMeasurement.Value = Timbre.PureTone(frequency, i, 0, MINIMUM_SAMPLE_RATE) * Damping.Natural(i, MINIMUM_SAMPLE_RATE / m_sampleRate, MINIMUM_SAMPLE_RATE) * (Int16.MaxValue * 0.90D); m_buffer.Enqueue(upsampledMeasurement); } } else { m_buffer.Enqueue(measurement); } } } // If we've managed to buffer a full second of data, // stop the timeout timer and start the dump timer. // The dump timer is sending measurements to the sound card // so change the playback state to playing. if (m_dumpTimer != null && !m_dumpTimer.IsRunning && m_buffer.Count / 2 > m_sampleRate) { if (m_timeoutTimer != null) { m_timeoutTimer.Stop(); } m_dumpTimer.Start(); OnStateChanged(PlaybackState.Playing); } }
// Static Methods /// <summary> /// Computes a dual-tone multi-frequency sound for the given <see cref="DTMF"/> information and time. /// </summary> /// <param name="tone">Instance of the <see cref="DTMF"/> specifying the duration as well as the low and high frequencies of the dual-tone.</param> /// <param name="sampleIndex">Sample index (represents time anywhere from zero to full length of tone).</param> /// <param name="sampleRate">Number of samples per second.</param> /// <returns>The amplitude for the dual-tone at the given time.</returns> /// <remarks> /// This method computes an amplitude representing the acoustic pressure of a /// <see cref="DTMF"/> of the given frequency for the given time. /// </remarks> public static double ComputeFrequencies(DTMF tone, long sampleIndex, int sampleRate) { return((Timbre.PureTone(tone.LowFrequency, sampleIndex, 0, sampleRate) + Timbre.PureTone(tone.HighFrequency, sampleIndex, 0, sampleRate)) / 2); }