Witton, Caroline | 4 May 11:13 2012
Picon
Picon

sndarray with numpy array in Windows

Hello,

I'm a researcher using pygame to measure sensory processing in children.  I want to use sndarray to play out a
numpy array I have created, containing a sound stimulus. But I can't seem to get any sound at all.  I'm not an
expert programmer so I would welcome any advice.

I'm using Windows 7, with python 2.7, and the array will play out fine (as float) if I use pyaudiere.  A
simplified version of my code is below - interestingly I also get no sound when I run the example which
someone has kindly posted as a comment on the sndarray doc page. I am baffled!

Many thanks
Caroline

from numpy import *
import pygame

SRATE=44100 # sample rate in Hz
DURATION=1 # duration in sec
# an array of floating-point random numbers
noise= array(random.randn(SRATE*DURATION))
pygame.mixer.pre_init(SRATE, 16, 1,4096)
pygame.init()
# make it int16, scale it for 16 bit
mysound=int16(noise.copy()*2**15)
snd=pygame.sndarray.make_sound(mysound)
snd.play()
pygame.time.wait(DURATION*1000)

Russell Jones | 4 May 15:17 2012
Picon

Re: Re : [pygame] raycasting engine performances (numpy array)



On 29 April 2012 20:48, Ian Mallett <geometrian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
As with others, absolutely: raycasting is going to be slow.  It's slow even in C, and that's kinda the reason GPUs were invented.  As far as optimization, often people set up 2D arrays laid out in memory with x as the second variable.  So, although this might not be possible with NumPy, if you can order your array accesses as arr[y][x], you might get better cache coherency.

On Fri, Apr 27, 2012 at 2:41 AM, nathan.open-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <nathan.open-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
So now my question is, can i write the game logic entirely in python and write the rendering part in C with OpenGL calls?
Yes.
 
Though using pyopengl or some other existing binding might be easier, or at least be useful reference to save you some of the integration effort.

Russell
stabbingfinger | 4 May 16:42 2012
Picon

Re: sndarray with numpy array in Windows

Hi, Caroline.


If you initialize the display before playing the sound it works. I know it is weird, but I've encountered this gotcha before--maybe someone familiar with the C source could comment.

If you don't want to display a window, there is a recipe for headless pygame you can use.

Gumm

On Fri, May 4, 2012 at 2:13 AM, Witton, Caroline <c.witton-Rq4gIEi9UVT10XsdtD+oqA@public.gmane.org> wrote:
Hello,

I'm a researcher using pygame to measure sensory processing in children.  I want to use sndarray to play out a numpy array I have created, containing a sound stimulus. But I can't seem to get any sound at all.  I'm not an expert programmer so I would welcome any advice.

I'm using Windows 7, with python 2.7, and the array will play out fine (as float) if I use pyaudiere.  A simplified version of my code is below - interestingly I also get no sound when I run the example which someone has kindly posted as a comment on the sndarray doc page. I am baffled!

Many thanks
Caroline

from numpy import *
import pygame

SRATE=44100 # sample rate in Hz
DURATION=1 # duration in sec
# an array of floating-point random numbers
noise= array(random.randn(SRATE*DURATION))
pygame.mixer.pre_init(SRATE, 16, 1,4096)
pygame.init()
# make it int16, scale it for 16 bit
mysound=int16(noise.copy()*2**15)
snd=pygame.sndarray.make_sound(mysound)
snd.play()
pygame.time.wait(DURATION*1000)



Witton, Caroline | 4 May 19:18 2012
Picon
Picon

RE: sndarray with numpy array in Windows

Hi, Gumm,

That works a treat - many thanks indeed!!

best wishes
Caroline

From: owner-pygame-users@...
[owner-pygame-users@...] on behalf of stabbingfinger [stabbingfinger@...]
Sent: 04 May 2012 15:42
To: pygame-users@...
Subject: Re: [pygame] sndarray with numpy array in Windows

Hi, Caroline.

If you initialize the display before playing the sound it works. I know it is weird, but I've encountered
this gotcha before--maybe someone familiar with the C source could comment.

If you don't want to display a window, there is a recipe for headless
pygame<http://pygame.org/wiki/DummyVideoDriver> you can use.

Gumm

On Fri, May 4, 2012 at 2:13 AM, Witton, Caroline
<c.witton@...<mailto:c.witton@...>> wrote:
Hello,

I'm a researcher using pygame to measure sensory processing in children.  I want to use sndarray to play out a
numpy array I have created, containing a sound stimulus. But I can't seem to get any sound at all.  I'm not an
expert programmer so I would welcome any advice.

I'm using Windows 7, with python 2.7, and the array will play out fine (as float) if I use pyaudiere.  A
simplified version of my code is below - interestingly I also get no sound when I run the example which
someone has kindly posted as a comment on the sndarray doc page. I am baffled!

Many thanks
Caroline

from numpy import *
import pygame

SRATE=44100 # sample rate in Hz
DURATION=1 # duration in sec
# an array of floating-point random numbers
noise= array(random.randn(SRATE*DURATION))
pygame.mixer.pre_init(SRATE, 16, 1,4096)
pygame.init()
# make it int16, scale it for 16 bit
mysound=int16(noise.copy()*2**15)
snd=pygame.sndarray.make_sound(mysound)
snd.play()
pygame.time.wait(DURATION*1000)

Bartosz Debski | 8 May 11:12 2012
Picon

Re: Resetting display

toggle_fullscreen will work only under X11.

