예제 #1
0
        public void AddSamples(AudioSampleBuffer buffer, int numSamples)
        {
            int ret;

            if ((ret = ffmpeg.av_audio_fifo_realloc(audioFifo, GetBufferSize() + numSamples)) < 0)
            {
                throw new FFmpegException(ret, "Failed to reallocate fifo buffer.");
            }
            if ((ret = ffmpeg.av_audio_fifo_write(audioFifo, (void **)buffer.sampleBuffer, numSamples)) < 0)
            {
                throw new FFmpegException(ret, "Failed to write data to fifo buffer");
            }
        }
예제 #2
0
        public void StoreFrameFromDecoder(AudioDecoder decoder, Resampler resampler = null)
        {
            AVFrame *         inputFrame      = null;
            AudioSampleBuffer buffer          = null;
            AudioSampleBuffer resampledBuffer = null;

            try
            {
                Util.InitInputFrame(&inputFrame);
                if (decoder.GetNextAudioFrame(inputFrame))
                {
                    buffer = new AudioSampleBuffer(inputFrame);
                    if (resampler != null)
                    {
                        resampler.Resample(buffer, out resampledBuffer, inputFrame->nb_samples);
                        AddSamples(resampledBuffer, inputFrame->nb_samples);
                    }
                    else
                    {
                        AddSamples(buffer, inputFrame->nb_samples);
                    }
                }
            }
            finally
            {
                if (buffer != null)
                {
                    buffer.Dispose();
                }
                if (resampledBuffer != null)
                {
                    resampledBuffer.Dispose();
                }
                ffmpeg.av_frame_free(&inputFrame);
            }
        }
예제 #3
0
 public void Resample(AudioSampleBuffer input, out AudioSampleBuffer output, int numSamples)
 {
     output = new AudioSampleBuffer(OutputSampleFormat, NumOutputChannels, numSamples);
     Resample(input.sampleBuffer, output.sampleBuffer, numSamples);
 }