Beispiel #1
0
        protected override bool read(BinaryReader source, ReadTagParams readTagParams)
        {
            bool      result = true;
            SPCHeader header = new SPCHeader();
            SPCExTags footer = new SPCExTags();

            header.Reset();
            footer.Reset();
            resetData();

            source.BaseStream.Seek(sizeInfo.ID3v2Size, SeekOrigin.Begin);

            if (!readHeader(source, ref header))
            {
                throw new InvalidDataException("Not a SPC file");
            }

            // Reads the header tag
            if (SPCHeader.TAG_IN_HEADER == header.TagInHeader)
            {
                tagExists = true;
                source.BaseStream.Seek(REGISTERS_LENGTH, SeekOrigin.Current);
                readHeaderTags(source, ref header, readTagParams);
            }

            AudioDataOffset = source.BaseStream.Position;

            // Reads extended tag
            if (source.BaseStream.Length > SPC_RAW_LENGTH)
            {
                source.BaseStream.Seek(SPC_RAW_LENGTH, SeekOrigin.Begin);
                readExtendedData(source, ref footer, readTagParams);
            }
            else
            {
                if (readTagParams.PrepareForWriting)
                {
                    structureHelper.AddZone(SPC_RAW_LENGTH, 0, ZONE_EXTENDED);
                }
            }

            AudioDataSize = sizeInfo.FileSize - header.Size - footer.Size;
            bitrate       = AudioDataSize * 8 / duration;

            return(result);
        }
Beispiel #2
0
        protected override Boolean read(BinaryReader source, MetaDataIO.ReadTagParams readTagParams)
        {
            var result = true;
            var header = new SPCHeader();
            var footer = new SPCExTags();

            header.Reset();
            footer.Reset();
            resetData();

            source.BaseStream.Seek(sizeInfo.ID3v2Size, SeekOrigin.Begin);

            isValid = readHeader(source, ref header);
            if (!isValid)
            {
                throw new Exception("Not a SPC file");
            }

            // Reads the header tag
            if (SPCHeader.TAG_IN_HEADER == header.TagInHeader)
            {
                tagExists = true;
                source.BaseStream.Seek(REGISTERS_LENGTH, SeekOrigin.Current);
                readHeaderTags(source, ref header, readTagParams);
            }

            // Reads extended tag
            if (source.BaseStream.Length > SPC_RAW_LENGTH)
            {
                source.BaseStream.Seek(SPC_RAW_LENGTH, SeekOrigin.Begin);
                readExtendedData(source, ref footer, readTagParams);
            }
            else
            {
                if (readTagParams.PrepareForWriting)
                {
                    structureHelper.AddZone(SPC_RAW_LENGTH, 0, ZONE_EXTENDED);
                }
            }

            bitrate = (sizeInfo.FileSize - header.Size) * 8 / duration;

            return(result);
        }
