C Runtime for Lingua Franca
No Matches
wave_file_reader.h File Reference

Utility function for reading WAV audio files. More...

Go to the source code of this file.

Data Structures

struct  lf_waveform_t


typedef struct lf_waveform_t lf_waveform_t


lf_waveform_tread_wave_file (const char *path)

Detailed Description

Utility function for reading WAV audio files.

Edward A. Lee

This defines functions and data types for importing audio files with the wave audio format. The main function is read_wave_file(), which, given a path to a .wav file, reads the file and, if the format of the file is supported, returns an lf_waveform_t struct, which contains the raw audio data in 16-bit linear PCM form.

This code has few dependencies, so it should run on just about any platform.

To use this, include the following flags in your target properties:

target C {
    files: [
    cmake-include: [

In addition, you need this in your Lingua Franca file or reactor:

   preamble {=
       #include "wave_file_reader.h"

Typedef Documentation

◆ lf_waveform_t

typedef struct lf_waveform_t lf_waveform_t

Waveform in 16-bit linear-PCM format. The waveform element is an array containing audio samples. If there are two channels, then they are interleaved left and right channel. The length is the total number of samples, a multiple of the number of channels.

Function Documentation

◆ read_wave_file()

lf_waveform_t * read_wave_file ( const char * path)

Open a wave file, check that the format is supported, allocate memory for the sample data, and fill the memory with the sample data. It is up to the caller to free the memory when done with it. That code should first free the waveform element of the returned struct, then the struct itself. This implementation supports only 16-bit linear PCM files. On a Mac, you can convert audio files into this format using the afconvert utility.

pathThe path to the file.
An array of sample data or NULL if the file can't be opened or has an usupported format.