Exemplo n.º 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;
         var  Data       = new byte[CB_AUDIO * NSECTORS];
         bool Cont       = true;
         bool ReadOk     = true;
         if (ProgressEvent != null)
         {
             var 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)
             {
                 var dra = new DataReadEventArgs(Data, (uint)(CB_AUDIO * Sectors2Read));
                 DataReadEvent(this, dra);
                 BytesRead += (uint)(CB_AUDIO * Sectors2Read);
                 if (ProgressEvent != null)
                 {
                     var rpa = new ReadProgressEventArgs(Bytes2Read, BytesRead);
                     ProgressEvent(this, rpa);
                     Cont = !rpa.CancelRead;
                 }
             }
         }
         if (ReadOk)
         {
             return((int)BytesRead);
         }
         else
         {
             return(-1);
         }
     }
     else
     {
         return(-1);
     }
 }
Exemplo n.º 2
0
 public int ReadTrack(int track, CdDataReadEventHandler DataReadEvent, uint StartSecond, uint Seconds2Read, CdReadProgressEventHandler ProgressEvent)
 {
     if (((this.TocValid && (track >= this.Toc.FirstTrack)) && (track <= this.Toc.LastTrack)) && (DataReadEvent != null))
     {
         ReadProgressEventArgs args;
         int startSector = this.GetStartSector(track);
         int endSector   = this.GetEndSector(track);
         if ((startSector += ((int)(StartSecond * 0x4b))) >= endSector)
         {
             startSector -= (int)(StartSecond * 0x4b);
         }
         if ((Seconds2Read > 0) && ((startSector + ((int)(Seconds2Read * 0x4b))) < endSector))
         {
             endSector = startSector + ((int)(Seconds2Read * 0x4b));
         }
         uint   num3      = (uint)((endSector - startSector) * 0x930);
         uint   bytesread = 0;
         byte[] buffer    = new byte[0x7770];
         bool   flag      = true;
         bool   flag2     = true;
         if (ProgressEvent != null)
         {
             args = new ReadProgressEventArgs(num3, 0);
             ProgressEvent(this, args);
             flag = !args.CancelRead;
         }
         for (int i = startSector; ((i < endSector) && flag) && flag2; i += 13)
         {
             int numSectors = ((i + 13) < endSector) ? 13 : (endSector - i);
             flag2 = this.ReadSector(i, buffer, numSectors);
             if (flag2)
             {
                 DataReadEventArgs ea = new DataReadEventArgs(buffer, (uint)(0x930 * numSectors));
                 DataReadEvent(this, ea);
                 bytesread += (uint)(0x930 * numSectors);
                 if (ProgressEvent != null)
                 {
                     args = new ReadProgressEventArgs(num3, bytesread);
                     ProgressEvent(this, args);
                     flag = !args.CancelRead;
                 }
             }
         }
         if (flag2)
         {
             return((int)bytesread);
         }
         return(-1);
     }
     return(-1);
 }
        private void ReadAudioTrack(
            int track, ExtractionPaths paths, ProgressReporter progress)
        {
            Directory.CreateDirectory(paths.OutputDirectory);

            string     outputPath = GenerateOutputPath(paths, track - 1);
            ID3TagData metadata   = GenerateTrackMetadata(track - 1);

            using (var mp3Writer = new LameMP3FileWriter(
                       outputPath, new WaveFormat(), LAMEPreset.STANDARD, metadata))
            {
                CdDataReadEventHandler     onDataRead = (x, y) => OnDataRead(x, y, mp3Writer);
                CdReadProgressEventHandler onProgress = (x, y) => OnTrackProgress(x, y, progress);

                if (m_drive.ReadTrack(track, onDataRead, onProgress) == 0)
                {
                    throw new InvalidOperationException($"Cannot read track {track}");
                }
            }
        }
Exemplo n.º 4
0
 public int ReadTrack(int track, CdDataReadEventHandler DataReadEvent, CdReadProgressEventHandler ProgressEvent)
 {
     return(this.ReadTrack(track, DataReadEvent, 0, 0, ProgressEvent));
 }
Exemplo n.º 5
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="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, CdReadProgressEventHandler ProgressEvent)
 {
     return ReadTrack(track, DataReadEvent, 0, 0, ProgressEvent);
 }
