/// <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.resampler = new Resampler(); if (!resampler.MediaObject.SupportsInputWaveFormat(0, inputProvider.WaveFormat)) { throw new ArgumentException("Unsupported Input Stream format", "inputStream"); } resampler.MediaObject.SetInputWaveFormat(0, inputProvider.WaveFormat); if (!resampler.MediaObject.SupportsOutputWaveFormat(0, outputFormat)) { throw new ArgumentException("Unsupported Output Stream format", "outputStream"); } resampler.MediaObject.SetOutputWaveFormat(0, outputFormat); if (inputStream != null) { position = InputToOutputPosition(inputStream.Position); } this.inputMediaBuffer = new MediaBuffer(inputProvider.WaveFormat.AverageBytesPerSecond); this.outputBuffer = new DmoOutputDataBuffer(outputFormat.AverageBytesPerSecond); }
public void ResamplerCanCallProcessInput() { Resampler resampler = new Resampler(); resampler.MediaObject.SetInputWaveFormat(0, WaveFormat.CreateIeeeFloatWaveFormat(44100, 2)); resampler.MediaObject.SetOutputWaveFormat(0, WaveFormat.CreateIeeeFloatWaveFormat(48000, 2)); using (MediaBuffer buffer = new MediaBuffer(44100 * 2 * 4)) { buffer.Length = 8000; resampler.MediaObject.ProcessInput(0, buffer, DmoInputDataBufferFlags.None, 0, 0); } }
public void CanExamineOutputTypesOnResampler() { Resampler resampler = new Resampler(); Assert.AreEqual(resampler.MediaObject.OutputStreamCount, 1); foreach (DmoMediaType mediaType in resampler.MediaObject.GetOutputTypes(0)) { Console.WriteLine(String.Format("{0}:{1}:{2}", mediaType.MajorTypeName, mediaType.SubTypeName, mediaType.FormatTypeName)); } }
public void ResamplerCanCallProcessOutput() { Resampler resampler = new Resampler(); WaveFormat inputFormat = WaveFormat.CreateIeeeFloatWaveFormat(44100, 2); WaveFormat outputFormat = WaveFormat.CreateIeeeFloatWaveFormat(48000, 2); resampler.MediaObject.SetInputWaveFormat(0, inputFormat); resampler.MediaObject.SetOutputWaveFormat(0, outputFormat); resampler.MediaObject.AllocateStreamingResources(); using (MediaBuffer inputBuffer = new MediaBuffer(inputFormat.AverageBytesPerSecond)) { inputBuffer.Length = inputFormat.AverageBytesPerSecond / 10; Debug.WriteLine(String.Format("Input Length {0}", inputBuffer.Length)); resampler.MediaObject.ProcessInput(0, inputBuffer, DmoInputDataBufferFlags.None, 0, 0); Debug.WriteLine(String.Format("Input Length {0}", inputBuffer.Length)); Debug.WriteLine(String.Format("Input Lookahead {0}", resampler.MediaObject.GetInputSizeInfo(0).MaxLookahead)); //Debug.WriteLine(String.Format("Input Max Latency {0}", resampler.MediaObject.GetInputMaxLatency(0))); using (DmoOutputDataBuffer outputBuffer = new DmoOutputDataBuffer(outputFormat.AverageBytesPerSecond)) { // one buffer for each output stream resampler.MediaObject.ProcessOutput(DmoProcessOutputFlags.None, 1, new DmoOutputDataBuffer[] { outputBuffer }); Debug.WriteLine(String.Format("Converted length: {0}", outputBuffer.Length)); Debug.WriteLine(String.Format("Converted flags: {0}", outputBuffer.StatusFlags)); //Assert.AreEqual((int)(inputBuffer.Length * 48000.0 / inputFormat.SampleRate), outputBuffer.Length, "Converted buffer length"); } using (DmoOutputDataBuffer outputBuffer = new DmoOutputDataBuffer(48000 * 2 * 4)) { // one buffer for each output stream resampler.MediaObject.ProcessOutput(DmoProcessOutputFlags.None, 1, new DmoOutputDataBuffer[] { outputBuffer }); Debug.WriteLine(String.Format("Converted length: {0}", outputBuffer.Length)); Debug.WriteLine(String.Format("Converted flags: {0}", outputBuffer.StatusFlags)); //Assert.AreEqual((int)(inputBuffer.Length * 48000.0 / inputFormat.SampleRate), outputBuffer.Length, "Converted buffer length"); } } resampler.MediaObject.FreeStreamingResources(); }
private bool IsResamplerConversionSupported(WaveFormat from, WaveFormat to) { Resampler resampler = new Resampler(); // need to set an input format before we can ask for an output format to resampler.MediaObject.SetInputWaveFormat(0, from); return resampler.MediaObject.SupportsOutputWaveFormat(0, to); }
private bool IsResamplerInputFormatSupported(WaveFormat waveFormat) { Resampler resampler = new Resampler(); return resampler.MediaObject.SupportsInputWaveFormat(0, waveFormat); }
public void CanCreateResamplerMediaObject() { Resampler resampler = new Resampler(); }
public void ResamplerCanGetInputAndOutputBufferSizes() { Resampler resampler = new Resampler(); resampler.MediaObject.SetInputWaveFormat(0, WaveFormat.CreateIeeeFloatWaveFormat(44100, 2)); resampler.MediaObject.SetOutputWaveFormat(0, WaveFormat.CreateIeeeFloatWaveFormat(48000, 2)); MediaObjectSizeInfo inputSizeInfo = resampler.MediaObject.GetInputSizeInfo(0); Assert.IsNotNull(inputSizeInfo, "Input Size Info"); Console.WriteLine(inputSizeInfo.ToString()); MediaObjectSizeInfo outputSizeInfo = resampler.MediaObject.GetOutputSizeInfo(0); Assert.IsNotNull(outputSizeInfo, "Output Size Info"); Console.WriteLine(outputSizeInfo.ToString()); }
/// <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 (resampler != null) { //resampler.Dispose(); s resampler = null; } base.Dispose(disposing); }