September 02, 2017 Re: 24-bit int | ||||
---|---|---|---|---|
| ||||
Posted in reply to kinke | On Saturday, 2 September 2017 at 07:20:07 UTC, kinke wrote:
> struct int24 {
> ubyte[3] _payload;
> }
>
> static assert(int24.sizeof == 3);
> static assert(int24.alignof == 1);
>
> Making absolute sense. ubytes don't need any specific alignment to be read efficiently.
Yes, that does make sense. It doesn't make sense that I didn't realize it.
|
September 02, 2017 Re: 24-bit int | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | 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:
>> struct int24 {
>> ubyte[3] _payload;
>>
>> this(int x) {
>> value = x;
>> }
>>
>> ...
>> }
>
> 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 very first test in my code checks this:
int24[3] a;
assert(a.sizeof == 9);
On the other hand, using Mir's well-tested code instead of something I hacked together in 10 minutes is probably a good idea.
--
Biotronic
|
September 03, 2017 Re: 24-bit int | ||||
---|---|---|---|---|
| ||||
Posted in reply to EntangledQuanta | 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.
If you need to perform math on integer audio, I strongly suggest to use int32 for this purpose to avoid performance degradation, then convert back to int24 when you're finished. Probably going to add such feature into my PCM library.
|
September 03, 2017 Re: 24-bit int | ||||
---|---|---|---|---|
| ||||
Posted in reply to EntangledQuanta | 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 |
September 03, 2017 Re: 24-bit int | ||||
---|---|---|---|---|
| ||||
Posted in reply to Biotronic | 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: big endian is indeed problematic. > @property > int value(int x) { > _payload = (cast(ubyte*)&x)[0..3]; > return value; > } > will not work on big endian machine. version(BigEndian) _payload = (cast(ubyte*)&x)[1..4]; |
September 03, 2017 Re: 24-bit int | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | 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.
|
September 04, 2017 Re: 24-bit int | ||||
---|---|---|---|---|
| ||||
Posted in reply to EntangledQuanta | On Sunday, 3 September 2017 at 23:30:43 UTC, EntangledQuanta wrote: > 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: >>>> [...] >>> >>> 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. The implementation can be found here https://github.com/libmir/mir-algorithm/blob/master/source/mir/ndslice/iterator.d It uses unions and byte loads. The speed should be almost the same as direct access. |
Copyright © 1999-2021 by the D Language Foundation