24-bit int
EntangledQuanta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Sep 1 18:19:52 PDT 2017
On Saturday, 2 September 2017 at 00:43:00 UTC, Nicholas Wilson
wrote:
> On Friday, 1 September 2017 at 22:10:43 UTC, Biotronic wrote:
>> On Friday, 1 September 2017 at 19:39:14 UTC, EntangledQuanta
>> wrote:
>>> Is there a way to create a 24-bit int? One that for all
>>> practical purposes acts as such? This is for 24-bit stuff
>>> like audio. It would respect endianness, allow for arrays
>>> int24[] that work properly, etc.
>>
>> I haven't looked at endianness beyond it working on my
>> computer. If you have special needs in that regard, consider
>> this a starting point:
>>
>>
>> struct int24 {
>> ubyte[3] _payload;
>>
>> this(int x) {
>> value = x;
>> }
>>
>> ...
>> }
>>
>> --
>> Biotronic
>
> You may also want to put an align(1) on it so that you dont
> waste 25% of the allocated memory in an array of int24's
The whole point is so that there is no wasted space, so if it
requires that then it's not a waste of space but a bug.
Audio that is in24 is 3 bytes per sample, not 4. Every 3 bytes
are a sample, not every 3 out of 4.
Basically a byte[] cast to a int24 array should be 1/3 the size
and every 3 bytes are the same as an int24.
Thanks for pointing this out if it is necessary.
More information about the Digitalmars-d-learn
mailing list