Exemple #1
0
        private void ReadCDTextInformation(CDInfo cdInfo)
        {
            if (Settings.Current.DisableCDText)
            {
                return;
            }

            CDDrive cdDrive = new CDDrive();

            cdDrive.Open(CDEngine.DriveLetter);

            Ripper ripper = new Ripper(cdDrive);

            ripper.ReadCDText(CD);

            cdDrive.Close();
        }
        private static void SaveTrack(TrackInfo trackInfo)
        {
            string targetFileName = trackInfo.MusicTag.Title;

            if (m_Drive.Open(trackInfo.Item.Path[0]))
            {
                char[] Drives = CDDrive.GetCDDriveLetters();
                if ((Array.IndexOf(Drives, trackInfo.Item.Path[0]) > -1) && (m_Drive.IsCDReady()) && (m_Drive.Refresh()))
                {
                    try
                    {
                        m_Drive.LockCD();
                        if (dlgProgress.IsCanceled)
                        {
                            m_CancelRipping = true;
                        }
                        if (!m_CancelRipping)
                        {
                            try
                            {
                                try
                                {
                                    WaveFormat Format    = new WaveFormat(44100, 16, 2);
                                    BE_CONFIG  mp3Config = new BE_CONFIG(Format);
                                    if (mp3VBR)
                                    {
                                        mp3Config.format.lhv1.bEnableVBR = 1;
                                        if (mp3FastMode)
                                        {
                                            mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NEW;
                                        }
                                        else
                                        {
                                            mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_DEFAULT;
                                        }
                                        mp3Config.format.lhv1.nVBRQuality = mp3Quality;
                                    }
                                    else if (mp3CBR)
                                    {
                                        mp3Config.format.lhv1.bEnableVBR = 0;
                                        mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NONE;
                                        mp3Config.format.lhv1.dwBitrate  = Convert.ToUInt16(Rates[mp3BitRate]);
                                    }
                                    else
                                    {
                                        mp3Config.format.lhv1.bEnableVBR = 1;
                                        mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_ABR;
                                        uint ConToKbwVbrAbr_bps = Convert.ToUInt16(Rates[mp3BitRate]);
                                        mp3Config.format.lhv1.dwVbrAbr_bps = ConToKbwVbrAbr_bps * 1000;
                                    }

                                    if (mp3MONO)
                                    {
                                        mp3Config.format.lhv1.nMode = MpegMode.MONO;
                                    }

                                    mp3Config.format.lhv1.bWriteVBRHeader = 1;

                                    Stream WaveFile = new FileStream(trackInfo.TempFileName, FileMode.Create, FileAccess.Write);
                                    m_Writer = new Mp3Writer(WaveFile, Format, mp3Config);
                                    if (!m_CancelRipping)
                                    {
                                        try
                                        {
                                            Log.Info("CDIMP: Processing track {0}", trackInfo.MusicTag.Track);

                                            DateTime InitTime = DateTime.Now;
                                            if (
                                                m_Drive.ReadTrack(trackInfo.MusicTag.Track, new CdDataReadEventHandler(WriteWaveData),
                                                                  new CdReadProgressEventHandler(CdReadProgress)) > 0)
                                            {
                                                if (dlgProgress.IsCanceled)
                                                {
                                                    m_CancelRipping = true;
                                                }
                                                if (!m_CancelRipping)
                                                {
                                                    TimeSpan Duration = DateTime.Now - InitTime;
                                                    double   Speed    = m_Drive.TrackSize(trackInfo.MusicTag.Track) / Duration.TotalSeconds /
                                                                        Format.nAvgBytesPerSec;
                                                    Log.Info("CDIMP: Done reading track {0} at {1:0.00}x speed", trackInfo.MusicTag.Track, Speed);
                                                }
                                            }
                                            else
                                            {
                                                Log.Info("CDIMP: Error reading track {0}", trackInfo.MusicTag.Track);
                                                m_Writer.Close();
                                                WaveFile.Close();
                                                if (File.Exists(trackInfo.TempFileName))
                                                {
                                                    try
                                                    {
                                                        File.Delete(trackInfo.TempFileName);
                                                    }
                                                    catch {}
                                                }
                                                //progressBar1.Value = 0;
                                            }
                                        }
                                        finally
                                        {
                                            m_Writer.Close();
                                            m_Writer = null;
                                            WaveFile.Close();
                                            Lame_encDll.beWriteVBRHeader(trackInfo.TempFileName);
                                        }
                                    }
                                }
                                finally {}
                            }
                            finally
                            {
                                m_Drive.Close();
                            }
                        }
                    }
                    finally
                    {
                        //progressBar1.Value = 0;
                    }
                }
                if (dlgProgress.IsCanceled)
                {
                    m_CancelRipping = true;
                }
                if (m_CancelRipping)
                {
                    if (File.Exists(trackInfo.TempFileName))
                    {
                        File.Delete(trackInfo.TempFileName);
                    }
                    m_Drive.Close();
                }
            }
        }