Show / Hide Table of Contents

    Class WEMReader

    This is used to open up the WEM audio files and WEM segment in the SoundBank (BNK) file and setup something that NAudio can access.

    Inheritance
    Object
    WEMReader
    Implements
    IDisposable
    Namespace: Anki.AudioKinetic
    Assembly: Anki.Resources.SDK.dll
    Syntax
    public class WEMReader : IDisposable
    Remarks

    A lot of the format info came from:

    • http://bobdoleowndu.github.io/mgsv/documentation/soundswapping.html
    • VGMStream's WWise support

    Making this a kind of plug-in/extension to NAudio was done because it is NAudio is ubiquitous, powerful in ways that matter. There is an existing framework (NVorbis) that we use here -- similar to how vgmstream uses libvorbis -- to decode the audiostream from Cozmo resources. By integrating with NAudio, it is easy to hook into Anki.Vector.SDK, and many other potential programs without learning new tricks.

    Examples

    You can pipe the sounds into NAudio using code like:

      var WEM = new WEMReader("some path to a .wem");
      WEM.Open();
      var waveOut      = new WaveOut();
      var waveProvider = WEM.WaveProvider();
      waveOut.Init(waveProvider);
      waveOut.Play();
      Thread.Sleep(30000);
      waveOut.Stop();
      waveProvider.Dispose();
      waveOut.Dispose();

    Constructors

    WEMReader(Stream)

    Provides access the a WEM sound file or segment

    Declaration
    public WEMReader(Stream stream)
    Parameters
    Type Name Description
    Stream stream

    Stream with the sound file embedded

    Remarks

    Call Open() to begin reading the file

    WEMReader(String)

    Provides access the a WEM sound file

    Declaration
    public WEMReader(string filePath)
    Parameters
    Type Name Description
    String filePath

    The path to the sound file

    Remarks

    Call Open() to begin reading the file

    Properties

    AudioFormat

    The Audio format of the encapsulated data.

    Declaration
    public uint AudioFormat { get; }
    Property Value
    Type Description
    UInt32
    Remarks
    valueDescription
    0xffffWWise's Vorbis stream, using Tremor (fixed-point Vorbis)
    0x0002WWise IMA ADPCM

    AvgBytesPerSec

    The average number of bytes per second

    Declaration
    public uint AvgBytesPerSec { get; }
    Property Value
    Type Description
    UInt32

    BitsPerSample

    The number of bits per sample

    Declaration
    public uint BitsPerSample { get; }
    Property Value
    Type Description
    UInt32

    BlockAlign

    The block alignment

    Declaration
    public uint BlockAlign { get; }
    Property Value
    Type Description
    UInt32

    Duration

    An estimate the duration of the sound, in seconds. (0 on error)

    Declaration
    public float Duration { get; }
    Property Value
    Type Description
    Single

    NumChannels

    The number of channels in the audio file

    Declaration
    public uint NumChannels { get; }
    Property Value
    Type Description
    UInt32

    SampleRate

    The number of samples per second from audio file

    Declaration
    public uint SampleRate { get; }
    Property Value
    Type Description
    UInt32

    Methods

    DataStream()

    Returns a stream of the data for the sound, in its format

    Declaration
    public Stream DataStream()
    Returns
    Type Description
    Stream

    null on error, otherwise a stream of the data

    Dispose()

    Dispose of any extra resources

    Declaration
    public void Dispose()

    Dispose(Boolean)

    Dispose fo the binary stream

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    Boolean disposing

    Open()

    Opens the file and checks out its basic format

    Declaration
    public bool Open()
    Returns
    Type Description
    Boolean

    false if there was an error, true if the file was opened successfully

    WaveProvider()

    This provides an NAudio WaveProvider that can be used to play this file

    Declaration
    public IWaveProvider WaveProvider()
    Returns
    Type Description
    NAudio.Wave.IWaveProvider

    null on error, otherwise a wave provider

    Examples
      var waveOut      = new WaveOut();
      var waveProvider = WEM.WaveProvider();
      waveOut.Init(waveProvider);
      waveOut.Play();
      Thread.Sleep(30000);
      waveOut.Stop();
      waveProvider.Dispose();
      waveOut.Dispose();

    Implements

    System.IDisposable
    Back to top Copyright (c) 2020 by Randall Maas