示例#1
0
        /// <summary>
        /// Read the digital data of the track
        /// </summary>
        /// <param name="track">Track to read</param>
        /// <param name="OnDataRead">Call each time data is read</param>
        /// <param name="StartSecond">First second of the track to read, 0 means to start at beginning of the track</param>
        /// <param name="Seconds2Read">Number of seconds to read, 0 means to read until the end of the track</param>
        /// <param name="OnProgress">Delegate to indicate the reading progress</param>
        /// <returns>Negative value means an error. On success returns the number of bytes read</returns>
        public int ReadTrack(int track, CdDataReadEventHandler DataReadEvent, uint StartSecond, uint Seconds2Read, CdReadProgressEventHandler ProgressEvent)
        {
            if ( TocValid && (track >= Toc.FirstTrack) && (track <= Toc.LastTrack) && (DataReadEvent != null) )
              {
            int StartSect = GetStartSector(track);
            int EndSect = GetEndSector(track);
            if ( (StartSect += (int)StartSecond*75) >= EndSect )
            {
              StartSect -= (int)StartSecond*75;
            }
            if ( (Seconds2Read > 0) && ( (int)(StartSect + Seconds2Read*75) < EndSect ) )
            {
              EndSect = StartSect + (int)Seconds2Read*75;
            }
            uint Bytes2Read = (uint)(EndSect - StartSect)*CB_AUDIO;
            uint BytesRead = 0;
            byte[] Data = new byte[CB_AUDIO*NSECTORS];
            bool Cont = true;
            bool ReadOk = true;
            if ( ProgressEvent != null )
            {
              ReadProgressEventArgs rpa = new ReadProgressEventArgs(Bytes2Read, 0);
              ProgressEvent(this, rpa);
              Cont = !rpa.CancelRead;
            }
            for (int sector = StartSect; (sector < EndSect) && (Cont) && (ReadOk); sector+=NSECTORS)
            {
              int Sectors2Read = ( (sector + NSECTORS) < EndSect )?NSECTORS:(EndSect-sector);
              ReadOk = ReadSector(sector, Data, Sectors2Read);
              if ( ReadOk )
              {
            DataReadEventArgs dra = new DataReadEventArgs(Data, (uint)(CB_AUDIO*Sectors2Read));
            DataReadEvent(this, dra);
            BytesRead += (uint)(CB_AUDIO*Sectors2Read);
            if ( ProgressEvent != null )
            {
              ReadProgressEventArgs rpa = new ReadProgressEventArgs(Bytes2Read, BytesRead);
              ProgressEvent(this, rpa);
              Cont = !rpa.CancelRead;
            }
              }
            }
            if ( ReadOk )
            {
              return (int)BytesRead;
            }
            else
            {
              return -1;
            }

              }
              else
              {
            return -1;
              }
        }
示例#2
0
 public void OnCdDataRead(object sender, DataReadEventArgs ea)
 {
     Buffer.BlockCopy(ea.Data, 0, BufferArray, WritePosition, (int)ea.DataSize);
       WritePosition += (int)ea.DataSize;
 }