rsoundio
rsoundio copied to clipboard
Supporting 24 bit stream types
Citing https://docs.klingt.net/rustdoc/rsoundio/enum.SioFormat.html:
Because there is no native number type that is 24 bits wide, (at least not in Rusts std) I had to use something like C unions in Rust to support them. This would probably be unsafe and working with 3 byte number types is also not too much fun.
libsoundio's docs state that one passes 32 bit variables in this case, so the only reason I can see to need a special type at all is to simulate overflow. And if they're ever necessary, Rust has floor (and related) and plenty of bit operators, which don't require unsafe.
So, the idea is to simulate a 24-bit value by masking a 32-bit integer?
Yep. The C lbrary isn't doing/requiring anything tricky, certainly nothing Rust can't handle. I changed my comment above to mention floor, but one can pass any 32 bit number ((un)signed float or integer depending on sample type unless the library does implicit conversion, not sure) and the top 8 bits are simply ignored.
What I don't know yet is whether the sample type's endianness affects the interpretation of Rust's primitive number types. I need to look at libsoundio's source, but I'm working on using it in Nim or Julia.
I think there is no special endianess handling, at least not in outstream_begin_write_alsa. Libsoundio set's the correct endian type for the format enums at compile time.
We should take at look at every outstream_begin_write implementation in libsoundio to be sure that there is nothing special.
I'm not confident I would know it was happening if I saw it. I can say though that if endianness were a problem, it would apply to any SoundIoFormat from 16 to 64 bits.
Are you referring to this compile-time stuff?
I'm personally not worried about endianness for now, but andrewrk has an email address if we really want to be sure.
Are you referring to this compile-time stuff?
Yes, that's what I was referring too. Endianess shouldn't be a problem because almost all consumer machines nowadays are little endian ones.
I'm working with Andrew to add 24-bit packed/3bytes formats for the next major libsoundio version. The SoundIoFormat endianness seems to matter when writing to the buffer pointed at by a soundIoChannelArea[channel].ptr.
I am planning to make a rewrite of rsoundio for version 0.2 where I will address this issue.
libsoundio can use 24-bit formats now (well, ALSA can).
Thank your for the info, but there is no new libsoundio release, 1.1.0 is still the latest version. I hope too find some time for the rsoundio rewrite because I am now working full time.