Document toolboxDocument toolbox

WaveFileSink

Overview

Captures the input wire audio samples and writes it into a multi-channel output .wav file

Discussion

The WaveFileSink module captures audio samples from the input pin and writes them to the output .wav file specified by the user. File writing happens in the deferred processing thread, if .isActive flag is TRUE, so as to not interrupt real-time processing. On the halting the current run, output .wav is available to the user.

Arguments

This module has one input pin. The output .wav will capture all the channels from the input pin, and will use the sample rate derived the input pin. The sampleSize (either 2 or 4 bytes) of the recorded audio is a module argument. The module is designed to work with both Native and Linux targets. The directoryName and baseName of the output.wav can also be specified as module arguments.

e.g.: if the baseName:RECORD then output .wav = RECORD.wav).

By prefixing or postfixing to the baseName, the output .wav file will be created with timestamp information appended to the file name.

e.g.: if # is prefixed in the baseName:#-RECORD then output .wav = YYYYMONDAY_HHMMSS-RECORD.wav).

e.g.: if # is postfixed in the baseName:RECORD-# then output .wav = RECORD-YYYYMONDAY_HHMMSS.wav).

Also note that and absolute paths for directoryName are not portable across Windows and Linux, but relative paths are.

e.g.: Linux full directoryName : /home/pi/AudioWeaver-8.0.0-Linux/AWECore/Audio will not work in Windows environment, and Windows full directoryName \Audio\ will not work in the Linux environment

e.g.: The following types of relative directoryName (relative to the current working directory) ../AWECore/Audio or ..\AudioWeaver\Audio are portable across Windows and Linux environment

Note that the current working directory in Windows is: \Bin\win32-vc142-rel (32 bit builds) or \Bin\x64-vc142-rel(64 bit builds)

The current working directory in Linux is the directory where the application is executed from

e.g.: if the package (AWECoreOS) is extracted on the target and the sample application Libtester is executed from ~/AWECoreOS/Bin, then the Bin directory is the current working directory in this case

The blockSize of the module will be derived from the input pin.

The cache size argument defines the size of the cache buffer that is allocated by the module to store the audio before issuing a fwrite in the deferred set call. This is a per channel configuration, internally the module will allocate a buffer that is cache size * number of channels. If the user notices that the overRunCtr counter is incrementing, indicating insufficient caching, then try increasing the cache size until no more over runs occur. To avoid circular wrap of cache buffer with in a block, the size of the cache buffer is aligned with the block size. i.e. the allocated cache buffer size is ceil(cache size/blockSize) * blockSize * number of channels

Supported File Formats

The WaveFileSink module creates an output .wav file of the following format:

    Chunk ID : RIFF

    WAVE ID : WAVE

    sub chunk1 ID : fmt

    sub chunk2 ID : data

    Format Tag : PCM (1)

Inspector Details

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

initDone : 0 indicates that initialization failed, and 1 means that initialization was successful

isActive : Used to control start/pause. On pause, the module stops capturing the audio data from the input pin.

overRunCtr : This counter increments when the cache overflows. Increase the cacheSize argument to prevent over runs.

errorCode : Captures errors that arise in the module C code. To help debug the configuration

Error Codes

Possible ERROR codes, reported (Inspector -> errorCode). In this situation the module stays uninitialized (initDone = 0) and the .wav file is not created

E_WAVE_FILE_OPEN -1 : File fopen command error (output.wav)

E_WAVE_FILE_READ -2 : File fread command error (output.wav)

E_WAVE_FILE_WRITE -3 : File fwrite command error (output.wav)

E_WAVE_FILE_FSEEK -4 : File fseek command error (output.wav)

E_WAVE_FILE_EXISTS -5 : File already exits / File name already used by another module in the layout

E_WAVE_FILE_INVALID_DIR -6 : File fopen command error : No such file or directory

E_WAVE_FILE_NOT_EN_MEM -7 : File fopen command error : Out of memory

E_WAVE_FILE_ACC_DENIED -8 : File fopen command error : write permission is denied

E_WAVE_FILE_RO_FS -9 : File fopen command error : read-only file system and mode requires write access

Type Definition

typedef struct _ModuleWaveFileSink { ModuleInstanceDescriptor instance; // Common Audio Weaver module instance structure UINT32 cacheSize; // The size of the buffer that is used to store the audio samples captured from the input pin before the deferred set call issues a fwrite, defined in terms number of samples per channel (CACHESIZE * NUMCHANNELS) UINT32 sampleSize; // Size of the sample to be stored in the file (2 bytes / 4 bytes) INT32 isActive; // True means recording is active/started, false means recording is paused. Can be dynamically controlled in inspector INT32 initDone; // State variable, indicates initialization done state. Appears on the inspector UINT32 readIndex; // Current read-pointer of the cache memory UINT32 writeIndex; // Current write-pointer of the cache memory UINT32 fillLevel; // Current fill level in the cache UINT32 overRunCtr; // Counts the number of over runs, incremented when the cache overflows. Appears on the inspector INT32 errorCode; // Captures errors that could arise in the module C code. Appears on the inspector UINT32 totalNoSamples; // Total number of samples written into the output.wav INT32 fullFileSize; // Size of the array to hold the full file path for the output.wav file to be created INT32* fullFileName; // Complete file path for the output.wav file to be created fract32* cache; // The buffer used to store the audio samples from the input wire before the deferred set call issues a fwrite void * inFile; // File pointer to access the output wav file } ModuleWaveFileSinkClass;

Variables

Properties

Name

Type

Usage

isHidden

Default value

Range

Units

cacheSize

uint

const

0

2048

Unrestricted

 

sampleSize

uint

const

0

2

Unrestricted

 

isActive

int

parameter

0

1

Unrestricted

 

initDone

int

state

0

0

Unrestricted

 

readIndex

uint

state

0

0

Unrestricted

 

writeIndex

uint

state

0

0

Unrestricted

 

fillLevel

uint

state

0

0

Unrestricted

 

overRunCtr

uint

state

0

0

Unrestricted

 

errorCode

int

state

0

0

Unrestricted

 

totalNoSamples

uint

const

0

0

Unrestricted

 

fullFileSize

int

const

0

2

Unrestricted

 

fullFileName

int*

parameter

1

[1 x 2]

Unrestricted

 

cache

fract32*

state

0

[0 x 0]

Unrestricted

 

inFile

void *

const

0

 

Unrestricted

 

Pins

Input Pins

Name: in

Description: Input audio

Data type: fract32

Channel range: Unrestricted

Block size range: Unrestricted

Sample rate range: Unrestricted

Complex support: Real

MATLAB Usage

File Name: wave_file_sink_module.m

M = wave_file_sink_module(NAME, DIRECTORYNAME, BASENAME, CACHESIZE, SAMPLESIZE) WaveFileSink module captures the input data from the input pin and stores it on to a output.wav (RIFF) file. The audio data from the input pin is stored to a buffer (cache) by the process function and periodically written into the file in the deferred call. Output .wav file will be a wave file of PCM format only. User configurable sample width of 2 or 4 bytes for output .wav. Floating point data not supported. The data on the input pin is always of the type Fract32 This module is designed to work on Native and Linux targets

Â