예제 #1
0
        public void Encode(ReadOnlySpan <byte> pcm, ref Span <byte> target)
        {
            if (pcm.Length != target.Length)
            {
                throw new ArgumentException("PCM and Opus buffer lengths need to be equal.", nameof(target));
            }

            var duration   = AudioFormat.CalculateSampleDuration(pcm.Length);
            var frameSize  = AudioFormat.CalculateFrameSize(duration);
            var sampleSize = AudioFormat.CalculateSampleSize(duration);

            if (pcm.Length != sampleSize)
            {
                throw new ArgumentException("Invalid PCM sample size.", nameof(target));
            }

            Interop.OpusEncode(Encoder, pcm, frameSize, ref target);
        }