/// <summary> /// Quickly checks an array of bytes to see if it represents a valid AAC frame header. /// </summary> /// <param name="frameHeader">Bytes representing an AAC frame header.</param> /// <returns>true if the supplied bytes are a valid frame header, otherwise, false.</returns> public static bool IsValidFrame(byte[] frameHeader) { if (frameHeader == null) { throw new ArgumentNullException("frameHeader"); } int value = BitTools.MaskBits(frameHeader, 0, 12); if (value != AacpFrame.syncValue) { return(false); } int sampleRate = AacpFrame.ParseSampleRate(frameHeader); if (sampleRate == -1) { return(false); } int numberOfChannels = AacpFrame.ParseChannel(frameHeader); if (numberOfChannels == -1) { return(false); } return(true); }
/// <summary> /// Determines whether the specified Object is equal to the current Object /// </summary> /// <param name="obj">The object to compare with the current object.</param> /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns> public override bool Equals(object obj) { AacpFrame other = obj as AacpFrame; if (other == null) { return(false); } return((this.NumberOfChannels == other.NumberOfChannels) && (this.SamplingRate == other.SamplingRate) && (this.BitRate == other.BitRate)); }
/// <summary> /// Initializes a new instance of the AacpFrame class. /// </summary> /// <remarks> /// <para> /// This class is a partial implementation of an AAC audio frame. The primary purpose of this class is to represent an AAC /// file. Many of the features not explicitly needed for audio rendering are omitted from the implementation. /// </para> /// <para> /// Data on this format is readily discoverable in many books as well as by /// searching for "AAC Frame" in your favorite search engine. As always, /// Wikipedia is well stocked in all of these areas as well. /// </para> /// </remarks> /// <param name="frameHeader">Byte array containing 4 bytes representing an AAC header.</param> public AacpFrame(byte[] frameHeader) : base() { if (frameHeader == null) { throw new ArgumentNullException("frameHeader"); } // Sync int value = BitTools.MaskBits(frameHeader, 0, 12); if (value != syncValue) { throw new ArgumentException("Invalid sync value."); } this.NumberOfChannels = AacpFrame.ParseChannel(frameHeader); this.SamplingRate = AacpFrame.ParseSampleRate(frameHeader); this.BitRate = AacpFrame.CalculateBitRate(this.SamplingRate, this.NumberOfChannels); this.FrameSize = AacpFrame.ParseFrameSize(frameHeader); int objectTypeId = BitTools.MaskBits(frameHeader, 16, 2); }