/* -------------------------------------------------------------------------- */ // No explicit destructors with C# /* -------------------------------------------------------------------------- */ public bool ReadFromFile(String FileName) { FileStream fs = null; BinaryReader source = null; char[] signatureChunk = new char[4]; tta_header ttaheader = new tta_header(); long TagSize; bool result = false; FResetData(); // load tags first FID3v2.ReadFromFile(FileName); FID3v1.ReadFromFile(FileName); FAPEtag.ReadFromFile(FileName); // calulate total tag size TagSize = 0; if (FID3v1.Exists) TagSize += 128; if (FID3v2.Exists) TagSize += FID3v2.Size; if (FAPEtag.Exists) TagSize += FAPEtag.Size; // begin reading data from file try { fs = new FileStream(FileName,FileMode.Open, FileAccess.Read); fs.Lock(0,fs.Length); source = new BinaryReader(fs); // seek past id3v2-tag if ( FID3v2.Exists ) { fs.Seek(FID3v2.Size, SeekOrigin.Begin); } signatureChunk = source.ReadChars(4); if ( Utils.StringEqualsArr("TTA1",signatureChunk) ) { // start looking for chunks ttaheader.Reset(); ttaheader.AudioFormat = source.ReadUInt16(); ttaheader.NumChannels = source.ReadUInt16(); ttaheader.BitsPerSample = source.ReadUInt16(); ttaheader.SampleRate = source.ReadUInt32(); ttaheader.DataLength = source.ReadUInt32(); ttaheader.CRC32 = source.ReadUInt32(); FFileSize = fs.Length; FValid = true; FAudioFormat = ttaheader.AudioFormat; FChannels = ttaheader.NumChannels; FBits = ttaheader.BitsPerSample; FSampleRate = ttaheader.SampleRate; FSamples = ttaheader.DataLength; FCRC32 = ttaheader.CRC32; FBitrate = (double)FFileSize * 8 / (FSamples / FSampleRate) / 1000; FDuration = (double)ttaheader.DataLength / ttaheader.SampleRate; result = true; } } catch (Exception e) { System.Console.WriteLine(e.StackTrace); result = false; } if (fs != null) { fs.Unlock(0,fs.Length); if (source != null) source.Close(); } return result; }
/* -------------------------------------------------------------------------- */ // No explicit destructors with C# /* -------------------------------------------------------------------------- */ public bool ReadFromFile(String FileName) { FileStream fs = null; BinaryReader source = null; char[] signatureChunk = new char[4]; tta_header ttaheader = new tta_header(); long TagSize; bool result = false; FResetData(); // load tags first FID3v2.ReadFromFile(FileName); FID3v1.ReadFromFile(FileName); FAPEtag.ReadFromFile(FileName); // calulate total tag size TagSize = 0; if (FID3v1.Exists) { TagSize += 128; } if (FID3v2.Exists) { TagSize += FID3v2.Size; } if (FAPEtag.Exists) { TagSize += FAPEtag.Size; } // begin reading data from file try { fs = new FileStream(FileName, FileMode.Open, FileAccess.Read); fs.Lock(0, fs.Length); source = new BinaryReader(fs); // seek past id3v2-tag if (FID3v2.Exists) { fs.Seek(FID3v2.Size, SeekOrigin.Begin); } signatureChunk = source.ReadChars(4); if (Utils.StringEqualsArr("TTA1", signatureChunk)) { // start looking for chunks ttaheader.Reset(); ttaheader.AudioFormat = source.ReadUInt16(); ttaheader.NumChannels = source.ReadUInt16(); ttaheader.BitsPerSample = source.ReadUInt16(); ttaheader.SampleRate = source.ReadUInt32(); ttaheader.DataLength = source.ReadUInt32(); ttaheader.CRC32 = source.ReadUInt32(); FFileSize = fs.Length; FValid = true; FAudioFormat = ttaheader.AudioFormat; FChannels = ttaheader.NumChannels; FBits = ttaheader.BitsPerSample; FSampleRate = ttaheader.SampleRate; FSamples = ttaheader.DataLength; FCRC32 = ttaheader.CRC32; FBitrate = (double)FFileSize * 8 / (FSamples / FSampleRate) / 1000; FDuration = (double)ttaheader.DataLength / ttaheader.SampleRate; result = true; } } catch (Exception e) { System.Console.WriteLine(e.StackTrace); result = false; } if (fs != null) { fs.Unlock(0, fs.Length); if (source != null) { source.Close(); } } return(result); }