Exemplo n.º 1
0
        /// <summary>
        /// Creates a new band filter.
        /// </summary>
        /// <param name="type">
        /// Type of the filter, it must be a band filter with a single cutoff frequency (not <see cref="FilterKind.AllPass"/>
        /// or another single cutoff frequency filter).
        /// </param>
        /// <param name="design">Designer used to build the filter (it must support creation of required filter).</param>
        /// <param name="settings">
        /// Settings for the filter (base class <see cref="FilterDesignSettings"/> may be used if you do not want to specify
        /// any of extra settings supported by designer for this specific type of filter).
        /// </param>
        /// <param name="band">Frequency band of this filter.</param>
        /// <returns>
        /// An on-line filter with specified type and characteristics.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="design"/> is <see langword="null"/>.
        /// <br/>-or-<br/>
        /// If <paramref name="settings"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If one of the frequencies is 0 or less or <see cref="Double.NaN"/> or <see cref="Double.PositiveInfinity"/>.
        /// <br/>-or-<br/>
        /// If <c>band.Minimum</c> is greater than <c>band.Maximum</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="type"/> is not a band filter.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// If specified <paramref name="design"/> does not support required filter <paramref name="type"/>.
        /// </exception>
        /// <exception cref="ArithmeticException">
        /// If filter cannot be designed as required (but parameters are all OK).
        /// </exception>
        public static IOnlineFilter Create(FilterKind type, OnlineFilterDesigner design, FilterDesignSettings settings, Range <double> band)
        {
            ValidateSettingsWithDesigner(design, settings);
            ValidateFrequency(band.Minimum);
            ValidateFrequency(band.Maximum);

            if (band.Maximum < band.Minimum)
            {
                throw new ArgumentOutOfRangeException("band");
            }

            if (type == FilterKind.BandPass)
            {
                return(design.CreateBandPass(settings, band.Minimum, band.Maximum));
            }
            else if (type == FilterKind.BandStop)
            {
                return(design.CreateBandPass(settings, band.Minimum, band.Maximum));
            }
            else if (type == FilterKind.AllPass)
            {
                return(design.CreateAllPass(settings, band.Minimum, band.Maximum));
            }

            throw new ArgumentException("This overload can be used only to create band filters.", "type");
        }
Exemplo n.º 2
0
        /// <overload>
        /// Creates a new filter.
        /// </overload>
        /// <summary>
        /// Creates a new all-pass filter or a designer specific filter.
        /// </summary>
        /// <param name="type">Type of the filter, it must be <see cref="FilterKind.AllPass"/>.</param>
        /// <param name="design">Designer used to build the filter (it must support creation of an all-pass filter).</param>
        /// <param name="settings">
        /// Settings for the filter (base class <see cref="FilterDesignSettings"/> may be used if you do not want to specify
        /// any of extra settings supported by designer for this specific type of filter).
        /// </param>
        /// <returns>
        /// An on-line filter with specified type and characteristics.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="design"/> is <see langword="null"/>.
        /// <br/>-or-<br/>
        /// If <paramref name="settings"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="type"/> is not <see cref="FilterKind.AllPass"/> or <see cref="FilterKind.Other"/>.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// If specified <paramref name="design"/> does not support required filter <paramref name="type"/>.
        /// </exception>
        /// <exception cref="ArithmeticException">
        /// If filter cannot be designed as required (but parameters are all OK).
        /// </exception>
        public static IOnlineFilter Create(FilterKind type, OnlineFilterDesigner design, FilterDesignSettings settings)
        {
            ValidateSettingsWithDesigner(design, settings);

            if (type == FilterKind.Other)
            {
                return(design.CreateOther(settings));
            }

            if (type == FilterKind.AllPass)
            {
                return(design.CreateAllPass(settings, 0.0, settings.SamplingRate / 2));
            }

            throw new ArgumentException("This overload can be used only to create all pass/other filters.", "type");
        }