24-bit int

EntangledQuanta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 1 20:27:18 PDT 2017


On Saturday, 2 September 2017 at 02:37:08 UTC, Mike Parker wrote:
> On Saturday, 2 September 2017 at 01:19:52 UTC, EntangledQuanta 
> wrote:
>>
>> 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.
>
> It's not a bug, but a feature. Data structure alignment is 
> important for efficient reads, so several languages (D, C, C++, 
> Ada, and more) will automatically pad structs so that they can 
> maintain specific byte alignments. On a 32-bit system, 4-byte 
> boundaries are the default. So a struct with 3 ubytes is going 
> to be padded with an extra byte at the end. Telling the 
> compiler to align on a 1-byte boundary (essentially disabling 
> alignment) will save you space, but will will generally cost 
> you cycles in accessing the data.

You fail to read correctly. A bug in his code. If he is treating 
in24's as int32's and simply ignoring the upper byte then it is 
not a true int24 and all the work he did would be pointless. I 
can do that by simply reading an int32 and masking the high bit.




More information about the Digitalmars-d-learn mailing list