Example #1
0
        internal static int frame_size_select(int frame_size, OpusFramesize variable_duration, int Fs)
        {
            int new_size;

            if (frame_size < Fs / 400)
            {
                return(-1);
            }
            if (variable_duration == OpusFramesize.OPUS_FRAMESIZE_ARG)
            {
                new_size = frame_size;
            }
            else if (variable_duration == OpusFramesize.OPUS_FRAMESIZE_VARIABLE)
            {
                new_size = Fs / 50;
            }
            else if (variable_duration >= OpusFramesize.OPUS_FRAMESIZE_2_5_MS && variable_duration <= OpusFramesize.OPUS_FRAMESIZE_60_MS)
            {
                new_size = Inlines.IMIN(3 * Fs / 50, (Fs / 400) << (variable_duration - OpusFramesize.OPUS_FRAMESIZE_2_5_MS));
            }
            else
            {
                return(-1);
            }
            if (new_size > frame_size)
            {
                return(-1);
            }
            if (400 * new_size != Fs && 200 * new_size != Fs && 100 * new_size != Fs &&
                50 * new_size != Fs && 25 * new_size != Fs && 50 * new_size != 3 * Fs)
            {
                return(-1);
            }
            return(new_size);
        }
Example #2
0
        internal static int compute_frame_size <T>(T[] analysis_pcm, int analysis_pcm_ptr, int frame_size,
                                                   OpusFramesize variable_duration, int C, int Fs, int bitrate_bps,
                                                   int delay_compensation, Downmix.downmix_func <T> downmix, float[] subframe_mem, bool analysis_enabled
                                                   )
        {
            if (analysis_enabled && variable_duration == OpusFramesize.OPUS_FRAMESIZE_VARIABLE && frame_size >= Fs / 200)
            {
                int LM = 3;
                LM = optimize_framesize(analysis_pcm, analysis_pcm_ptr, frame_size, C, Fs, bitrate_bps,
                                        0, subframe_mem, delay_compensation, downmix);
                while ((Fs / 400 << LM) > frame_size)
                {
                    LM--;
                }
                frame_size = (Fs / 400 << LM);
            }
            else
            {
                frame_size = frame_size_select(frame_size, variable_duration, Fs);
            }

            if (frame_size < 0)
            {
                return(-1);
            }
            return(frame_size);
        }
Example #3
0
        internal int opus_multistream_encoder_init(
            int Fs,
            int channels,
            int streams,
            int coupled_streams,
            byte[] mapping,
            OpusApplication application,
            int surround
            )
        {
            int i, ret;
            int encoder_ptr;

            if ((channels > 255) || (channels < 1) || (coupled_streams > streams) ||
                (streams < 1) || (coupled_streams < 0) || (streams > 255 - coupled_streams))
            {
                return(OpusError.OPUS_BAD_ARG);
            }

            this.layout.nb_channels        = channels;
            this.layout.nb_streams         = streams;
            this.layout.nb_coupled_streams = coupled_streams;
            this.subframe_mem[0]           = this.subframe_mem[1] = this.subframe_mem[2] = 0;
            if (surround == 0)
            {
                this.lfe_stream = -1;
            }
            this.bitrate_bps       = OpusConstants.OPUS_AUTO;
            this.application       = application;
            this.variable_duration = OpusFramesize.OPUS_FRAMESIZE_ARG;
            for (i = 0; i < this.layout.nb_channels; i++)
            {
                this.layout.mapping[i] = mapping[i];
            }
            if (OpusMultistream.validate_layout(this.layout) == 0 || validate_encoder_layout(this.layout) == 0)
            {
                return(OpusError.OPUS_BAD_ARG);
            }

            encoder_ptr = 0;

            for (i = 0; i < this.layout.nb_coupled_streams; i++)
            {
                ret = this.encoders[encoder_ptr].opus_init_encoder(Fs, 2, application);
                if (ret != OpusError.OPUS_OK)
                {
                    return(ret);
                }
                if (i == this.lfe_stream)
                {
                    this.encoders[encoder_ptr].IsLFE = true;
                }
                encoder_ptr += 1;
            }
            for (; i < this.layout.nb_streams; i++)
            {
                ret = this.encoders[encoder_ptr].opus_init_encoder(Fs, 1, application);
                if (i == this.lfe_stream)
                {
                    this.encoders[encoder_ptr].IsLFE = true;
                }
                if (ret != OpusError.OPUS_OK)
                {
                    return(ret);
                }
                encoder_ptr += 1;
            }
            if (surround != 0)
            {
                Arrays.MemSetInt(this.preemph_mem, 0, channels);
                Arrays.MemSetInt(this.window_mem, 0, channels * 120);
            }
            this.surround = surround;
            return(OpusError.OPUS_OK);
        }