private static byte[] ResamplePcm(ref byte[] toResample, ref int sourceLength, WaveFormat sourceFormat, WaveFormat destPcmFormat, out int resultLength) { Debug.Assert(destPcmFormat.Encoding == WaveFormatEncoding.Pcm, "Codec format must be PCM"); if (resampleRateStream != null && (!lastResampleSourceFormat.Equals(sourceFormat) || !lastResampleDestFormat.Equals(destPcmFormat))) { resampleRateStream.Dispose(); resampleRateStream = null; } if (resampleRateStream == null) { WaveFormat sourceRateFormat = new WaveFormat(sourceFormat.SampleRate, sourceFormat.BitsPerSample, destPcmFormat.Channels); resampleRateStream = new AcmStream(sourceRateFormat, destPcmFormat); if (sourceFormat.Channels != destPcmFormat.Channels) { WaveFormat destChanFormat = new WaveFormat(sourceFormat.SampleRate, sourceFormat.BitsPerSample, destPcmFormat.Channels); if (resampleChannelStream != null) { resampleChannelStream.Dispose(); } resampleChannelStream = new AcmStream(sourceFormat, destChanFormat); } lastResampleSourceFormat = sourceFormat; lastResampleDestFormat = destPcmFormat; } int bytesConverted; if (sourceFormat.Channels != destPcmFormat.Channels) { if (destPcmFormat.Channels == 1 && sourceFormat.Channels == 2) { toResample = MixStereoToMono(toResample, sourceLength); sourceLength = toResample.Length; } else { Buffer.BlockCopy(toResample, 0, resampleChannelStream.SourceBuffer, 0, sourceLength); sourceLength = resampleChannelStream.Convert(sourceLength, out bytesConverted); if (bytesConverted >> 1 != sourceLength) { Console.WriteLine("WARNING: All input bytes were not converted."); } toResample = resampleChannelStream.DestBuffer; } } Buffer.BlockCopy(toResample, 0, resampleRateStream.SourceBuffer, 0, sourceLength); resultLength = resampleRateStream.Convert(sourceLength, out bytesConverted); if (bytesConverted != sourceLength) { Console.WriteLine("WARNING: All input bytes were not converted."); return(null); } return(resampleRateStream.DestBuffer); }
/// <summary> /// Disposes this stream /// </summary> /// <param name="disposing">true if the user called this</param> protected override void Dispose(bool disposing) { if (disposing) { // Release managed resources. if (conversionStream != null) { conversionStream.Dispose(); conversionStream = null; } if (sourceStream != null) { sourceStream.Dispose(); sourceStream = null; } } else { System.Diagnostics.Debug.Assert(false, "WaveFormatConversionStream was not disposed"); } // Release unmanaged resources. // Set large fields to null. // Call Dispose on your base class. base.Dispose(disposing); }
public void Dispose() { if (conversionStream != null) { conversionStream.Dispose(); conversionStream = null; } }
/// <summary> /// Disposes this stream /// </summary> /// <param name="disposing">true if the user called this</param> protected virtual void Dispose(bool disposing) { if (!isDisposed) { isDisposed = true; conversionStream.Dispose(); } }
/// <summary> /// Disposes of this MP3 frame decompressor /// </summary> public void Dispose() { if (!disposed) { disposed = true; conversionStream.Dispose(); GC.SuppressFinalize(this); } }
public void Dispose() { if (encodeStream != null) { encodeStream.Dispose(); encodeStream = null; } if (decodeStream != null) { decodeStream.Dispose(); decodeStream = null; } }
public void Dispose() { if (_encodeStream != null) { _encodeStream.Dispose(); _encodeStream = null; } if (_decodeStream != null) { _decodeStream.Dispose(); _decodeStream = null; } }
public void Dispose() { if (_encoder != null) { _encoder.Dispose(); _encoder = null; } if (_decoder != null) { _decoder.Dispose(); _decoder = null; } }
protected virtual void Dispose(bool disposing) { if (!this.isDisposed) { this.isDisposed = true; AcmStream expr_15 = this.conversionStream; if (expr_15 == null) { return; } expr_15.Dispose(); } }
public void Dispose() { if (EncodeStream != null) { EncodeStream.Dispose(); EncodeStream = null; } if (DecodeStream == null) { return; } DecodeStream.Dispose(); DecodeStream = null; }