Example #1
0
        /// <summary>
        /// WaveStream to resample using the DMO Resampler
        /// </summary>
        /// <param name="inputProvider">Input Stream</param>
        /// <param name="outputFormat">Desired Output Format</param>
        public ResamplerDmoStream(IWaveProvider inputProvider, WaveFormat outputFormat)
        {
            this.inputProvider = inputProvider;
            this.inputStream = inputProvider as WaveStream;
            this.outputFormat = outputFormat;
            this.dmoResampler = new DmoResampler();
            if (!dmoResampler.MediaObject.SupportsInputWaveFormat(0, inputProvider.WaveFormat))
            {
                throw new ArgumentException("Unsupported Input Stream format", "inputStream");
            }

            dmoResampler.MediaObject.SetInputWaveFormat(0, inputProvider.WaveFormat);
            if (!dmoResampler.MediaObject.SupportsOutputWaveFormat(0, outputFormat))
            {
                throw new ArgumentException("Unsupported Output Stream format", "outputStream");
            }

            dmoResampler.MediaObject.SetOutputWaveFormat(0, outputFormat);
            if (inputStream != null)
            {
                position = InputToOutputPosition(inputStream.Position);
            }
            this.inputMediaBuffer = new MediaBuffer(inputProvider.WaveFormat.AverageBytesPerSecond);
            this.outputBuffer = new DmoOutputDataBuffer(outputFormat.AverageBytesPerSecond);
        }
        /// <summary>
        /// Initializes a new instance of the DMO MP3 Frame decompressor
        /// </summary>
        /// <param name="sourceFormat"></param>
        public DmoMp3FrameDecompressor(WaveFormat sourceFormat)
        {
            this.mp3Decoder = new WindowsMediaMp3Decoder();
            if (!mp3Decoder.MediaObject.SupportsInputWaveFormat(0, sourceFormat))
            {
                throw new ArgumentException("Unsupported input format");
            }
            mp3Decoder.MediaObject.SetInputWaveFormat(0, sourceFormat);
            pcmFormat = new WaveFormat(sourceFormat.SampleRate, sourceFormat.Channels); // 16 bit
            if (!mp3Decoder.MediaObject.SupportsOutputWaveFormat(0, pcmFormat))
            {
                throw new ArgumentException(String.Format("Unsupported output format {0}", pcmFormat));
            }
            mp3Decoder.MediaObject.SetOutputWaveFormat(0, pcmFormat);

            // a second is more than enough to decompress a frame at a time
            inputMediaBuffer = new MediaBuffer(sourceFormat.AverageBytesPerSecond);
            outputBuffer = new DmoOutputDataBuffer(pcmFormat.AverageBytesPerSecond);
        }
Example #3
0
 /// <summary>
 /// Dispose
 /// </summary>
 /// <param name="disposing">True if disposing (not from finalizer)</param>
 protected override void Dispose(bool disposing)
 {
     if (inputMediaBuffer != null)
     {
         inputMediaBuffer.Dispose();
         inputMediaBuffer = null;
     }
     outputBuffer.Dispose();
     if (dmoResampler != null)
     {
         //resampler.Dispose(); s
         dmoResampler = null;
     }
     base.Dispose(disposing);
 }
 /// <summary>
 /// Dispose of this obejct and clean up resources
 /// </summary>
 public void Dispose()
 {
     if (inputMediaBuffer != null)
     {
         inputMediaBuffer.Dispose();
         inputMediaBuffer = null;
     }
     outputBuffer.Dispose();
     if (mp3Decoder!= null)
     {
         mp3Decoder.Dispose();
         mp3Decoder = null;
     }
 }