I got this working with reloading pygame with new params. This is
working fine for me as long you are in menu of a game so you don't
care for a ingame stuff.

eg.
1. start a game  with basic setup
2. change settings in game menu and save the config.
3. reload pygame module with new setup.

working example:
http://www.pygame.org/project-Dark+Gates-1522-2710.html

No source avaliable atm, but if you are interested i can give you a
code example no problem.

Cheers

On Wed, Apr 4, 2012 at 3:31 PM, Radomir Dopieralski <pygame@...> wrote:
> On Wed, Apr 4, 2012 at 16:28, Nathan Biagini <nathan.open@...> wrote:
>> Hi,
>>
>> i'd like to know if i can, with pygame, reset the display stuffs. I
>> mean, i start with a certain resolution and i'd like to set the
>> fullscreen after a certain condition is raised, but i don't know how
>> to do that? Is that possible?
>
> Yes.
>
> http://www.pygame.org/docs/ref/display.html#pygame.display.toggle_fullscreen
> --
> Radomir Dopieralski

Radomir Dopieralski | 8 May 11:32 2012
Picon

Re: Resetting display

On Tue, May 8, 2012 at 11:12 AM, Bartosz Debski <bartosz@...> wrote:
> toggle_fullscreen will work only under X11.

I didn't know you could run pygame outside of X11.

[...]

--

-- 
Radomir Dopieralski

Silver | 9 May 05:30 2012
Picon

help with clock

I wrote a small clock program that I might use if it turns out well, but
I am having a small issue where the top of the arcs that grow over time
shifts when I would like it to stay still. Does anyone know how to
achieve this?
Attachment (clock.py): text/x-python, 1175 bytes
Bartosz Debski | 9 May 13:31 2012
Picon

Re: Resetting display

Well, i haven't tried to be honest but will toggle_fullscreen work
under Windows ?

On Tue, May 8, 2012 at 10:32 AM, Radomir Dopieralski
<pygame@...> wrote:
> On Tue, May 8, 2012 at 11:12 AM, Bartosz Debski <bartosz@...> wrote:
>> toggle_fullscreen will work only under X11.
>
> I didn't know you could run pygame outside of X11.
>
> [...]
>
> --
> Radomir Dopieralski

Julian Marchant | 9 May 14:29 2012
Picon

Re: Resetting display

No. Only X11, e.g. GNU/Linux (and I think Mac OS X is another example).

If you really want to use toggle_fullscreen when the program is run on X11 without also sacrificing
platform-independence, you could do something like:

fullscreen = not fullscreen
if not pygame.display.toggle_fullscreen():
    if fullscreen:
        window = pygame.display.set_mode(size, FULLSCREEN)
    else:
        window = pygame.display.set_mode(size)

That's of course assuming that the most recent comment in the docs (from 12/30/2010) is right about what
pygame.display.toggle_fullscreen returns.

--- On Wed, 5/9/12, Bartosz Debski <bartosz@...> wrote:

> From: Bartosz Debski <bartosz@...>
> Subject: Re: [pygame] Resetting display
> To: pygame-users@...
> Date: Wednesday, May 9, 2012, 11:31 AM
> Well, i haven't tried to be honest
> but will toggle_fullscreen work
> under Windows ?
> 
> On Tue, May 8, 2012 at 10:32 AM, Radomir Dopieralski
> <pygame@...>
> wrote:
> > On Tue, May 8, 2012 at 11:12 AM, Bartosz Debski <bartosz@...>
> wrote:
> >> toggle_fullscreen will work only under X11.
> >
> > I didn't know you could run pygame outside of X11.
> >
> > [...]
> >
> > --
> > Radomir Dopieralski
> 

Davy Mitchell | 9 May 23:02 2012
Picon

Re: Resetting display

Thanks Julian - handy for popping in my PyWeek game :-)

On 9 May 2012 13:29, Julian Marchant <onpon4@...> wrote:
> No. Only X11, e.g. GNU/Linux (and I think Mac OS X is another example).
>
> If you really want to use toggle_fullscreen when the program is run on X11 without also sacrificing
platform-independence, you could do something like:
>
> fullscreen = not fullscreen
> if not pygame.display.toggle_fullscreen():
>    if fullscreen:
>        window = pygame.display.set_mode(size, FULLSCREEN)
>    else:
>        window = pygame.display.set_mode(size)
>
> That's of course assuming that the most recent comment in the docs (from 12/30/2010) is right about what
pygame.display.toggle_fullscreen returns.
>
> --- On Wed, 5/9/12, Bartosz Debski <bartosz@...> wrote:
>
>> From: Bartosz Debski <bartosz@...>
>> Subject: Re: [pygame] Resetting display
>> To: pygame-users@...
>> Date: Wednesday, May 9, 2012, 11:31 AM
>> Well, i haven't tried to be honest
>> but will toggle_fullscreen work
>> under Windows ?
>>
>> On Tue, May 8, 2012 at 10:32 AM, Radomir Dopieralski
>> <pygame@...>
>> wrote:
>> > On Tue, May 8, 2012 at 11:12 AM, Bartosz Debski <bartosz@...>
>> wrote:
>> >> toggle_fullscreen will work only under X11.
>> >
>> > I didn't know you could run pygame outside of X11.
>> >
>> > [...]
>> >
>> > --
>> > Radomir Dopieralski
>>

--

-- 
--
  Davy's Blog Reborn - http://retrospaniel.wordpress.com


Gmane