Beispiel #1
0
        public override void Convert(AudioFrame inFrame, AudioFrame outFrame)
        {
            if (kernelCount > 1 && kernelCount != inFrame.format.Channels)
            {
                throw new ArgumentException($"{nameof(inFrame)}的数据行数和卷积核个数不一致", nameof(inFrame));
            }

            var inFormat   = inFrame.format;
            var inSamples  = inFrame.sampleCount;
            var outSamples = convs[0].GetOutLength(inSamples);
            var outFormat  = inFormat;

            if (resampler == null && inFormat.SampleFormat != AVSampleFormat.DoublePlanar)
            {
                outFormat = new AudioFormat(inFormat.SampleRate, inFormat.ChannelLayout, inFormat.SampleFormat.ToPlanar());
                resampler = new AudioResampler(inFormat, outFormat);
            }
            if (resampler != null)
            {
                resampler.Resample(inFrame, tempInput);
                inFrame = tempInput;
            }

            outFrame.Resize(outFormat, outSamples);

            for (int i = 0; i < kernelCount; i++)
            {
                convs[kernelCount == 1 ? 0 : i].Convolve((double *)inFrame.datas[i], inSamples, (double *)outFrame.datas[i], outSamples);
            }
        }
Beispiel #2
0
        public static void Merge(AudioFrame outFrame, params AudioFrame[] inFrames)
        {
            if (inFrames.Length == 0)
            {
                return;
            }
            var format = inFrames[0].format;

            for (int i = 1; i < inFrames.Length; i++)
            {
                if (format != inFrames[i].format)
                {
                    throw new ArgumentException($"{nameof(inFrames)}的所有元素的{nameof(Format)}必须一致", nameof(inFrames));
                }
            }

            int outSampleCount = inFrames.Sum(frame => frame.sampleCount);

            outFrame.format = format;
            outFrame.Resize(outSampleCount);

            int offset = 0;

            for (int i = 0; i < inFrames.Length; i++)
            {
                FF.av_samples_copy(outFrame.datas, inFrames[i].datas, offset, 0, inFrames[i].sampleCount, format.Channels, format.SampleFormat);
                offset += inFrames[i].sampleCount;
            }
        }
        public static void ToPlanar(AudioFrame inOutFrame)
        {
            AudioResampler resampler = GetPlanarResampler(inOutFrame.format);

            if (resampler == null)
            {
                return;
            }

            var samples = inOutFrame.SampleCount;
            int bytes   = resampler.GetOutBytes(samples);

            packedCache.Resize(bytes);
            var data = packedCache.data;

            Buffer.MemoryCopy((void *)inOutFrame.datas[0], (void *)data, bytes, bytes);
            int lineBytes = resampler.Destination.GetLineBytes(samples);

            inOutFrame.format = resampler.Destination;
            inOutFrame.Resize(samples);
            fixed(IntPtr *input = inOutFrame.datas)
            {
                resampler.Resample((IntPtr)(&data), samples, (IntPtr)input, samples);
            }

            inOutFrame.sampleCount = samples;
        }
        public void ResampleFinal(AudioFrame outFrame)
        {
            int outSamples = GetOutSampleCount(0);

            outFrame.format = Destination;
            outFrame.Resize(outSamples);
            outSamples           = Resample(null, 0, outFrame.datas, outSamples);
            outFrame.sampleCount = outSamples;
        }
        internal void InternalResample(AudioFrame frame)
        {
            int inSamples  = frame.frame->NbSamples;
            int outSamples = GetOutSampleCount(inSamples);

            frame.format = Destination;
            frame.Resize(outSamples);
            fixed(IntPtr *output = frame.datas)
            {
                outSamples = Resample((IntPtr)frame.frame->ExtendedData, inSamples, (IntPtr)output, outSamples);
            }

            frame.sampleCount = outSamples;
        }
        public void Resample(AudioFrame inFrame, AudioFrame outFrame)
        {
            if (inFrame == null)
            {
                ResampleFinal(outFrame);
                return;
            }

            if (!Source.Equals(inFrame.format))
            {
                throw new ArgumentException("输入帧的格式和重采样器的源格式不一致", nameof(inFrame));
            }

            int inSamples  = inFrame.SampleCount;
            int outSamples = GetOutSampleCount(inSamples);

            outFrame.format = Destination;
            outFrame.Resize(outSamples);
            outSamples           = Resample(inFrame.datas, inSamples, outFrame.datas, outSamples);
            outFrame.sampleCount = outSamples;
        }
Beispiel #7
0
 public void CopyTo(int srcSampleOffset, int srcSampleCount, AudioFrame dstFrame)
 {
     dstFrame.Resize(format, srcSampleCount);
     FF.av_samples_copy(dstFrame.datas, datas, 0, srcSampleOffset, srcSampleCount, format.Channels, format.SampleFormat);
 }