Пример #1
0
        public static void PackFrame(CriHcaFrame frame, Crc16 crc, byte[] outBuffer)
        {
            var writer = new BitWriter(outBuffer);

            writer.Write(0xffff, 16);
            writer.Write(frame.AcceptableNoiseLevel, 9);
            writer.Write(frame.EvaluationBoundary, 7);

            foreach (CriHcaChannel channel in frame.Channels)
            {
                WriteScaleFactors(writer, channel);
                if (channel.Type == ChannelType.StereoSecondary)
                {
                    for (int i = 0; i < SubframesPerFrame; i++)
                    {
                        writer.Write(channel.Intensity[i], 4);
                    }
                }
                else if (frame.Hca.HfrGroupCount > 0)
                {
                    for (int i = 0; i < frame.Hca.HfrGroupCount; i++)
                    {
                        writer.Write(channel.HfrScales[i], 6);
                    }
                }
            }

            for (int sf = 0; sf < SubframesPerFrame; sf++)
            {
                foreach (CriHcaChannel channel in frame.Channels)
                {
                    WriteSpectra(writer, channel, sf);
                }
            }

            writer.AlignPosition(8);
            for (int i = writer.Position / 8; i < frame.Hca.FrameSize - 2; i++)
            {
                writer.Buffer[i] = 0;
            }

            WriteChecksum(writer, crc, outBuffer);
        }