Hey, it’s April!
In astrid-land, I’m still debugging issues with the new
lpsampler interfaces and working on getting the ADC
sampling interface working in the python instruments. The (mostly
stupid, as usual) issues with the shared memory backing are mostly
sorted and libpippi buffers are now using flexible array members as
their last elements.
At the moment I’m trying to avoid more copies and allocations when reading from the sampler in cython. Pippi’s SoundBuffers are still numpy-backed Note 0 and I don’t think there’s any safe way to avoid all copies until they’re libpippi-backed…
I’m trying out creating the numpy array that will be used to back the
output buffer from the sampler first, then (hopefully) giving C a
pointer to the underlying memory there to fill the buffer, and just
wrapping it back into a SoundBuffer at the end. In other
words copying once into a new array whose memory is managed by numpy.
The fiddly bits in the middle are where I’m stuck this morning.
The cython docs show this way of getting a pointer to a memoryview:
the_memoryview: cython.double[::1] = numpy_array # this must already be C contiguous / typed as a double
some_c_function_that_wants_a_pointer(cython.address(the_memoryview[0]))
Pippi uses numpy ndarrays typed as double[:,:] at the
moment. It makes working with arbitrary numbers of channels easier since
you can slice across dimensions and just operate on one channel at a
time without an extra copy for example… but I’m stumbling over the
reshaping here, it might not be possible to get the pointer directly
without another copy?
Allocating a temporary array in the right shape, copying the samples
into it through the C call, and then copying it back into the
double[:,:]-shaped numpy array is the best idea I have
right now.
It’s fine! I don’t care much about the extra copies I guess, but getting rid of them is probably a project for another time. Once the sampler works the fun stuff can begin: pushing brass tones through astrid into resonators.
Note 0: There are a lot of places where pippi assumes that
SoundBuffers have a frames param which is the
numpy array, and that gets used to do things with the python buffer API
interfaces. The new buffers are backed by libpippi
lpbuffer_t structs and expose the buffer API directly on
the object – that’s probably the last big pippi project before I take it
out of beta, whatever that means.
Log March 2024
Log February 2024
Log January 2024
Log December 2023