Beispiel #3
0
        // === PUBLIC METHODS ===

        public bool ReadFromFile(String fileName)
        {
            bool      result = true;
            SPCHeader header = new SPCHeader();
            SPCExTags footer = new SPCExTags();

            FResetData();

            header.Reset();
            footer.Reset();

            FileStream   fs     = null;
            BinaryReader source = null;

            try
            {
                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                fs.Lock(0, fs.Length);
                source = new BinaryReader(fs);

                if (!readHeader(ref source, ref header))
                {
                    throw new Exception("Not a PSF file");
                }

                // Reads the header tag
                if (SPCHeader.TAG_IN_HEADER == header.TagInHeader)
                {
                    source.BaseStream.Seek(REGISTERS_LENGTH, SeekOrigin.Current);
                    readHeaderTags(ref source);
                }

                // Reads extended tag
                if (fs.Length > SPC_RAW_LENGTH)
                {
                    source.BaseStream.Seek(SPC_RAW_LENGTH, SeekOrigin.Begin);
                    readExtendedData(ref source, ref footer);

                    if (footer.Items.ContainsKey(XID6_ARTIST))
                    {
                        FArtist = (String)((ExtendedItem)footer.Items[XID6_ARTIST]).Data;
                    }
                    if (footer.Items.ContainsKey(XID6_CMNTS))
                    {
                        FComment = (String)((ExtendedItem)footer.Items[XID6_CMNTS]).Data;
                    }
                    if (footer.Items.ContainsKey(XID6_SONG))
                    {
                        FTitle = (String)((ExtendedItem)footer.Items[XID6_SONG]).Data;
                    }
                    if (footer.Items.ContainsKey(XID6_COPY))
                    {
                        FYear = ((ExtendedItem)footer.Items[XID6_COPY]).Length.ToString();
                    }
                    if (footer.Items.ContainsKey(XID6_TRACK))
                    {
                        FTrack = ((ExtendedItem)footer.Items[XID6_TRACK]).Length >> 8;
                    }
                    if (footer.Items.ContainsKey(XID6_OST))
                    {
                        FAlbum = (String)((ExtendedItem)footer.Items[XID6_OST]).Data;
                    }
                    if (("" == FAlbum) && (footer.Items.ContainsKey(XID6_GAME)))
                    {
                        FAlbum = (String)((ExtendedItem)footer.Items[XID6_GAME]).Data;
                    }

                    long ticks = 0;
                    if (footer.Items.ContainsKey(XID6_LOOP))
                    {
                        ticks += Math.Min(XID6_MAXTICKS, (int)((ExtendedItem)footer.Items[XID6_LOOP]).Data);
                    }
                    if (footer.Items.ContainsKey(XID6_LOOPX))
                    {
                        ticks = ticks * Math.Min(XID6_MAXLOOP, (int)((ExtendedItem)footer.Items[XID6_LOOPX]).Length);
                    }
                    if (footer.Items.ContainsKey(XID6_INTRO))
                    {
                        ticks += Math.Min(XID6_MAXTICKS, (int)((ExtendedItem)footer.Items[XID6_INTRO]).Data);
                    }
                    if (footer.Items.ContainsKey(XID6_END))
                    {
                        ticks += Math.Min(XID6_MAXTICKS, (int)((ExtendedItem)footer.Items[XID6_END]).Data);
                    }

                    if (ticks > 0)
                    {
                        FDuration = Math.Round((double)ticks / XID6_TICKSSEC);
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.StackTrace);
                //LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            if (fs != null)
            {
                fs.Unlock(0, fs.Length);
                fs.Close();
            }

            return(result);
        }
Beispiel #4
0
		// === PUBLIC METHODS ===

		public bool ReadFromFile(String fileName)
		{
			bool result = true;
			SPCHeader header = new SPCHeader();
			SPCExTags footer = new SPCExTags();

			FResetData();
			
			header.Reset();
			footer.Reset();

			FileStream fs = null;
			BinaryReader source = null;

			try
			{
				fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
				fs.Lock(0,fs.Length);
				source = new BinaryReader(fs);

				if ( !readHeader(ref source, ref header) ) throw new Exception("Not a PSF file");

				// Reads the header tag
				if (SPCHeader.TAG_IN_HEADER == header.TagInHeader)
				{
					source.BaseStream.Seek(REGISTERS_LENGTH,SeekOrigin.Current);
					readHeaderTags(ref source);
				}

				// Reads extended tag
				if (fs.Length > SPC_RAW_LENGTH)
				{
					source.BaseStream.Seek(SPC_RAW_LENGTH,SeekOrigin.Begin);
					readExtendedData(ref source, ref footer);
					
					if (footer.Items.ContainsKey(XID6_ARTIST)) FArtist = (String)((ExtendedItem)footer.Items[XID6_ARTIST]).Data;
					if (footer.Items.ContainsKey(XID6_CMNTS)) FComment = (String)((ExtendedItem)footer.Items[XID6_CMNTS]).Data;
					if (footer.Items.ContainsKey(XID6_SONG)) FTitle = (String)((ExtendedItem)footer.Items[XID6_SONG]).Data;
					if (footer.Items.ContainsKey(XID6_COPY)) FYear = ((ExtendedItem)footer.Items[XID6_COPY]).Length.ToString();
					if (footer.Items.ContainsKey(XID6_TRACK)) FTrack = ((ExtendedItem)footer.Items[XID6_TRACK]).Length >> 8;
					if (footer.Items.ContainsKey(XID6_OST)) FAlbum = (String)((ExtendedItem)footer.Items[XID6_OST]).Data;
					if (("" == FAlbum) && (footer.Items.ContainsKey(XID6_GAME))) FAlbum = (String)((ExtendedItem)footer.Items[XID6_GAME]).Data;
					
					long ticks = 0;
					if (footer.Items.ContainsKey(XID6_LOOP)) ticks += Math.Min(XID6_MAXTICKS, (int)((ExtendedItem)footer.Items[XID6_LOOP]).Data);
					if (footer.Items.ContainsKey(XID6_LOOPX)) ticks = ticks * Math.Min(XID6_MAXLOOP, (int)((ExtendedItem)footer.Items[XID6_LOOPX]).Length );
					if (footer.Items.ContainsKey(XID6_INTRO)) ticks += Math.Min(XID6_MAXTICKS, (int)((ExtendedItem)footer.Items[XID6_INTRO]).Data);
					if (footer.Items.ContainsKey(XID6_END)) ticks += Math.Min(XID6_MAXTICKS, (int)((ExtendedItem)footer.Items[XID6_END]).Data);
					
					if (ticks > 0)
						FDuration = Math.Round( (double)ticks / XID6_TICKSSEC );
				}
			}
			catch (Exception e) 
			{
				System.Console.WriteLine(e.StackTrace);
				//LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
				result = false;
			}

			if (fs != null)
			{
				fs.Unlock(0,fs.Length);
				fs.Close();
			}

			return result;
		}