Example #1
0
        /// <summary>
        /// Creates a new resampler with the supplied quality parameters.
        ///
        /// Can be used to create a variable-rate resampler by supplying SOXR_HQ as recipe
        /// and SOXR_VR as flag. For a variable resampler, inputRate/outputRate must equate
        /// to the maximum IO ratio that will be set by calling SetRatio. To set the initial
        /// ratio, call SetRatio with a transitionLength of 0 on the created instance.
        /// </summary>
        /// <param name="inputRate"></param>
        /// <param name="outputRate"></param>
        /// <param name="channels"></param>
        /// <param name="qualityRecipe"></param>
        /// <param name="qualityFlags"></param>
        /// <exception cref="SoxrException">when parameters are incorrect; see error message for details</exception>
        public SoxResampler(double inputRate, double outputRate, int channels,
                            QualityRecipe qualityRecipe, QualityFlags qualityFlags)
        {
            if (inputRate <= 0 || outputRate <= 0 || channels <= 0)
            {
                throw new SoxrException("one or more parameters are invalid (zero or negative)");
            }

            SoxrError error = SoxrError.Zero;

            // Apply the default configuration as per soxr.c
            InteropWrapper.SoxrIoSpec      ioSpec = InteropWrapper.soxr_io_spec(Datatype.SOXR_FLOAT32_I, Datatype.SOXR_FLOAT32_I);
            InteropWrapper.SoxrQualitySpec qSpec  = InteropWrapper.soxr_quality_spec(qualityRecipe, qualityFlags);
            InteropWrapper.SoxrRuntimeSpec rtSpec = InteropWrapper.soxr_runtime_spec(1);

            if (qualityFlags == QualityFlags.SOXR_VR)
            {
                if (qualityRecipe != QualityRecipe.SOXR_HQ)
                {
                    throw new SoxrException("Invalid parameters: variable rate resampling only works with the HQ recipe");
                }
                variableRate = true;
                maxRatio     = inputRate / outputRate;
            }

            soxr = InteropWrapper.soxr_create(inputRate, outputRate, (uint)channels,
                                              out error, ref ioSpec, ref qSpec, ref rtSpec);

            if (error != SoxrError.Zero)
            {
                throw new SoxrException(GetError(error));
            }

            this.channels = channels;
        }
Example #2
0
 public static extern SoxrInstance soxr_create(double input_rate, double output_rate, uint num_channels,
                                               out SoxrError error, ref InteropWrapper.SoxrIoSpec io_spec, ref InteropWrapper.SoxrQualitySpec quality_spec, ref InteropWrapper.SoxrRuntimeSpec runtime_spec);