hi,

Here's an email Nick just sent me... which he sent to Marcus directly
rather than to the mailing list.

It's to do with sndarray... he found the error whilst we were making a
pyweek game... but in the rush forgot about it.

It could be a similar bug.


cu.


---------

I was recently using numpy via pygame.sndarray to build up some accurate loops
of a short stereo sound file.

I would get an error:

" array.shape = shape
ValueError: total size of new array must be unchanged "

I traced it back to the function _array_sample in _numpysndarray.py


    def _array_samples(sound, raw):
        ...

        fmtbytes = (abs (info[1]) & 0xff) >> 3

        ...

        shape = (len (data) / channels * fmtbytes, )


fmtbytes refers to the amount of bytes per sample?

So if we had 16 bit samples / 8bits per byte = 2 bytes per sample?

Stereo at 2 bytes per sample = 4 bytes each "frame"?

Assuming len returns the number of bytes?
(len(data) / 4, 2) would be the correct shape then?

I think there is an operator precedence typo:

    shape = (len (data) / channels * fmtbytes, )
    8 / 2 * 2   = 8

    shape = (len (data) / (channels * fmtbytes), )
    8 / (2 * 2) = 2


re:      fmtbytes = (abs (info[1]) & 0xff) >> 3

is that basically abs(info[1] / 8)?

But then I'm assuming fmtbytes refers to bytes per sample with possible
info[1] values of (-16, -8, 8, 16)

Anyway, I made the operator precedence change and my code worked, so I thought
I would bring it to your attention as there is a possibility there is a bug in
the function and it's not my misunderstanding.





On Tue, Jan 20, 2009 at 10:06 AM, René Dudfield <[email protected]> wrote:
> I don't think it should be 0.  That means it's not visible, and
> contradicts the convention as you say.
>
> I'm not sure if it has always been like that, or if it changed with
> the 1.8 changes to surfarray?
>
> ps.  I think there might be a bug with 24bit numpy arrays with
> surfarray in general?  I think I came across a bug the other day...
> but not sure.  If I find the code where I thought it was happening,
> I'll turn it into a test.
>
> cu,
>
>
> On Tue, Jan 20, 2009 at 9:49 AM, Lenard Lindstrom <[email protected]> wrote:
>> Hi,
>>
>> I've been looking at bug 24 at http://pygame.motherhamster.org/bugzilla
>> regarding blit_array and I found something unusual. When blitting to a 32
>> bit SRCALPHA surface the alpha is set 0. This contradicts the convention of
>> a default alpha of 255. So what do I do? I can leave it that way for both
>> Numeric and NumPy arrays, change it for NumPy only or change it for both
>> array types. I'm inclined to change it for NumPy only. Is there any reason
>> alpha should be zero?
>>
>> Lenard
>>
>> --
>> Lenard Lindstrom
>> <[email protected]>
>>
>>
>

Reply via email to