[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] array interface/new buffer protocol handling for mixer.Sound



Hi,

I have been playing at updating the mixer.Sound type to recognize and export the Numpy like array interface. This new functionality replaces the Python code in sndarray for handling Numpy arrays. Once finished, the lessons learned will be applied to pygame.Surface. mixer.Sound also recognizes the new buffer protocol, but will not implement it for now, as the protocol is still in development.

In extending Sound to handle an array interface I reused C code from the make_sound method in _numericsndarray.c, the old sndarray module. Though not documented, make_sound will convert various array integer sizes to the appropriate sound sample size. But it does not do this consistently. When going from an array integer to a smaller sound sample - from 16 bits to 8 bits for example - the integer is simply left truncated. But when going from an 8 bit array integer to a 16 bit sound sample the value is left shifted by 8 bits - multiplied by 256. Personally I do not think this inconsistency should remain. So what to do? Copy with truncation/left sign bit padding as with C or Numpy integer conversion? Or do scaling by zero padding/truncating from the right? Are there other suggestions?

Lenard Lindstrom