ComputeFrequencies() публичный статический Метод

Computes a dual-tone multi-frequency sound for the given DTMF information and time.
This method computes an amplitude representing the acoustic pressure of a DTMF of the given frequency for the given time.
public static ComputeFrequencies ( DTMF tone, long sampleIndex, int sampleRate ) : double
tone DTMF Instance of the specifying the duration as well as the low and high frequencies of the dual-tone.
sampleIndex long Sample index (represents time anywhere from zero to full length of tone).
sampleRate int Number of samples per second.
Результат double
Пример #1
0
        /// <summary>
        /// Generates the specified dual-tone multi-frequencies <paramref name="repeatCount"/> times storing them in the specified <see cref="WaveFile"/>.
        /// </summary>
        /// <param name="destination"><see cref="WaveFile"/> used to store generated dual-tone multi-frequencies.</param>
        /// <param name="tones">Dual-tone multi-frequencies to generate.</param>
        /// <param name="volume">Volume of generated dual-tones as a percentage (0 to 1).</param>
        /// <param name="repeatCount">Number of times to repeat each tone.</param>
        /// <exception cref="ArgumentOutOfRangeException">Value must be expressed as a fractional percentage between zero and one.</exception>
        /// <exception cref="InvalidOperationException"><see cref="DTMF"/> only generated for <see cref="WaveFile"/> with a sample rate of 8, 16, 24, 32 or 64 bits per sample.</exception>
        public static void Generate(WaveFile destination, DTMF[] tones, double volume, int repeatCount)
        {
            if (volume < 0.0D || volume > 1.0D)
            {
                throw new ArgumentOutOfRangeException("volume", "Value must be expressed as a fractional percentage between zero and one");
            }

            double amplitude = destination.AmplitudeScalar * volume;

            // Iterate through each repeat count
            for (int x = 0; x < repeatCount; x++)
            {
                // Interate through each tone
                foreach (DTMF tone in tones)
                {
                    // Iterate through each sample for total DTMF duration
                    for (long y = 0; y < tone.Duration * destination.SampleRate; y++)
                    {
                        // Compute frequencies of DTMF at given time and add to wave file
                        destination.AddSample(DTMF.ComputeFrequencies(tone, y, destination.SampleRate) * amplitude);
                    }
                }
            }
        }