|
miniDSP
A small C library for audio DSP
|
Audio file I/O and feature vector writing. More...
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <inttypes.h>#include <sndfile.h>

Go to the source code of this file.
Functions | |
| int | FIO_read_audio (const char *infile, float **indata, size_t *datalen, unsigned *samprate, unsigned donorm) |
| Read a single-channel audio file into memory. | |
| int | FIO_write_npy (const char *outfile, const float **outvecs, size_t nvecs, size_t veclen) |
| Write a 2D float32 array in NumPy .npy v1.0 format. | |
| int | FIO_write_safetensors (const char *outfile, const float **outvecs, size_t nvecs, size_t veclen) |
| Write a 2D float32 array in safetensors format. | |
| int | FIO_write_wav (const char *outfile, const float *data, size_t datalen, unsigned samprate) |
| Write mono float audio to a WAV file. | |
| int | FIO_write_htk_feats (const char *outfile, const float **outvecs, size_t nvecs, size_t veclen, unsigned vecsamprate) |
| Write feature vectors in HTK binary format. | |
Audio file I/O and feature vector writing.
This module provides:
Definition in file fileio.h.
| int FIO_read_audio | ( | const char * | infile, |
| float ** | indata, | ||
| size_t * | datalen, | ||
| unsigned * | samprate, | ||
| unsigned | donorm | ||
| ) |
Read a single-channel audio file into memory.
| infile | Path to the audio file. |
| indata | Output: pointer to the audio samples (caller must free). |
| datalen | Output: number of samples read. |
| samprate | Output: sampling rate of the file (Hz). |
| donorm | If 1, normalise samples to [-1.0, 1.0]. |
Read a single-channel audio file into memory.
Supported formats include everything that libsndfile can open: WAV, FLAC, AIFF, OGG, and many more.
| infile | Path to the audio file. |
| indata | Output: pointer to allocated float array with samples. The caller is responsible for calling free() on this. |
| datalen | Output: total number of samples read. |
| samprate | Output: sample rate in Hz. |
| donorm | 1 to normalise samples to [-1.0, 1.0]; 0 for raw values. |
| int FIO_write_htk_feats | ( | const char * | outfile, |
| const float ** | outvecs, | ||
| size_t | nvecs, | ||
| size_t | veclen, | ||
| unsigned | vecsamprate | ||
| ) |
Write feature vectors in HTK binary format.
| outfile | Path to the output file. |
| outvecs | Array of nvecs pointers, each pointing to veclen floats. |
| nvecs | Number of feature vectors. |
| veclen | Number of floats per vector. |
| vecsamprate | Sampling rate of the feature vectors (Hz). |
Write feature vectors in HTK binary format.
The HTK format is: [12-byte header][vector 1][vector 2]...[vector N]
Each vector is a sequence of big-endian 32-bit floats.
| outfile | Output file path. |
| outvecs | Array of nvecs pointers, each to veclen floats. |
| nvecs | Number of feature vectors. |
| veclen | Number of float elements per vector. |
| vecsamprate | Feature sampling rate in Hz. |
| int FIO_write_npy | ( | const char * | outfile, |
| const float ** | outvecs, | ||
| size_t | nvecs, | ||
| size_t | veclen | ||
| ) |
Write a 2D float32 array in NumPy .npy v1.0 format.
Produces a file readable by numpy.load(). Data is stored as little-endian float32, row-major (C order).
| outfile | Path to the output .npy file. |
| outvecs | Array of nvecs pointers, each pointing to veclen floats. |
| nvecs | Number of feature vectors (rows). |
| veclen | Number of floats per vector (columns). |
| int FIO_write_safetensors | ( | const char * | outfile, |
| const float ** | outvecs, | ||
| size_t | nvecs, | ||
| size_t | veclen | ||
| ) |
Write a 2D float32 array in safetensors format.
Produces a file readable by the safetensors Python library. The tensor is stored under the key "features" as little-endian float32.
| outfile | Path to the output .safetensors file. |
| outvecs | Array of nvecs pointers, each pointing to veclen floats. |
| nvecs | Number of feature vectors (rows). |
| veclen | Number of floats per vector (columns). |
| int FIO_write_wav | ( | const char * | outfile, |
| const float * | data, | ||
| size_t | datalen, | ||
| unsigned | samprate | ||
| ) |
Write mono float audio to a WAV file.
Uses IEEE float format (SF_FORMAT_FLOAT) for lossless DSP round-trips.
| outfile | Path to the output .wav file. |
| data | Audio samples. |
| datalen | Number of samples. |
| samprate | Sampling rate in Hz. |