reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
wave_file_reader.c File Reference

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

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "wave_file_reader.h"

Data Structures

struct  lf_wav_riff_t
 
struct  lf_wav_format_t
 
struct  lf_wav_data_t
 
struct  lf_wav_t
 

Macros

#define FILE_PATH_SEPARATOR   '/';
 

Functions

lf_waveform_tread_wave_file (const char *path)
 

Detailed Description

Utility function for reading WAV audio files.

Author
Edward A. Lee

See wave_file_reader.h for instructions.

Macro Definition Documentation

◆ FILE_PATH_SEPARATOR

#define FILE_PATH_SEPARATOR   '/';

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.

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