Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Scroll Documents: Update page title prefix

Overview

Opens and reads audio data from an input .wav file and streams it over the output wire

Discussion

The Wavefilesource module opens, reads, and streams the audio data from a .wav file over the module's output wire. File reading happens in the deferred processing thread so as not to interrupt real-time processing.

Arguments

This module, designed to work with Linux and Windows based targets, has one output pin with user configurable number of channels, sample rate and block sizes. And if there is a mismatch between configured values and number of channels and sample rate from the input .wav file, the user configurations take precedence. A channel matching mechanism is implemented internally as explained below for any mismatch in the number of channels in the .wav file and the numChannels module argument.

...

The LoopFile argument will cause the module to loop through the file forever when enabled. If disabled, the file will play only once and then output zeros. This setting can't be changed dynamically.

Supported File Formats

The WaveFileSource can handle input .wav files only of the following format:

...

The WaveFileSource module can handle INT/FRACT 16/32 bit data types only. The 16 bit data types are internally converted to 32 bit data then streamed over the wire. The data type of the output wire is always FRACT32.

Inspector Details

On double clicking the module, an inspector will show up on the canvas with the following information:

...

wavSampleRate : The sample rate of the input .wav. This is parsed in the module C code

Error Codes

Possible WARNINGS codes, reported in (Inspector -> errorCode). In this situation the module completes initialization (initDone = 1) and continues to stream the audio data on the wire.

...

E_WAVE_FILE_SAMPLE_WIDTH_UNSUPPORTED -11 : Input .wav sample width unsupported (only 2 and 4 byte sample widths supported)

Type Definition

Code Block
typedef struct _ModuleWaveFileSource
{
    ModuleInstanceDescriptor instance;            // Common Audio Weaver module instance structure
    UINT32 cacheSize;                             // The size of the buffer that is used to prefill the read audio samples in the deferred call, defined in terms number of samples (CACHESIZE * NUMCHANNELS)
    INT32 loopFile;                               // Play the audio file in a loop if enabled
    INT32 isActive;                               // True is playback is active, false is playback is paused. Can be dynamically controlled in inspector
    INT32 initDone;                               // State variable, indicates initialization done state. Appears on the inspector
    INT32 proNxtPass;                             // State variable, used to handling playback in a loop
    UINT32 readIndex;                             // Current read-pointer of the cache memory
    UINT32 writeIndex;                            // Current write-pointer of the cache memory
    UINT32 remSamples;                            // The number of samples remaining to be moved in the input.wav
    UINT32 fillLevel;                             // Current fill level in the cache
    UINT32 underRunCtr;                           // Counts the number of under runs, incremented when the cache does not have enough samples to output to wire. Appears on the inspector
    INT32 errorCode;                              // Captures errors/warnings that could arise in the module C code. Appears on the inspector
    UINT32 totalNoSamples;                        // State variable: total number of samples in the input.wav file
    UINT32 sampleWidth;                           // Sample width in terms of bytes of input .wav file
    INT32 wavNumChannels;                         // Number of channels of the input.wav file. Appears on the inspector
    FLOAT32 wavSampleRate;                        // Sample rate of the input.wav file. Appears on the inspector
    INT32 fullFileSize;                           // Length of the file name+path of the input.wav file name in bytes
    INT32* fullFileName;                          // Complete file path/file for the input.wav file
    fract32* cache;                               // The buffer that is used internally to prefill the read audio samples
    void * inFile;                                // File pointer to access the input wav file
} ModuleWaveFileSourceClass;

Variables

Properties

Name

Type

Usage

isHidden

Default value

Range

Units

cacheSize

uint

const

0

2048

Unrestricted

loopFile

int

const

0

1

Unrestricted

isActive

int

parameter

0

1

Unrestricted

initDone

int

state

0

0

Unrestricted

proNxtPass

int

state

0

0

Unrestricted

readIndex

uint

state

0

0

Unrestricted

writeIndex

uint

state

0

0

Unrestricted

remSamples

uint

state

0

0

Unrestricted

fillLevel

uint

state

0

0

Unrestricted

underRunCtr

uint

state

0

0

Unrestricted

errorCode

int

state

0

0

Unrestricted

totalNoSamples

uint

state

0

0

Unrestricted

sampleWidth

uint

state

0

0

Unrestricted

wavNumChannels

int

state

0

0

Unrestricted

wavSampleRate

float

state

0

0

Unrestricted

fullFileSize

int

const

0

3

Unrestricted

fullFileName

int*

parameter

1

[1 x 3]

Unrestricted

cache

fract32*

state

0

[0 x 0]

Unrestricted

inFile

void *

const

0

Unrestricted

Pins

Output Pins

Name: out

Description: Output audio

Data type: fract32

MATLAB Usage

File Name: wave_file_source_module.m

...