Table of Contents

Class MacAudioConverter

Namespace
NAudio.Wave
Assembly
NAudio.MacOS.dll

Provides the platform's resampler.
Has almost the same strengths as the Windows Media Resampler (excluding changing the input provider's audio format details on the fly), and even provides more options compared to that one, allowing to select resampling algorithm, quality and dithering.

public sealed class MacAudioConverter : IWaveProvider, IDisposable
Inheritance
MacAudioConverter
Implements
Inherited Members
Extension Methods

Constructors

MacAudioConverter(IWaveProvider, WaveFormat)

Initializes a new instance of the MacAudioConverter class, providing the source wave provider to resample, as well as the desired format to convert the data of the provider into.

public MacAudioConverter(IWaveProvider providerToResample, WaveFormat outputFormat)

Parameters

providerToResample IWaveProvider

The IWaveProvider whose data are subject to be resampled.

outputFormat WaveFormat

The audio format to output results as.

Properties

Complexity

Gets/sets the algorithm to use for resampling data.

public AudioConverterSampleRateComplexity Complexity { get; set; }

Property Value

AudioConverterSampleRateComplexity

Exceptions

ObjectDisposedException

The native converter object has been disposed of.

AudioConverterException

This property is not supported for this audio converter object.

Dithering

Gets/sets the dithering algorithm to apply to the audio converter.
The constant None can be used to disable dithering.
This is only supported in macOS.

public AudioConverterDitheringAlgorithm Dithering { get; set; }

Property Value

AudioConverterDitheringAlgorithm

Exceptions

ObjectDisposedException

The native converter object has been disposed of.

AudioConverterException

This property is not supported for this audio converter object.

DitheringBitLength

The pre-specified dithering algorithm is applied to the bit length denoted by the value of this property.
This is only supported in macOS.

public uint DitheringBitLength { get; set; }

Property Value

uint

Exceptions

ObjectDisposedException

The native converter object has been disposed of.

AudioConverterException

This property is not supported for this audio converter object.

Quality

Gets/sets the quality of the audio converter.

public AudioConverterQuality Quality { get; set; }

Property Value

AudioConverterQuality

Exceptions

ObjectDisposedException

The native converter object has been disposed of.

AudioConverterException

This property is not supported for this audio converter object.

WaveFormat

Provides the audio format under which the current resampler produces results as.

public WaveFormat WaveFormat { get; }

Property Value

WaveFormat

Methods

Dispose()

Releases any resources used by this MacAudioConverter instance.
Thread-safe.

public void Dispose()

Read(Span<byte>)

Reads data out from the source provider, passing them through this configured resampler.

public int Read(Span<byte> buffer)

Parameters

buffer Span<byte>

The buffer to place resampled data into.

Returns

int

Number of bytes actually read into buffer, 0 if end of stream.

Reset()

Resets the buffer state of the audio converter object, if there is reported a discontinuity in the source provider.

public void Reset()

Exceptions

ObjectDisposedException

The native converter object has been disposed of.

SetChannelMap(int[])

Allows to assign a custom channel mapping matrix to map an input channel to an output channel.
The array is arranged as follows:
Each element in the array is an output channel. The first element is the first channel, the second the second channel, and goes on. Each of these elements do contain an index to an index of a channel of the source IWaveProvider format.

An example (Stereo input to four channel output, the stereo input is copied to the last two channels):

int[] chMap = [ 0, 1, 0, 1 ];
theConverter.SetChannelMap(chMap);
public void SetChannelMap(int[] channelMap)

Parameters

channelMap int[]

The array that contains the channel map to assign. The length of this array must be the value of the Channels property.

Remarks

You may also set any element to a value of -1. This special value means that no input channel is to be mapped to the output.

Exceptions

ArgumentNullException

channelMap is null.

AudioConverterException

If channelMap is invalid for the current object or it cannot be set.

ArgumentException

channelMap must have a length equal to the output format number of channels.