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.
...
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:
...
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:
...
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_RO_FS -9 : File fopen command error : read-only file system and mode requires write access
Type Definition
Code Block |
---|
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
...
Sample rate range: Unrestricted
Complex support: Real
MATLAB Usage
File Name: wave_file_sink_module.m
...