Table of Contents

Class AcmStream

Namespace
NAudio.Wave.Compression
Assembly
NAudio.WinMM.dll

AcmStream encapsulates an Audio Compression Manager Stream used to convert audio from one format to another

public class AcmStream : IDisposable
Inheritance
AcmStream
Implements
Inherited Members

Remarks

We have observed access violations inside msacm32.dll when ACM calls are issued concurrently from multiple threads. It isn't clear whether every ACM codec is affected or only some, but as a defensive measure NAudio serialises every msacm32 P/Invoke through a single process-wide lock. As a result ACM operations are effectively single-threaded across the process. For high-throughput scenarios consider Media Foundation or DMO-based decoders/encoders instead.

Constructors

AcmStream(WaveFormat, WaveFormat)

Creates a new ACM stream to convert one format to another. Note that not all conversions can be done in one step

public AcmStream(WaveFormat sourceFormat, WaveFormat destFormat)

Parameters

sourceFormat WaveFormat

The source audio format

destFormat WaveFormat

The destination audio format

AcmStream(nint, WaveFormat, WaveFilter)

Creates a new ACM stream to convert one format to another, using a specified driver identifier and wave filter

public AcmStream(nint driverId, WaveFormat sourceFormat, WaveFilter waveFilter)

Parameters

driverId nint

the driver identifier

sourceFormat WaveFormat

the source format

waveFilter WaveFilter

the wave filter

Properties

DestBuffer

Returns the Destination buffer. This will contain the converted data after a successful call to Convert

public byte[] DestBuffer { get; }

Property Value

byte[]

SourceBuffer

Returns the Source Buffer. Fill this with data prior to calling convert

public byte[] SourceBuffer { get; }

Property Value

byte[]

Methods

Convert(int, out int)

Converts the contents of the SourceBuffer into the DestinationBuffer

public int Convert(int bytesToConvert, out int sourceBytesConverted)

Parameters

bytesToConvert int

The number of bytes in the SourceBuffer that need to be converted

sourceBytesConverted int

The number of source bytes actually converted

Returns

int

The number of converted bytes in the DestinationBuffer

DestToSource(int)

Returns the number of source bytes for a given number of destination bytes

public int DestToSource(int dest)

Parameters

dest int

Number of destination bytes

Returns

int

Number of source bytes

Dispose()

Frees resources associated with this ACM Stream

public void Dispose()

Dispose(bool)

Frees resources associated with this ACM Stream

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

~AcmStream()

Frees resources associated with this ACM Stream

protected ~AcmStream()

Reposition()

Report that we have repositioned in the source stream

public void Reposition()

SourceToDest(int)

Returns the number of output bytes for a given number of input bytes

public int SourceToDest(int source)

Parameters

source int

Number of input bytes

Returns

int

Number of output bytes

SuggestPcmFormat(WaveFormat)

Suggests an appropriate PCM format that the compressed format can be converted to in one step

public static WaveFormat SuggestPcmFormat(WaveFormat compressedFormat)

Parameters

compressedFormat WaveFormat

The compressed format

Returns

WaveFormat

The PCM format