Пример #1
0
        /// <summary>
        /// Returns the frame in a byte array.
        /// </summary>
        /// <returns>The frame in a byte array.</returns>
        public byte[] ToByteArray()
        {
            using (StreamBuffer sb = new StreamBuffer())
            {
                sb.WriteBigEndianInt32(_header);
                sb.Write(_sampleFrameNumberBytes);
                int blockSize = (_header >> 12) & 0xF;
                switch (blockSize)
                {
                    case 0x06:
                        sb.WriteByte((byte)(BlockSize - 1));
                        break;

                    case 0x07:
                        sb.WriteBigEndianInt16((short)(BlockSize - 1));
                        break;
                }
                int samplingRate = (_header >> 8) & 0xF;
                switch (samplingRate)
                {
                    case 0x0C:
                        sb.WriteByte((byte)(SamplingRate / 1000));
                        break;

                    case 0x0D:
                        sb.WriteBigEndianInt16((short)SamplingRate);
                        break;

                    case 0x0E:
                        sb.WriteBigEndianInt16((short)(SamplingRate / 10));
                        break;
                }
                sb.WriteByte((byte)_crc8);

                foreach (FlacSubFrame subFrame in SubFrames)
                    sb.Write(subFrame.ToByteArray());

                sb.WriteBigEndianInt16((short)_crc16);
                return sb.ToByteArray();
            }
        }
Пример #2
0
        /// <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();
            }
        }
Пример #3
0
        /// <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();
            }
        }
Пример #4
0
 /// <summary>
 /// Returns the frame in a byte array.
 /// </summary>
 /// <returns>The frame in a byte array.</returns>
 public virtual byte[] ToByteArray()
 {
     using (StreamBuffer sb = new StreamBuffer())
     {
         sb.WriteBigEndianInt32(Header);
         sb.WriteUnaryInt(WastedBits);
         return sb.ToByteArray();
     }
 }
Пример #5
0
 public void WriteBigEndianInt32Test()
 {
     StreamBuffer target = new StreamBuffer(); // TODO: Initialize to an appropriate value
     int value = 0; // TODO: Initialize to an appropriate value
     target.WriteBigEndianInt32(value);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
Пример #6
0
 ////------------------------------------------------------------------------------------------------------------------------------
 /// <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();
     }
 }