Exemplo n.º 1
0
        public bool processBuffer(byte[] rxBuf, out byte[] pcm16)
        {
            pcm16 = null;
            if (!_initialized)
            {
                if (!initialize(rxBuf))
                {
                    return(false);
                }
            }

            //next does not include the header (initialized with asc), works with all bitrates
            int bytesConsumed;
            int decoderObjectType   = 0;
            int decoderChannels     = 0;
            int decoderSamplingRate = 0;
            int startIx             = 0;

            int error = AACDecoder.decode(hDecoder, rxBuf, startIx, out pcm16, out bytesConsumed,
                                          out decoderSamplingRate, out decoderChannels, out decoderObjectType);

            if (error != 0)
            {
                string s = AACDecoder.getErrorMessage((byte)error);
                //logger.Error(s);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Process audio stream
        /// </summary>
        /// <param name="rxBuf">AAC coded audio buffer</param>
        /// <param name="pcm16">PCM16 decoded audio buffer</param>
        /// <returns></returns>
        private bool processBuffer(byte[] rxBuf, out byte[] pcm16)
        {
            pcm16 = null; //this one receives the decoded bytes
            // this is a complete aac frame with 960 samples
            if (!_initialized)
            {
                if (!initialize(rxBuf))
                {
                    return(false);
                }
            }

            //next does not include the header (initialized with asc), works with all bitrates
            int bytesConsumed;
            int decoderObjectType   = 0;
            int decoderChannels     = 0;
            int decoderSamplingRate = 0;
            int startIx             = 0;

            int error = AACDecoder.decode(hDecoder, rxBuf, startIx, out pcm16, out bytesConsumed,
                                          out decoderSamplingRate, out decoderChannels, out decoderObjectType);

            AACInfo.DecoderSamplingRate = decoderSamplingRate;
            AACInfo.DecoderChannels     = decoderChannels;
            AACInfo.DecoderObjectType   = (AAC_ObjectTypes)decoderObjectType;
            AACInfo.PCMBitDepth         = 16;

            // construct buffers of always 10000 bytes and send it to the audio
            if (error != 0)
            {
                string s = AACDecoder.getErrorMessage((byte)error);
                logger.Error(s);
                return(false);
            }
            else
            {
                byte[] pcm16Buf = audioOutBuf.createBuffer(pcm16);
                if (pcm16Buf != null)
                {
                    waudio.AddSamples(pcm16Buf, 0, pcm16Buf.Length);
                }
                //else is a normal operating case indicating that the const size buffer is not yet ready
            }
            return(true);
        }