/// <summary> /// Disposes the <see cref="AudioResampler"/> object. /// </summary> public void Dispose() { if (this.resampler != null) { this.resampler.Dispose(); this.resampler = null; } }
/// <summary> /// Resets the resampler and changes the input audio format. /// </summary> /// <param name="format">The audio format.</param> private void SetInputFormat(WaveFormat format) { // clone the data as we will be holding onto it beyond this callback format.DeepClone(ref this.currentInputFormat); this.Configuration.InputFormat = this.currentInputFormat; // dispose and re-create the resampler to switch formats this.resampler.Dispose(); this.resampler = new MFResampler(); this.resampler.Initialize( this.Configuration.TargetLatencyInMs, this.Configuration.InputFormat, this.Configuration.OutputFormat, this.AudioDataAvailableCallback); }
/// <summary> /// Initializes a new instance of the <see cref="AudioResampler"/> class. /// </summary> /// <param name="pipeline">The pipeline to add the component to.</param> /// <param name="configuration">The component configuration.</param> public AudioResampler(Pipeline pipeline, AudioResamplerConfiguration configuration) : base(pipeline) { this.configuration = configuration; this.currentInputFormat = configuration.InputFormat; // create the audio resampler this.resampler = new MFResampler(); // initialize the resampler this.resampler.Initialize( this.Configuration.TargetLatencyInMs, this.Configuration.InputFormat, this.Configuration.OutputFormat, this.AudioDataAvailableCallback); }