libsndfile / libsamplerate

An audio Sample Rate Conversion library
http://libsndfile.github.io/libsamplerate/
BSD 2-Clause "Simplified" License
600 stars 167 forks source link

What is a frame? #173

Closed philippludwig closed 2 years ago

philippludwig commented 2 years ago

The documentation talks about frames, e.g.

input_frames : The number of frames of data pointed to by data_in.

But what exactly is a "frame"? How do I put raw audio data (16bit values) into a "frame"?

evpobr commented 2 years ago

Hi @philippludwig .

Sample is minimum discrete item of audio data. For CD Audio (16-bit) one sample is 16-bit.

Frame is block of samples of all channels.

For CD Audio frame consists of 2 samples of 16-bit (left + right).

You can also read: http://libsndfile.github.io/libsndfile/api.html#read

To convert 16-bit data to floats as required by libsamplerate API, use Auxillary Functions.

For example:

int samples = 256;
int channels = 2;
int frames = samples * channels;

int16_t *src = malloc(sizeof(int16_t) * frames);

float *input_frames = malloc(sizeof(float) * frames);

src_short_to_float_array(src, input_frames, frames);
...
philippludwig commented 2 years ago

Thank you for the explanation and the example. I successfully managed to upsample a block of mono wave data, but I did not use the auxiliary functions yet - I will look into those.

(I would consider this solved, so this can be closed I guess)

evpobr commented 2 years ago

You're welcome!