Ejemplo n.º 1
0
        private void WriteAncillaryData(byte[] theData, int lengthInBits)
        {
            int bytesToSend   = lengthInBits / 8;
            int remainingBits = lengthInBits % 8;
            int wrd;

            userFrameDataPH.Position = 0;

            for (int i = 0; i < bytesToSend; i++)
            {
                wrd = theData[i];
                userFrameDataPH.Add(wrd, 8);
            }
            if (remainingBits != 0)
            {
                wrd = theData[bytesToSend] >> (8 - remainingBits);
                userFrameDataPH.Add(wrd, remainingBits);
            }
        }
Ejemplo n.º 2
0
        private void EncodeSideInfo(ref SideInfo l3_side, ref FrameParams fr_ps)
        {
            int bits_sent, mode_gr = 2;

            headerPH.Position = 0;

            headerPH.Add(4095, 12);
            headerPH.Add(1, 1);
            headerPH.Add(1, 2);
            headerPH.Add(fr_ps.Header.ErrorProtection, 1);
            headerPH.Add(fr_ps.Header.BitrateIndex, 4);
            headerPH.Add(fr_ps.Header.SamplingFrequency, 2);
            headerPH.Add(fr_ps.Header.Padding, 1);
            headerPH.Add(fr_ps.Header.Extension, 1);
            headerPH.Add(fr_ps.Header.Mode, 2);
            headerPH.Add(fr_ps.Header.ModeExt, 2);
            headerPH.Add(fr_ps.Header.Copyright, 1);
            headerPH.Add(fr_ps.Header.Original, 1);
            headerPH.Add(fr_ps.Header.Emphasis, 2);

            bits_sent = 32;

            frameSIPH.Position = 0;

            for (int ch = 0; ch < fr_ps.Chn; ch++)
            {
                channelSIPH[ch].Position = 0;
            }

            for (int gr = 0; gr < 2; gr++)
            {
                for (int ch = 0; ch < fr_ps.Chn; ch++)
                {
                    spectrumSIPH[ch, gr].Position = 0;
                }
            }

            if (fr_ps.Header.ErrorProtection == 0)
            {
                headerPH.Add(0, 16);
                bits_sent += 16;
            }

            frameSIPH.Add(l3_side.MainDataBegin, 9);

            if (fr_ps.Chn == 2)
            {
                frameSIPH.Add(l3_side.PrivateBits, 3);
            }
            else
            {
                frameSIPH.Add(l3_side.PrivateBits, 5);
            }

            for (int ch = 0; ch < fr_ps.Chn; ch++)
            {
                for (int scfsi_band = 0; scfsi_band < 4; scfsi_band++)
                {
                    channelSIPH[ch].Add(l3_side.Scfsi[ch, scfsi_band], 1);
                }
            }
            for (int gr = 0; gr < mode_gr; gr++)
            {
                for (int ch = 0; ch < fr_ps.Chn; ch++)
                {
                    spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].Part23Length, 12);

                    spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].BigValues, 9);
                    spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].GlobalGain, 8);
                    spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].ScalefacCompress, 4);
                    spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].WindowSwitchingFlag, 1);

                    if (l3_side.TT[ch, gr].WindowSwitchingFlag != 0)
                    {
                        spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].BlockType, 2);
                        spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].MixedBlockFlag, 1);

                        for (int region = 0; region < 2; region++)
                        {
                            spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].TableSelect[region], 5);
                        }
                        for (int window = 0; window < 3; window++)
                        {
                            spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].SubblockGain[window], 3);
                        }
                    }
                    else
                    {
                        for (int region = 0; region < 3; region++)
                        {
                            spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].TableSelect[region], 5);
                        }

                        spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].Region0Count, 4);
                        spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].Region1Count, 3);
                    }

                    spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].Preflag, 1);
                    spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].ScalefacScale, 1);
                    spectrumSIPH[ch, gr].Add(l3_side.TT[ch, gr].Count1tableSelect, 1);
                }
            }


            if (fr_ps.Chn == 2)
            {
                bits_sent += 256;
            }
            else
            {
                bits_sent += 136;
            }
        }