24-bit int
EntangledQuanta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Sep 3 16:30:43 PDT 2017
On Sunday, 3 September 2017 at 04:01:34 UTC, Ilya Yaroshenko
wrote:
> On Saturday, 2 September 2017 at 03:29:20 UTC, EntangledQuanta
> wrote:
>> On Saturday, 2 September 2017 at 02:49:41 UTC, Ilya Yaroshenko
>> 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.
>>>
>>> Hi,
>>>
>>> Probably you are looking for bitpack ndslice topology:
>>> http://docs.algorithm.dlang.io/latest/mir_ndslice_topology.html#.bitpack
>>>
>>> sizediff_t[] data;
>>> // creates a packed signed integer slice with max allowed
>>> value equal to `2^^24 - 1`.
>>> auto packs = data[].sliced.bitpack!24;
>>>
>>> packs has the same API as D arrays
>>>
>>> Package is Mir Algorithm
>>> http://code.dlang.org/packages/mir-algorithm
>>>
>>> Best,
>>> Ilya
>>
>> Thanks. Seems useful.
>
> Just added `bytegroup` topology. Released in v0.6.12 (will be
> available in DUB after few minutes.)
>
> http://docs.algorithm.dlang.io/latest/mir_ndslice_topology.html#bytegroup
>
> It is faster for your task then `bitpack`.
>
> Best regards,
> Ilya
Thanks! I might end up using this. Is this basically just a
logical mapping(cast(int)bytes[i*3]) & 0xFFFFFF) type of stuff or
is there more of a performance hit?
I could do the mapping myself if that is the case as I do not
need much of a general solution. I'll probably be using in a just
a few lines of code. It just needs to be nearly as fast as direct
access.
More information about the Digitalmars-d-learn
mailing list