numpy.int24 datatype
josephernest opened this issue · 2 comments
Hi, does anyone know how to define numpy.int24 (24 bits integers, very widely used in professional audio applications) data type ?
I use numpy a lot, but I don't have C knowledge to be able to do this myself...
Would someone have a hint ?
I upvoted this but (I say as someone who is not a developer of the numpy library), I fear this will always be impossible.
I want this right now for memory mapping large 24-bit WAV files but think of how it would have to work - somehow these arrays would need to be able to put together a 24-bit word from 8-bits in one word and 16-bits in another, do calculations on them, round them down to 24-bits, and then store them in those 24-bits of the target word, without affecting any other parts.
AFAIK, numpy is based around "take a pointer and an offset, get a C/C++ integer or floating point number", and I'm fairly sure these numbers are all word-aligned. Having the option of these (literally) odd-shaped numbers would be horribly difficult and likely affect most of numpy's core code.
The way to proceed is unfortunately to copy the samples to be 32-bit, either on disk or internally when you read them - like this.
I am going to archive this repository. We have new-style DTypes and this has been inactive for many years. At this point development from the NumPy side should go towards new ones.
(There will be a new repository to start examples using the new DType API.)
Yes, a 24bit integer could be an interesting DType of course! I hope somone looks into it!