Exemplo n.º 1
0
        /// <summary> Creates a new Opus encoder. </summary>
        /// <param name="samplingRate">Sampling rate of the input signal (Hz). Supported Values:  8000, 12000, 16000, 24000, or 48000.</param>
        /// <param name="channels">Number of channels (1 or 2) in input signal.</param>
        /// <param name="frameLength">Length, in milliseconds, that each frame takes. Supported Values: 2.5, 5, 10, 20, 40, 60</param>
        /// <param name="application">Coding mode.</param>
        /// <returns>A new <c>OpusEncoder</c></returns>
        public OpusEncoder(int samplingRate, int channels, int frameLength, Opus.Application application)
        {
            if (samplingRate != 8000 && samplingRate != 12000 &&
                samplingRate != 16000 && samplingRate != 24000 &&
                samplingRate != 48000)
            {
                throw new ArgumentOutOfRangeException(nameof(samplingRate));
            }
            if (channels != 1 && channels != 2)
            {
                throw new ArgumentOutOfRangeException(nameof(channels));
            }

            InputSamplingRate = samplingRate;
            InputChannels     = channels;
            Application       = application;
            FrameLength       = frameLength;
            SampleSize        = (BitRate / 8) * channels;
            SamplesPerFrame   = samplingRate / 1000 * FrameLength;
            FrameSize         = SamplesPerFrame * SampleSize;

            Opus.Error error;
            _ptr = Opus.CreateEncoder(samplingRate, channels, (int)application, out error);
            if (error != Opus.Error.OK)
            {
                throw new InvalidOperationException($"Error occured while creating encoder: {error}");
            }

            SetForwardErrorCorrection(true);
        }
Exemplo n.º 2
0
		/// <summary> Creates a new Opus encoder. </summary>
		/// <param name="samplingRate">Sampling rate of the input signal (Hz). Supported Values:  8000, 12000, 16000, 24000, or 48000.</param>
		/// <param name="channels">Number of channels (1 or 2) in input signal.</param>
		/// <param name="frameLength">Length, in milliseconds, that each frame takes. Supported Values: 2.5, 5, 10, 20, 40, 60</param>
		/// <param name="application">Coding mode.</param>
		/// <returns>A new <c>OpusEncoder</c></returns>
		public OpusEncoder(int samplingRate, int channels, int frameLength, Opus.Application application)
		{
			if (samplingRate != 8000 && samplingRate != 12000 &&
				samplingRate != 16000 && samplingRate != 24000 &&
				samplingRate != 48000)
				throw new ArgumentOutOfRangeException(nameof(samplingRate));
			if (channels != 1 && channels != 2)
				throw new ArgumentOutOfRangeException(nameof(channels));

			InputSamplingRate = samplingRate;
			InputChannels = channels;
			Application = application;
			FrameLength = frameLength;
			SampleSize = (BitRate / 8) * channels;
			SamplesPerFrame = samplingRate / 1000 * FrameLength;
			FrameSize = SamplesPerFrame * SampleSize;

			Opus.Error error;
			_ptr = Opus.CreateEncoder(samplingRate, channels, (int)application, out error);
			if (error != Opus.Error.OK)
				throw new InvalidOperationException($"Error occured while creating encoder: {error}");

			SetForwardErrorCorrection(true);
		}