XBAT sample values

10 views
Skip to first unread message

Ann Warde

unread,
Apr 22, 2009, 11:00:04 PM4/22/09
to xbat-devel
My understanding is that for each n-byte file, the XBAT function
sound_read reads integers and re-scales them using the maximum
absolute integer value (i.e. 2^(8n-1)). As a result all returned
sample values fall between -1 and +1.

Is this correct?

Thanks,
Ann

Ann Warde

unread,
Apr 22, 2009, 11:16:19 PM4/22/09
to xbat-devel
That is, for each n-byte integer in the file, sound_read reads the
integers and re-scales them using the maximum
absolute integer value (i.e. 2^(8n-1)). As a result all returned
sample values fall between -1 and +1.

Thanks,
-A

Harold Figueroa

unread,
Apr 23, 2009, 12:30:56 PM4/23/09
to xbat-...@googlegroups.com
Hello Anne,

For all currently supported file formats, except the MP3, the
conversion into floating-point is done by the open-source library
libsndfile: http://www.mega-nerd.com/libsndfile.

The reading functions are described here:
http://www.mega-nerd.com/libsndfile/api.html#readf. Further down the
page in the notes the integer to float behavior is described:

When converting between integer data and floating point data,
different rules apply. The default behaviour when reading floating
point data (sf_read_float() or sf_read_double ()) from a file with
integer data is normalisation. Regardless of whether data in the file
is 8, 16, 24 or 32 bit wide, the data will be read as floating point
data in the range [-1.0, 1.0]. Similarly, data in the range [-1.0,
1.0] will be written to an integer PCM file so that a data value of
1.0 will be the largest allowable integer for the given bit width.
This normalisation can be turned on or off using the sf_command
interface.

Actually XBAT, through libsndfile and the sound_file_read function,
can also read the integers into MATLAB ...

opt = sound_file_read; opt.class = 'int16';

samples = sound_file_read(my_file, start, count, [], [], opt)

will read 'count' samples starting at 'start' from all channels in the
file as 16-bit integers ... the bit-depth usef in a file is obtained
through the sound_file_info function ...

Harold
Reply all
Reply to author
Forward
0 new messages