Пример #1
0
        private bool initialize(byte[] rxBuf)
        {
            int result = AACDecoder.init(hDecoder, rxBuf, ref sample_rate, ref channels);

            if (result != 0)
            {
                return(false);
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Init AAC
        /// </summary>
        /// <param name="rxBuf"></param>
        /// <returns></returns>
        private bool initialize(byte[] rxBuf)
        {
            //parse header and initialize the decoder
            init_result = AACDecoder.init(hDecoder,
                                          rxBuf,
                                          ref sample_rate,
                                          ref channels);
            AACInfo.DecoderSamplingRate = sample_rate;
            AACInfo.DecoderChannels     = channels;
            if (init_result != 0)
            {
                init_result *= -1;
                string err = AACDecoder.getErrorMessage((byte)init_result);
                byte[] b   = System.Text.Encoding.ASCII.GetBytes(err);
                if (b == null)
                {
                    throw new Exception("BP");
                }
                //err = UnsafeCommon.UnsafeAsciiBytesToString(b, 0);

                string s = string.Format("Error initializing decoder library: {0}", err);
                AACDecoder.Close(hDecoder);
                hDecoder     = (IntPtr)0;
                _initialized = false;
                logger.Error(s);
                return(false);
            }

            if (waudio != null)
            {
                clear();
            }
            waudio = softsyst.qirx.Audio.wavAudio.create(eAudioSink.NAudio, "MP4", 0);
            if (waudio == null)
            {
                logger.Error("Cannot create audio sink MP4");
                return(false);
            }

            if (channels > 2)
            {
                logger.Warning($"{channels} audio channels detected. Reduced to two");
                channels = 2;
            }
            waudio.Init(sample_rate, 16, channels);
            waudio.Start();
            _initialized = true;
            logger.Debug("AAC and waudio initialized");

            return(true);
        }