/// <summary> /// Finds the <see cref="VbriHeader"/> header within the <paramref name="firstFrame"/>. /// </summary> /// <param name="firstFrame">The first frame.</param> /// <returns>The VBRI header if found; otherwise, null.</returns> /// <remarks> /// The VBRI header is located exactly 32 bytes after the end of the first MPEG audio header in the file. /// It will compare the first 4 bytes against the <see cref="HeaderIndicator"/> /// to see if the header contains a <see cref="VbriHeader"/> or not. /// </remarks> public static new VbriHeader FindHeader(MpaFrame firstFrame) { if (firstFrame == null) throw new ArgumentNullException("firstFrame"); using (StreamBuffer buffer = new StreamBuffer()) { byte[] data = firstFrame.ToByteArray(); buffer.Write(data); // 32 bytes = data indicating silence const long Offset = MpaFrame.FrameHeaderSize + SilenceDataSize; buffer.Seek(Offset, SeekOrigin.Begin); string tagName = buffer.ReadString(4, false, false); return String.Compare(tagName, HeaderIndicator, StringComparison.OrdinalIgnoreCase) == 0 ? new VbriHeader(firstFrame, buffer, Offset) : null; } }
/// <summary> /// Finds the <see cref="VbriHeader"/> header within the <paramref name="firstFrame"/>. /// </summary> /// <param name="firstFrame">The first frame.</param> /// <returns>The VBRI header if found; otherwise, null.</returns> /// <remarks> /// The XING header is located after the side information in Layer III in the first MPEG audio header in the file. /// It will compare the first 4 bytes against the <see cref="VbrHeaderIndicator"/> /// to see if the header contains a <see cref="XingHeader"/> or not. /// </remarks> public static new XingHeader FindHeader(MpaFrame firstFrame) { if (firstFrame == null) throw new ArgumentNullException("firstFrame"); long offset = MpaFrame.FrameHeaderSize + firstFrame.SideInfoSize; using (StreamBuffer buffer = new StreamBuffer()) { byte[] data = firstFrame.ToByteArray(); buffer.Write(data); buffer.Seek(offset, SeekOrigin.Begin); string tagName = buffer.ReadString(4, false, false); if ((String.Compare(tagName, VbrHeaderIndicator, StringComparison.OrdinalIgnoreCase) == 0) || (String.Compare(tagName, CbrHeaderIndicator, StringComparison.OrdinalIgnoreCase) == 0)) return new XingHeader(firstFrame, buffer, offset); } return null; }