public EncodingInfo Read(Stream raf) { EncodingInfo info = new EncodingInfo(); //Begin info fetch------------------------------------------- if (raf.Length == 0) { //Empty File throw new CannotReadException("File is empty"); } raf.Seek(0, SeekOrigin.Begin); //MP+ Header string byte[] b = new byte[3]; raf.Read(b, 0, b.Length); string mpc = new string(System.Text.Encoding.ASCII.GetChars(b)); if (mpc != "MP+" && mpc == "ID3") { //TODO Do we have to do this ?? //we have an ID3v2 tag at the beginning //We quickly jump to MPC data raf.Seek(6, SeekOrigin.Begin); int tagSize = ReadSyncsafeInteger(raf); raf.Seek(tagSize + 10, SeekOrigin.Begin); //retry to read MPC stream b = new byte[3]; raf.Read(b, 0, b.Length); mpc = new string(System.Text.Encoding.ASCII.GetChars(b)); if (mpc != "MP+") { //We could definitely not go there throw new CannotReadException("MP+ Header not found"); } } else if (mpc != "MP+") { throw new CannotReadException("MP+ Header not found"); } b = new byte[25]; raf.Read(b, 0, b.Length); MpcHeader mpcH = new MpcHeader(b); //We only support v7 Stream format, so if it isn't v7, then returned values //will be bogus, and the file will be ignored double pcm = mpcH.SamplesNumber; info.Duration = new TimeSpan((long)(pcm * 1152 / mpcH.SamplingRate) * TimeSpan.TicksPerSecond); info.ChannelNumber = mpcH.ChannelNumber; info.SamplingRate = mpcH.SamplingRate; info.EncodingType = mpcH.EncodingType; info.ExtraEncodingInfos = mpcH.EncoderInfo; info.Bitrate = ComputeBitrate(info.Duration.Seconds, raf.Length); return(info); }
public EncodingInfo Read( Stream raf ) { EncodingInfo info = new EncodingInfo(); //Begin info fetch------------------------------------------- if ( raf.Length==0 ) { //Empty File throw new CannotReadException("File is empty"); } raf.Seek( 0 , SeekOrigin.Begin); //MP+ Header string byte[] b = new byte[3]; raf.Read(b, 0, b.Length); string mpc = new string(System.Text.Encoding.ASCII.GetChars(b)); if (mpc != "MP+" && mpc == "ID3") { //TODO Do we have to do this ?? //we have an ID3v2 tag at the beginning //We quickly jump to MPC data raf.Seek(6, SeekOrigin.Begin); int tagSize = ReadSyncsafeInteger(raf); raf.Seek(tagSize+10, SeekOrigin.Begin); //retry to read MPC stream b = new byte[3]; raf.Read(b, 0, b.Length); mpc = new string(System.Text.Encoding.ASCII.GetChars(b)); if (mpc != "MP+") { //We could definitely not go there throw new CannotReadException("MP+ Header not found"); } } else if (mpc != "MP+"){ throw new CannotReadException("MP+ Header not found"); } b = new byte[25]; raf.Read(b, 0, b.Length); MpcHeader mpcH = new MpcHeader(b); //We only support v7 Stream format, so if it isn't v7, then returned values //will be bogus, and the file will be ignored double pcm = mpcH.SamplesNumber; info.Duration = new TimeSpan((long)(pcm * 1152 / mpcH.SamplingRate) * TimeSpan.TicksPerSecond); info.ChannelNumber = mpcH.ChannelNumber; info.SamplingRate = mpcH.SamplingRate; info.EncodingType = mpcH.EncodingType; info.ExtraEncodingInfos = mpcH.EncoderInfo; info.Bitrate = ComputeBitrate( info.Duration.Seconds, raf.Length ); return info; }