/// <inheritdoc/> public override byte[] ToByteArray() { using (StreamBuffer buffer = new StreamBuffer()) { buffer.WriteString(Name); buffer.WriteBigEndianInt16(Version); buffer.WriteBigEndianInt16((short)_delay); buffer.WriteBigEndianInt16((short)Quality); buffer.WriteBigEndianInt32(FileSize); buffer.WriteBigEndianInt32(FrameCount); buffer.WriteBigEndianInt16(TableEntries); buffer.WriteBigEndianInt16(TableScale); buffer.WriteBigEndianInt16(TableEntrySize); buffer.WriteBigEndianInt16(FramesPerTableEntry); for (int i = 0; i <= TableEntries; i++) buffer.WriteBigEndianBytes(Toc[i] / TableScale, TableEntrySize); return buffer.ToByteArray(); } }
/// <inheritdoc /> public byte[] ToByteArray() { using (StreamBuffer sb = new StreamBuffer()) { sb.WriteString(Identifier); FlacStreamInfoMetadataBlock streamInfoMetadataBlock = StreamInfoMetadataBlocks.FirstOrDefault(); if (streamInfoMetadataBlock != null) sb.Write(streamInfoMetadataBlock.ToByteArray()); foreach (FlacMetadataBlock metadataBlock in MetadataBlocks.Where(m => !ReferenceEquals(m, streamInfoMetadataBlock))) sb.Write(metadataBlock.ToByteArray()); foreach (FlacFrame frame in Frames) sb.Write(frame.ToByteArray()); return sb.ToByteArray(); } }
/// <summary> /// Places the <see cref="VorbisComment"/> into a byte array. /// </summary> /// <returns> /// A byte array that represents the <see cref="VorbisComment"/>. /// </returns> public byte[] ToByteArray() { using (StreamBuffer buf = new StreamBuffer()) { string val = (Name ?? String.Empty) + Delimiter + Value; buf.WriteInt(Encoding.UTF8.GetByteCount(val)); buf.WriteString(val, Encoding.UTF8); return buf.ToByteArray(); } }
/// <inheritdoc/> public override byte[] ToByteArray() { using (StreamBuffer buf = new StreamBuffer()) { buf.WriteString(Name); buf.WriteBigEndianInt32(Flags); if ((Flags & XingHeaderFlags.FrameCountFlag) != 0) buf.WriteBigEndianInt32(FrameCount); if ((Flags & XingHeaderFlags.FileSizeFlag) != 0) buf.WriteBigEndianInt32(FileSize); // Extract TOC (Table of Contents) for more accurate seeking if ((Flags & XingHeaderFlags.TocFlag) != 0) { for (int i = 0; i < 100; i++) buf.WriteByte((byte)Toc[i]); } if ((Flags & XingHeaderFlags.VbrScaleFlag) != 0) buf.WriteBigEndianInt32(Quality); return buf.ToByteArray(); } }
////------------------------------------------------------------------------------------------------------------------------------ /// <summary> /// Places the <see cref="VorbisComments"/> into a byte array. /// </summary> /// <returns> /// A byte array that represents the <see cref="VorbisComments"/>. /// </returns> public byte[] ToByteArray() { using (StreamBuffer buf = new StreamBuffer()) { Vendor = Vendor ?? String.Empty; buf.WriteInt(Encoding.UTF8.GetByteCount(Vendor)); buf.WriteString(Vendor, Encoding.UTF8); buf.WriteInt(Comments.Count); foreach (byte[] data in Comments.Where(c => c != null).Select(c => c.ToByteArray())) { buf.WriteInt(data.Length); buf.Write(data); } return buf.ToByteArray(); } }
////------------------------------------------------------------------------------------------------------------------------------ /// <inheritdoc/> public byte[] ToByteArray() { using (StreamBuffer buffer = new StreamBuffer()) { buffer.Write(HeaderIdentifierBytes); if (Lyrics != null) buffer.WriteString(Lyrics, Encoding); buffer.Write(FooterIdentifierBytes); return buffer.ToByteArray(); } }
////------------------------------------------------------------------------------------------------------------------------------ /// <inheritdoc /> public byte[] ToByteArray() { using (StreamBuffer buffer = new StreamBuffer()) { if (UseHeader) { // Header buffer.Write(HeaderIdentifierBytes); buffer.WritePadding(NullByte, 2); buffer.WriteString(XingEncoderVersion); buffer.WritePadding(NullByte, 2); buffer.WriteString(Version); buffer.WritePadding(NullByte, 2); buffer.WritePadding(PaddingByte, 226); } // Image extension int imageExtensionOffset = (int)buffer.Position; if ((Image != null) && !String.IsNullOrEmpty(Image.FileExtension)) { buffer.WriteString(Image.FileExtension); buffer.WritePadding(PaddingByte, 4 - Image.FileExtension.Length); } else buffer.WritePadding(PaddingByte, 4); // Image binary int imageBinaryOffset = (int)buffer.Position; if ((Image != null) && (Image.BinaryImage != null)) { buffer.WriteInt(Image.BinaryImage.Length); buffer.Write(Image.BinaryImage); } else buffer.WriteInt(0); // Unused int unusedOffset = (int)buffer.Position; buffer.WritePadding(NullByte, 4); // Version information int versionInfoOffset = (int)buffer.Position; buffer.WriteString(HeaderIdentifier); buffer.WritePadding(NullByte, 2); buffer.WriteString(XingEncoderVersion); buffer.WritePadding(NullByte, 2); buffer.WriteString(Version); buffer.WritePadding(NullByte, 2); buffer.WritePadding(PaddingByte, 226); // Audio meta-data // The audio meta-data is the heart of the MusicMatch tag. It contains most // of the pertinent information found in other tagging formats (song title, // album title, artist, etc.) and some that are unique to this format (mood, // preference, situation). int audioMetaDataOffset = (int)buffer.Position; // Single-line text fields buffer.WriteShort((short)(SongTitle ?? String.Empty).Length); buffer.WriteString(SongTitle ?? String.Empty); buffer.WriteShort((short)(AlbumTitle ?? String.Empty).Length); buffer.WriteString(AlbumTitle ?? String.Empty); buffer.WriteShort((short)(ArtistName ?? String.Empty).Length); buffer.WriteString(ArtistName ?? String.Empty); buffer.WriteShort((short)(Genre ?? String.Empty).Length); buffer.WriteString(Genre ?? String.Empty); buffer.WriteShort((short)(Tempo ?? String.Empty).Length); buffer.WriteString(Tempo ?? String.Empty); buffer.WriteShort((short)(Mood ?? String.Empty).Length); buffer.WriteString(Mood ?? String.Empty); buffer.WriteShort((short)(Situation ?? String.Empty).Length); buffer.WriteString(Situation ?? String.Empty); buffer.WriteShort((short)(Preference ?? String.Empty).Length); buffer.WriteString(Preference ?? String.Empty); // Non-text fields buffer.WriteShort((short)(SongDuration ?? String.Empty).Length); buffer.WriteString(SongDuration ?? String.Empty); buffer.WriteDouble(CreationDate.ToOADate()); buffer.WriteInt(PlayCounter); buffer.WriteShort((short)(OriginalFilename ?? String.Empty).Length); buffer.WriteString(OriginalFilename ?? String.Empty); buffer.WriteShort((short)(SerialNumber ?? String.Empty).Length); buffer.WriteString(SerialNumber ?? String.Empty); buffer.WriteShort(TrackNumber); // Multi-line text fields buffer.WriteShort((short)(Notes ?? String.Empty).Length); buffer.WriteString(Notes ?? String.Empty); buffer.WriteShort((short)(ArtistBio ?? String.Empty).Length); buffer.WriteString(ArtistBio ?? String.Empty); buffer.WriteShort((short)(Lyrics ?? String.Empty).Length); buffer.WriteString(Lyrics ?? String.Empty); // Internet addresses buffer.WriteShort((short)(ArtistUrl ?? String.Empty).Length); buffer.WriteString(ArtistUrl ?? String.Empty); buffer.WriteShort((short)(BuyCdUrl ?? String.Empty).Length); buffer.WriteString(BuyCdUrl ?? String.Empty); buffer.WriteShort((short)(ArtistEmail ?? String.Empty).Length); buffer.WriteString(ArtistEmail ?? String.Empty); // Null bytes buffer.WritePadding(NullByte, 16); // In all versions of the MusicMatch format up to and including 3.00, the // section is always 7868 bytes in length. All subsequent versions allowed // three possible lengths for this section: 7936, 8004, and 8132 bytes. The // conditions under which a particular length from these three possibilities // was used is unknown. In all cases, this section is padded with dashes // ($2D) to achieve this constant size. double version; if (!Double.TryParse(Version, out version)) version = 3.100000; // The padding is calculated by taking the AudioMetaDataSize minus the total size of audio meta data fields, // minus the total size of the data offset fields, minus the footer size. long paddingSize = ((version <= 3.1) ? AudioMetaDataSizes.First() : AudioMetaDataSizes.Last()) - (buffer.Length - audioMetaDataOffset) - DataOffsetFieldsSize - FooterSize; buffer.WritePadding(0x2D, (int)paddingSize); // Data offsets buffer.WriteInt(imageExtensionOffset); buffer.WriteInt(imageBinaryOffset); buffer.WriteInt(unusedOffset); buffer.WriteInt(versionInfoOffset); buffer.WriteInt(audioMetaDataOffset); // Footer buffer.Write(FooterIdentifierBytes); buffer.WritePadding(PaddingByte, 13); buffer.WriteString(Version.Substring(0 ,4)); buffer.WritePadding(PaddingByte, 12); return buffer.ToByteArray(); } }
public void WriteStringTest2() { StreamBuffer target = new StreamBuffer(); // TODO: Initialize to an appropriate value string str = string.Empty; // TODO: Initialize to an appropriate value Encoding encoding = null; // TODO: Initialize to an appropriate value int maxBytesToWrite = 0; // TODO: Initialize to an appropriate value target.WriteString(str, encoding, maxBytesToWrite); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public void WriteStringTest() { StreamBuffer target = new StreamBuffer(); // TODO: Initialize to an appropriate value string str = string.Empty; // TODO: Initialize to an appropriate value target.WriteString(str); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
////------------------------------------------------------------------------------------------------------------------------------ /// <summary> /// Writes the frame into a byte array. /// </summary> /// <returns> /// A byte array that represents the frame. /// </returns> public byte[] ToByteArray() { using (StreamBuffer sb = new StreamBuffer()) { sb.WriteString(Identifier, Encoding.ASCII, FieldIdentifierLength); byte[] data = Data; if (data != null) { sb.WriteString(data.Length.ToString("D" + FieldSizeLength, CultureInfo.InvariantCulture)); sb.Write(data); } else { sb.WriteString(0.ToString("D" + FieldSizeLength, CultureInfo.InvariantCulture)); } return sb.ToByteArray(); } }
////------------------------------------------------------------------------------------------------------------------------------ /// <summary> /// Places the <see cref="LameTag"/> into a byte array. /// </summary> /// <returns>A byte array that represents the <see cref="LameTag"/> instance.</returns> public byte[] ToByteArray() { using (StreamBuffer buffer = new StreamBuffer()) { if (Version < 3.09f) { buffer.WriteString(EncoderVersion, Encoding.ASCII, 20); } else { buffer.WriteString(EncoderVersion, Encoding.ASCII, 9); buffer.WriteByte((byte)((InfoTagRevision & 0xF0) | (VbrMethod & 0x0F))); buffer.WriteByte((byte)LowpassFilterValue); buffer.WriteFloat(PeakSignalAmplitude); buffer.WriteShort(RadioReplayGain); buffer.WriteShort(AudiophileReplayGain); buffer.WriteByte((byte)EncodingFlags); buffer.WriteByte((byte)BitRate); buffer.WriteBytes(EncoderDelays, 3); buffer.WriteByte((byte)Misc); buffer.WriteByte((byte)Mp3Gain); buffer.WriteShort(PresetSurroundInfo); buffer.WriteBigEndianInt32(MusicLength); buffer.WriteBigEndianInt16(_musicCrc); buffer.WriteBigEndianInt16(_infoTagCrc); } return buffer.ToByteArray(); } }