rsoundio icon indicating copy to clipboard operation
rsoundio copied to clipboard

Supporting 24 bit stream types

Open 0joshuaolson1 opened this issue 9 years ago • 11 comments

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.

0joshuaolson1 avatar Apr 08 '16 01:04 0joshuaolson1

So, the idea is to simulate a 24-bit value by masking a 32-bit integer?

klingtnet avatar Apr 08 '16 10:04 klingtnet

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.

0joshuaolson1 avatar Apr 08 '16 15:04 0joshuaolson1

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.

0joshuaolson1 avatar Apr 08 '16 16:04 0joshuaolson1

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.

klingtnet avatar Apr 08 '16 19:04 klingtnet

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?

0joshuaolson1 avatar Apr 08 '16 19:04 0joshuaolson1

I'm personally not worried about endianness for now, but andrewrk has an email address if we really want to be sure.

0joshuaolson1 avatar Apr 08 '16 20:04 0joshuaolson1

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.

klingtnet avatar Apr 08 '16 20:04 klingtnet

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.

0joshuaolson1 avatar Jul 30 '16 20:07 0joshuaolson1

I am planning to make a rewrite of rsoundio for version 0.2 where I will address this issue.

klingtnet avatar Sep 05 '16 09:09 klingtnet

libsoundio can use 24-bit formats now (well, ALSA can).

0joshuaolson1 avatar Apr 05 '17 23:04 0joshuaolson1

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.

klingtnet avatar Apr 06 '17 07:04 klingtnet