Пример #1
0
        private static void CompareContainer(TagContainer c1, TagContainer c2)
        {
            Assert.AreEqual(c1.Count, c2.Count);
            TagDescriptorV3 c1Tag = c1.GetId3V23Descriptor();
            TagDescriptorV3 c2Tag = c2.GetId3V23Descriptor();

            Assert.AreEqual(c1Tag.MajorVersion, c2Tag.MajorVersion);
            Assert.AreEqual(c1Tag.Revision, c2Tag.Revision);
            Assert.AreEqual(c1Tag.ExperimentalIndicator, c2Tag.ExperimentalIndicator);
            Assert.AreEqual(c1Tag.ExtendedHeader, c2Tag.ExtendedHeader);
            Assert.AreEqual(c1Tag.Unsynchronisation, c2Tag.Unsynchronisation);

            Assert.AreEqual(c1Tag.CrcDataPresent, c2Tag.CrcDataPresent);
            Assert.IsTrue(ComparePayload(c1Tag.Crc, c2Tag.Crc));
            Assert.AreEqual(c1Tag.PaddingSize, c2Tag.PaddingSize);
        }
Пример #2
0
        private static void EncodeV3(Id3TagInfo tagInfo, TagContainer container)
        {
            TagDescriptorV3 descriptor = container.GetId3V23Descriptor();

            tagInfo.Experimental = descriptor.ExperimentalIndicator;
            tagInfo.ExtendedHeaderAvailable = descriptor.ExtendedHeader;
            tagInfo.Unsynchronised = descriptor.Unsynchronisation;

            if (descriptor.ExtendedHeader)
            {
                tagInfo.ExtendedHeader = ExtendedTagHeaderV3.Create(descriptor.PaddingSize, descriptor.CrcDataPresent,
                                                                    descriptor.Crc);
            }
        }
Пример #3
0
        private static byte[] GetTagHeader(TagContainer tagContainer)
        {
            var tagHeader = new byte[10];
            tagHeader[0] = 0x49;
            tagHeader[1] = 0x44;
            tagHeader[2] = 0x33;

            switch (tagContainer.TagVersion)
            {
                case TagVersion.Id3V23:
                    var descriptorV3 = tagContainer.GetId3V23Descriptor();
                    tagHeader[3] = 0x03;
                    tagHeader[4] = 0x00;

                    if (descriptorV3.Unsynchronisation)
                    {
                        tagHeader[5] |= 0x80;
                    }

                    if (descriptorV3.ExtendedHeader)
                    {
                        tagHeader[5] |= 0x40;
                    }

                    if (descriptorV3.ExperimentalIndicator)
                    {
                        tagHeader[5] |= 0x20;
                    }
                    break;

                case TagVersion.Id3V24:
                    var descriptorV4 = tagContainer.GetId3V24Descriptor();
                    tagHeader[3] = 0x04;
                    tagHeader[4] = 0x00;

                    if (descriptorV4.Unsynchronisation)
                    {
                        tagHeader[5] |= 0x80;
                    }

                    if (descriptorV4.ExtendedHeader)
                    {
                        tagHeader[5] |= 0x40;
                    }

                    if (descriptorV4.ExperimentalIndicator)
                    {
                        tagHeader[5] |= 0x20;
                    }

                    if (descriptorV4.Footer)
                    {
                        tagHeader[5] |= 0x10;
                    }

                    break;
                default:
                    throw new ID3TagException("Unknown version!");
            }

            return tagHeader;
        }
Пример #4
0
        private static byte[] GetExtendedHeaderV3(TagContainer tagContainer)
        {
            var extendedHeaderBytes = new byte[0];
            var tag = tagContainer.GetId3V23Descriptor();

            if (tag.ExtendedHeader)
            {
                var extendedHeaderLength = 0;

                if (tag.CrcDataPresent)
                {
                    extendedHeaderLength = 10;
                }
                else
                {
                    extendedHeaderLength = 6;
                }

                // Create and set the length
                extendedHeaderBytes = new byte[extendedHeaderLength + 4];
                extendedHeaderBytes[3] = Convert.ToByte(extendedHeaderLength);

                var paddingBytes = BitConverter.GetBytes(tag.PaddingSize);
                Array.Reverse(paddingBytes);
                Array.Copy(paddingBytes, 0, extendedHeaderBytes, 6, 4);
                if (tag.CrcDataPresent)
                {
                    extendedHeaderBytes[4] |= 0x80;
                    Array.Copy(tag.Crc, 0, extendedHeaderBytes, 10, 4);
                }
            }

            return extendedHeaderBytes;
        }
Пример #5
0
        private static byte[] BuildId3V3Tag(TagContainer tagContainer)
        {
            byte[] tagBytes;
            var tag = tagContainer.GetId3V23Descriptor();
            var frameBytes = GetFrameBytes(tagContainer);

            //
            //  Calculate the CRC32 value of the frameBytes ( before unsync!)
            //
            if (tag.CrcDataPresent)
            {
                var crc32 = new Crc32(Crc32.DefaultPolynom);
                var crcValue = crc32.Calculate(frameBytes);

                tag.SetCrc32(crcValue);
            }

            //
            //  OK. Build the complete tag
            //
            var extendedHeaderBytes = GetExtendedHeaderV3(tagContainer);
            var tagHeader = GetTagHeader(tagContainer);
            var rawTagBytes = BuildFinalTag(tagHeader, extendedHeaderBytes, frameBytes, tag.PaddingSize, false);
            if (tag.Unsynchronisation)
            {
                tagBytes = AddUnsyncBytes(rawTagBytes);
            }
            else
            {
                tagBytes = rawTagBytes;
            }

            return tagBytes;
        }