Exemplo n.º 6
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;
         var Data = new byte[CB_AUDIO*NSECTORS];
         bool Cont = true;
         bool ReadOk = true;
         if (ProgressEvent != null)
         {
             var 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)
             {
                 var dra = new DataReadEventArgs(Data, (uint) (CB_AUDIO*Sectors2Read));
                 DataReadEvent(this, dra);
                 BytesRead += (uint) (CB_AUDIO*Sectors2Read);
                 if (ProgressEvent != null)
                 {
                     var rpa = new ReadProgressEventArgs(Bytes2Read, BytesRead);
                     ProgressEvent(this, rpa);
                     Cont = !rpa.CancelRead;
                 }
             }
         }
         if (ReadOk)
         {
             return (int) BytesRead;
         }
         else
         {
             return -1;
         }
     }
     else
     {
         return -1;
     }
 }
Exemplo n.º 7
0
 public int ReadTrack(int track, CdDataReadEventHandler DataReadEvent, uint StartSecond, uint Seconds2Read, CdReadProgressEventHandler ProgressEvent)
 {
     if (((this.TocValid && (track >= this.Toc.FirstTrack)) && (track <= this.Toc.LastTrack)) && (DataReadEvent != null))
     {
         ReadProgressEventArgs args;
         int startSector = this.GetStartSector(track);
         int endSector = this.GetEndSector(track);
         if ((startSector += ((int)(StartSecond * 0x4b))) >= endSector)
         {
             startSector -= (int)(StartSecond * 0x4b);
         }
         if ((Seconds2Read > 0) && ((startSector + ((int)(Seconds2Read * 0x4b))) < endSector))
         {
             endSector = startSector + ((int)(Seconds2Read * 0x4b));
         }
         uint num3 = (uint)((endSector - startSector) * 0x930);
         uint bytesread = 0;
         byte[] buffer = new byte[0x7770];
         bool flag = true;
         bool flag2 = true;
         if (ProgressEvent != null)
         {
             args = new ReadProgressEventArgs(num3, 0);
             ProgressEvent(this, args);
             flag = !args.CancelRead;
         }
         for (int i = startSector; ((i < endSector) && flag) && flag2; i += 13)
         {
             int numSectors = ((i + 13) < endSector) ? 13 : (endSector - i);
             flag2 = this.ReadSector(i, buffer, numSectors);
             if (flag2)
             {
                 DataReadEventArgs ea = new DataReadEventArgs(buffer, (uint)(0x930 * numSectors));
                 DataReadEvent(this, ea);
                 bytesread += (uint)(0x930 * numSectors);
                 if (ProgressEvent != null)
                 {
                     args = new ReadProgressEventArgs(num3, bytesread);
                     ProgressEvent(this, args);
                     flag = !args.CancelRead;
                 }
             }
         }
         if (flag2)
         {
             return (int)bytesread;
         }
         return -1;
     }
     return -1;
 }
Exemplo n.º 8
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;
                }

                /////////////START NORMALISIEREN
                // Normalisieren?
                double normFactor = 0;
                int    maxValue   = 0;
                if (Big3.Hitbase.Configuration.Settings.Current.NormalizeActive)
                {
                    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)
                        {
                            BytesRead += (uint)(CB_AUDIO * Sectors2Read);

                            for (int i = 0; i < Data.Length; i += 2)
                            {
                                int intValue = (int)(short)(Data[i + 1] * 256 + Data[i]);
                                if (Math.Abs(intValue) > maxValue)
                                {
                                    maxValue = Math.Abs(intValue);
                                }
                            }

                            if (ProgressEvent != null)
                            {
                                ReadProgressEventArgs rpa = new ReadProgressEventArgs(Bytes2Read, BytesRead);
                                ProgressEvent(this, rpa);
                                Cont = !rpa.CancelRead;
                            }
                        }
                    }

                    normFactor = 32768.0 / (double)maxValue;
                }
                /////////////ENDE NORMALISIEREN


                BytesRead = 0;

                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)
                    {
                        if (Big3.Hitbase.Configuration.Settings.Current.NormalizeActive)
                        {
                            for (int i = 0; i < Data.Length; i += 2)
                            {
                                int    intValue        = (int)(short)(Data[i + 1] * 256 + Data[i]);
                                int    normalizedValue = (int)((double)intValue * normFactor);
                                byte[] shortValues     = BitConverter.GetBytes((short)normalizedValue);
                                Data[i + 1] = shortValues[1];
                                Data[i]     = shortValues[0];
                            }
                        }


                        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);
            }
        }