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

[pygame] 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)