예제 #1
0
        protected unsafe void ResampleStream(ReadOnlySpan <float> samples, Span <float> output, int channel, bool last, out int inputSamplesUsed, out int outputSamplesUsed)
        {
            if (handles[channel] == IntPtr.Zero)
            {
                throw new ObjectDisposedException(nameof(handles));
            }

            int processedSamples;
            int sampleBufferUsed;

            fixed(float *samplePtr = samples)
            fixed(float *outputPtr = output)
            {
                processedSamples = LibResampleAPI.resample_process(handles[channel],
                                                                   factor,
                                                                   samplePtr,
                                                                   samples.Length,
                                                                   last ? 1 : 0,
                                                                   out sampleBufferUsed,
                                                                   outputPtr,
                                                                   output.Length);
            }

            inputSamplesUsed  = Math.Max(sampleBufferUsed, 0);
            outputSamplesUsed = Math.Max(processedSamples, 0);
        }
예제 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                for (int i = 0; i < Channels; i++)
                {
                    LibResampleAPI.resample_close(handles[i]);
                    handles[i] = IntPtr.Zero;
                }

                disposed = true;
            }
        }
예제 #3
0
        public LibResampler(int originalRate, int newRate, int channels)
        {
            SampleRate = newRate;
            Channels   = channels;

            factor = SampleRate / (double)originalRate;

            handles = new IntPtr[Channels];

            for (int i = 0; i < Channels; i++)
            {
                handles[i] = LibResampleAPI.resample_open(1, factor, factor);
            }
        }