예제 #1
0
 /// <summary>
 /// Function creates a new linear-phase resampler object
 /// </summary>
 ///
 /// <param name="srcSampleRate">Source signal sample rate. Both sample rates can be
 /// specified as a ratio, e.g. SrcSampleRate = 1.0, DstSampleRate = 2.0.</param>
 ///
 /// <param name="dstSampleRate">Destination signal sample rate</param>
 ///
 /// <param name="maxInputBufferLength">The maximal planned length of the input buffer (in samples)
 /// that will be passed to the resampler. The resampler relies on this value as
 /// it allocates intermediate buffers. Input buffers longer than this value
 /// should never be supplied to the resampler. Note that the resampler may use
 /// the input buffer itself for intermediate sample data storage.</param>
 ///
 /// <param name="reqTransBand">Required transition band, in percent of the
 /// spectral space of the input signal (or the output signal if
 /// downsampling is performed) between filter's -3 dB point and the Nyquist
 /// frequency. The range is from CDSPFIRFilter::getLPMinTransBand() to
 /// CDSPFIRFilter::getLPMaxTransBand(), inclusive. When upsampling 88200 or
 /// 96000 audio to a higher sample rates the ReqTransBand can be
 /// considerably increased, up to 30. The selection of ReqTransBand depends
 /// on the level of desire to preserve the high-frequency content. While
 /// values 0.5 to 2 are extremely "greedy" settings, not necessary in most
 /// cases, values 2 to 3 can be used in most cases. Values 3 to 4 are
 /// relaxed settings, but they still offer a flat frequency response up to
 /// 21kHz with 44.1k source or destination sample rate.</param>
 ///
 /// <param name="resolution">Resampler's required resolution</param>
 public R8BrainSampleRateConverter(double srcSampleRate,
                                   double dstSampleRate,
                                   int maxInputBufferLength,
                                   double reqTransBand,
                                   R8BrainResamplerResolution resolution)
 {
     FUnmanagedInstance      = R8BrainDLLWrapper.Create(srcSampleRate, dstSampleRate, maxInputBufferLength, reqTransBand, resolution);
     FSourcRate              = srcSampleRate;
     FDestinationRate        = dstSampleRate;
     FRequiredTransitionBand = reqTransBand;
 }
예제 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // Free other state (managed objects).
                }

                // Free your own state (unmanaged objects).
                // Set large fields to null.
                R8BrainDLLWrapper.Delete(FUnmanagedInstance);
                disposed = true;
            }
        }
예제 #3
0
        /// <summary>
        /// Function performs sample rate conversion.
        /// If the source and destination sample rates are equal, the resampler will do
        /// nothing and will simply return the input buffer unchanged.
        ///
        /// You do not need to allocate an intermediate output buffer for use with this
        /// function. If required, the resampler will allocate a suitable intermediate
        /// output buffer itself.
        /// </summary>
        ///
        /// <param name="input">Input buffer. This buffer may be used as output buffer by this function.</param>
        ///
        /// <param name="output">This variable receives the pointer to the resampled data.
        /// This pointer may point to the address within the "ip0" input buffer, or to
        /// *this object's internal buffer. In real-time applications it is suggested
        /// to pass this pointer to the next output audio block and consume any data
        /// left from the previous output audio block first before calling the
        /// process() function again. The buffer pointed to by the "op0" on return may
        /// be owned by the resampler, so it should not be freed by the caller.</param>
        ///
        /// <returns>The number of samples available in the output buffer. If the
        /// data from the output buffer is going to be written to a bigger output
        /// buffer, it is suggested to check the returned number of samples so that no
        /// overflow of the bigger output buffer happens.</returns>
        public int Process(double[] input, ref double[] output)
        {
            //pin the input during process
            var pinnedHandle = GCHandle.Alloc(input, GCHandleType.Pinned);

            //resample
            var outSamples = R8BrainDLLWrapper.Process(FUnmanagedInstance, pinnedHandle.AddrOfPinnedObject(), input.Length, out FOutBufferPtr);

            //copy to output array
            if (output.Length < outSamples)
            {
                output = new double[outSamples];
            }

            Marshal.Copy(FOutBufferPtr, output, 0, outSamples);

            //free pin
            pinnedHandle.Free();

            return(outSamples);
        }
예제 #4
0
 /// <summary>
 /// Function clears (resets) the state of the resampler object and returns it
 /// to the state after construction. All input data accumulated in the
 /// internal buffer of this resampler object so far will be discarded.
 /// </summary>
 public void Clear()
 {
     R8BrainDLLWrapper.Clear(FUnmanagedInstance);
 }