public void Encode()
        {
            if (this.trackGain == null && this.drMeter == null)
            {
                throw new SkipEncodingItemException("Neither ReplayGain nor DynamicRange to calculate.");
            }

            AudioBuffer buffer = new AudioBuffer(audioSource.PCM, FileEncoderBase.BufferSize);

            while (audioSource.Read(buffer, FileEncoderBase.BufferSize) > 0)
            {
                if (this.trackGain != null)
                {
                    DspHelper.AnalyzeSamples(this.trackGain, buffer);
                }
                if (this.drMeter != null)
                {
                    this.drMeter.Feed(buffer.Samples, buffer.Length);
                }

                ProgressChangedEventArgs eventArgs = new ProgressChangedEventArgs((double)this.audioSource.Position / this.audioSource.Length);
                this.OnProgressChanged(eventArgs);
                if (eventArgs.Cancel)
                {
                    this.trackGain = null;
                    this.drMeter = null;
                    return;
                }
            }

            if (this.drMeter != null)
            {
                this.drMeter.Finish();
            }
        }
 public RemoteMp3VbrEncoder(IPAddress remoteAddress, IAudioSource audioSource, string targetFilename, AudioFileTag tags, int vbrQuality, TrackGain trackGain, DrMeter drMeter)
     : base(audioSource, targetFilename, tags, trackGain, drMeter)
 {
     this.AudioDest = new RemoteMp3VbrWriter(remoteAddress, targetFilename, audioSource.PCM)
     {
         CompressionLevel = vbrQuality
     };
 }
 public RemoteFlacEncoder(IPAddress remoteAddress, IAudioSource audioSource, string targetFilename, AudioFileTag tags, int compressionLevel, TrackGain trackGain, DrMeter drMeter)
     : base(audioSource, targetFilename, tags, trackGain, drMeter)
 {
     this.AudioDest = new RemoteFlacWriter(remoteAddress, targetFilename, audioSource.PCM)
     {
         CompressionLevel = compressionLevel
     };
 }
 public LocalMp3Encoder(IAudioSource audioSource, string targetFilename, AudioFileTag tags, int vbrQuality, TrackGain trackGain, DrMeter drMeter)
     : base(audioSource, targetFilename, tags, trackGain, drMeter)
 {
     this.AudioDest = new LameWriter(targetFilename, audioSource.PCM)
     {
         Settings = LameWriterSettings.CreateVbr(vbrQuality)
     };
 }
 public CueToolsFlacEncoder(IAudioSource audioSource, string targetFilename, AudioFileTag tags, int compressionLevel, TrackGain trackGain, DrMeter drMeter)
     : base(audioSource, targetFilename, tags, trackGain, drMeter)
 {
     this.AudioDest = new FLACWriter(targetFilename, audioSource.PCM)
     {
         CompressionLevel = compressionLevel
     };
 }
Example #6
0
 /// <summary>
 /// After calculating the ReplayGain data for an album, call this to append the data to the album.
 /// </summary>
 public void AppendTrackData(TrackGain trackGain)
 {
     int[] sourceAccum = trackGain.gainData.Accum;
     for (int i = 0; i < sourceAccum.Length; ++i)
     {
         this.albumData.Accum[i] += sourceAccum[i];
     }
     this.albumData.PeakSample = Math.Max(this.albumData.PeakSample, trackGain.gainData.PeakSample);
 }
Example #7
0
 /// <summary>
 /// After calculating the ReplayGain data for an album, call this to append the data to the album.
 /// </summary>
 public void AppendTrackData(TrackGain trackGain)
 {
     int[] sourceAccum = trackGain.gainData.Accum;
     for (int i = 0; i < sourceAccum.Length; ++i)
     {
         this.albumData.Accum[i] += sourceAccum[i];
     }
     this.albumData.PeakSample = Math.Max(this.albumData.PeakSample, trackGain.gainData.PeakSample);
 }
Example #8
0
 public static void AnalyzeSamples(TrackGain trackGain, AudioBuffer buffer)
 {
     int[] leftSamples = new int[buffer.Length];
     int[] rightSamples = new int[buffer.Length];
     for (int j = 0; j < buffer.Length; ++j)
     {
         leftSamples[j] = buffer.Samples[j, 0];
         rightSamples[j] = buffer.Samples[j, 1];
     }
     trackGain.AnalyzeSamples(leftSamples, rightSamples);
 }
        public FileEncoderBase(IAudioSource audioSource, string targetFilename, AudioFileTag tags, TrackGain trackGain, DrMeter drMeter)
        {
            if (audioSource == null)
            {
                throw new SkipEncodingItemException("Unsupported audio source.");
            }

            this.targetFilename = targetFilename;
            this.audioSource = audioSource;
            Directory.CreateDirectory(Path.GetDirectoryName(this.targetFilename));
            this.tags = tags;
            this.trackGain = trackGain;
            this.drMeter = drMeter;
        }
 public DspCalculatorEncoder(IAudioSource audioSource, TrackGain trackGain, DrMeter drMeter)
 {
     this.audioSource = audioSource;
     this.trackGain = trackGain;
     this.drMeter = drMeter;
 }