Question

I am writing a software which processes audio files. I am using libsndfile library for reading wave file data, and I come across a doubt that wasn't solved by their documentation: what is the difference between functions that read items and functions that read frames? Or, in other words, am I getting the same results if I interchange both sf_read_short and sf_readf_short?

I have read in some questions that an audio frame equals a single sample, so I thought that what libsndfile calls items might be the same thing. During my tests they seemed to be the same.

Was it helpful?

Solution

I was concerned too and found the answer.

Q12 : I'm looking at sf_read*. What are items? What are frames?

An item is a single sample of the data type you are reading; ie a single short value for sf_read_short or a single float for sf_read_float. For a sound file with only one channel, a frame is the same as a item (ie a single sample) while for multi channel sound files, a single frame contains a single item for each channel.

Here are two simple, correct examples, both of which are assumed to be working on a stereo file, first using items:

    #define CHANNELS 2
    short data [CHANNELS * 100] ;
    sf_count items_read = sf_read_short (file, data, 200) ;
    assert (items_read == 200) ;

and now readng the exact same amount of data using frames:

    #define CHANNELS 2
    short data [CHANNELS * 100] ;
    sf_count frames_read = sf_readf_short (file, data, 100) ;
    assert (frames_read == 100) ;

This is a copy&paste from: libsndfile FAQ, question 12.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top