Esempio n. 1
0
        private void Initialize(Header header)
        {
            // REVIEW: allow customizable scale factor
            float scalefactor = 32700.0f;

            int mode = header.mode();
            int layer = header.layer();
            int channels = mode == Header.SINGLE_CHANNEL ? 1 : 2;

            // set up output buffer if not set up by client.
            if (m_Output == null)
                m_Output = new SampleBuffer(header.frequency(), channels);

            float[] factors = m_Equalizer.BandFactors;
            //Console.WriteLine("NOT CREATING SYNTHESIS FILTERS");
            m_LeftChannelFilter = new SynthesisFilter(0, scalefactor, factors);

            // REVIEW: allow mono output for stereo
            if (channels == 2)
                m_RightChannelFilter = new SynthesisFilter(1, scalefactor, factors);

            m_OutputChannels = channels;
            m_OutputFrequency = header.frequency();

            m_IsInitialized = true;
        }
Esempio n. 2
0
        /// <summary>
        ///     Decodes one frame from an MPEG audio bitstream.
        /// </summary>
        /// <param name="header">
        ///     Header describing the frame to decode.
        /// </param>
        /// <param name="stream">
        ///     Bistream that provides the bits for the body of the frame.
        /// </param>
        /// <returns>
        ///     A SampleBuffer containing the decoded samples.
        /// </returns>
        public virtual ABuffer DecodeFrame(Header header, Bitstream stream)
        {
            if (!m_IsInitialized)
            {
                Initialize(header);
            }

            int layer = header.layer();

            m_Output.ClearBuffer();

            IFrameDecoder decoder = RetrieveDecoder(header, stream, layer);

            decoder.DecodeFrame();

            m_Output.WriteBuffer(1);

            return m_Output;
        }
Esempio n. 3
0
        protected internal virtual IFrameDecoder RetrieveDecoder(Header header, Bitstream stream, int layer)
        {
            IFrameDecoder decoder = null;

            // REVIEW: allow channel output selection type
            // (LEFT, RIGHT, BOTH, DOWNMIX)
            switch (layer)
            {
                case 3:
                    if (m_L3Decoder == null)
                    {
                        m_L3Decoder = new LayerIIIDecoder(stream, header, m_LeftChannelFilter, m_RightChannelFilter, m_Output,
                            (int) OutputChannelsEnum.BOTH_CHANNELS);
                    }

                    decoder = m_L3Decoder;
                    break;

                case 2:
                    if (m_L2Decoder == null)
                    {
                        m_L2Decoder = new LayerIIDecoder();
                        m_L2Decoder.Create(stream, header, m_LeftChannelFilter, m_RightChannelFilter, m_Output,
                            (int) OutputChannelsEnum.BOTH_CHANNELS);
                    }
                    decoder = m_L2Decoder;
                    break;

                case 1:
                    if (m_L1Decoder == null)
                    {
                        m_L1Decoder = new LayerIDecoder();
                        m_L1Decoder.Create(stream, header, m_LeftChannelFilter, m_RightChannelFilter, m_Output,
                            (int) OutputChannelsEnum.BOTH_CHANNELS);
                    }
                    decoder = m_L1Decoder;
                    break;
            }

            if (decoder == null)
            {
                throw NewDecoderException(DecoderErrors.UNSUPPORTED_LAYER, null);
            }

            return decoder;
        }
Esempio n. 4
0
 private void InitBlock()
 {
     m_CRC = new Crc16[1];
     m_SyncBuffer = new sbyte[4];
     m_FrameBytes = new sbyte[BUFFER_INT_SIZE*4];
     m_FrameBuffer = new int[BUFFER_INT_SIZE];
     m_Header = new Header();
 }