private StepDetail ProcessTrack(Track track) { string newFileName = string.Format("{0}.{1}", CdRipper.GetFileName(WordCasing.KeepCase, track, OutputFilePattern), this.EncoderSettings.AudioMediaFormatType.ToString().ToLowerInvariant()); StepDetail detail = new StepDetail(); detail.Description = Translator.Translate("TXT_PROCESSING_TRACK", track, newFileName); RaiseTaskStepInitEvent(detail); detail.Results = Translator.Translate("TXT_UNHANDLED"); detail.IsSuccess = false; try { _grabber = CdRipper.CreateGrabber(this.EncoderSettings.AudioMediaFormatType); char letter = Drive.RootDirectory.FullName.ToUpperInvariant()[0]; using (CDDrive cd = new CDDrive()) { if (cd.Open(letter) && cd.Refresh() && cd.HasAudioTracks()) { string destFile = Path.Combine(OutputFolder, newFileName); bool generateTagsFromMetadata = false; switch (this.EncoderSettings.AudioMediaFormatType) { case AudioMediaFormatType.WAV: break; case AudioMediaFormatType.MP3: (_grabber as GrabberToMP3).Mp3ConversionOptions = this.EncoderSettings.Mp3EncoderSettings.Mp3ConversionOptions; generateTagsFromMetadata = this.EncoderSettings.Mp3EncoderSettings.GenerateTagsFromTrackMetadata; break; } _grabber.Grab(cd, track, destFile, generateTagsFromMetadata); } } detail.IsSuccess = true; } catch (Exception ex) { detail.Results = ex.Message; } return detail; }
public void DoTranscoding(EncoderSettingsContainer encoderSettings, string inputFile) { _grabber = CdRipper.CreateGrabber(OutputFormat); if (_grabber == null) throw new NotSupportedException(string.Format("TXT_UNSUPPORTED_OUTPUT_FORMAT: {0}", InputFormat)); switch (InputFormat) { case AudioMediaFormatType.WAV: switch (OutputFormat) { case AudioMediaFormatType.MP3: { // Transcode WAV => MP3 i.o.w encode the wav WaveFormatEx wfex = WaveFormatEx.Cdda; byte[] buff = ReadWAV(inputFile, ref wfex); GrabberToMP3 grabber = (_grabber as GrabberToMP3); grabber.Mp3ConversionOptions = encoderSettings.Mp3EncoderSettings.Mp3ConversionOptions; // Resample is not supported at this time. // Specify the same sample rate as the input WAV file, otherwise we'll be failing. grabber.Mp3ConversionOptions.format.dwSampleRate = (uint)wfex.nSamplesPerSec; grabber.EncodeBuffer(buff, Path.ChangeExtension(inputFile, "MP3"), false, null); return; } } break; case AudioMediaFormatType.MP3: switch (OutputFormat) { case AudioMediaFormatType.WAV: // Transcode MP3 => WAV i.o.w decode the MP3 string outputFile = Path.ChangeExtension(inputFile, "WAV"); if (DecodeMP3ToWAV(inputFile, outputFile) == false) throw new Exception("TXT_FAILED_CONVERSION_MP3_WAV"); return; case AudioMediaFormatType.MP3: { // Transcode MP3 => MP3 i.o.w adjust MP3 encoding string tempWavFile = Path.GetTempFileName(); if (DecodeMP3ToWAV(inputFile, tempWavFile) == false) throw new Exception("TXT_FAILED_CONVERSION_MP3_TEMP_WAV"); WaveFormatEx wfex = WaveFormatEx.Cdda; byte[] buff = ReadWAV(tempWavFile, ref wfex); GrabberToMP3 grabber = (_grabber as GrabberToMP3); grabber.Mp3ConversionOptions = encoderSettings.Mp3EncoderSettings.Mp3ConversionOptions; ID3FileInfoSlim ifiSlim = new ID3FileInfoSlim(MediaFileInfo.FromPath(inputFile, false)); grabber.EncodeBuffer(buff, Path.ChangeExtension(inputFile, "REENC.MP3"), encoderSettings.Mp3EncoderSettings.GenerateTagsFromTrackMetadata, ifiSlim); return; } } break; } throw new NotSupportedException(string.Format("TXT_UNSUPPORTED_TRANSCODING: {0}", this)); }