kcat / alure

Alure is a utility library for OpenAL, providing a C++ API and managing common tasks that include file loading, caching, and streaming
zlib License
70 stars 20 forks source link

Added unsigned 8-bit and Mulaw support to libsndfile decoder. #28

Closed LAGonauta closed 6 years ago

LAGonauta commented 6 years ago

Almost all sound files that I have to read are U8, and reading them as 16-bit was using more memory than could be used. Thus, I added support for unsigned 8-bit to the libsndfile decoder.

Very simple commit, however there is no problem if I have to change anything. (maybe change read() to a switch case?)

kcat commented 6 years ago

Have you double-checked that this works correctly with stereo unsigned 8-bit files? The header's description of the raw function is kind of vague on the return value.

LAGonauta commented 6 years ago

You are correct, I was mistaken thinking it behaved the same as readf. The following page elucidates the ambiguity: http://www.mega-nerd.com/libsndfile/api.html#raw

The raw read and write functions return the number of bytes read or written (which should be the same as the bytes parameter).

Thus I should actually convert "got" back to frames. Just fixed it and also took the liberty to change the if-else to a switch statement, I hope this is OK. (seemed more readable as there are two lines of code to read U8 now)