Advertisement
Guest User

Pygame problem with stereo sound

a guest
Dec 1st, 2011
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. import numpy as np
  2. import pygame as pg
  3. import time
  4.  
  5. frequency, samplerate, duration = 400, 44100, 20000
  6. nchannels = 1 # change to 2 for stereo 
  7. pg.mixer.pre_init(channels=nchannels, frequency=samplerate)
  8. pg.init()
  9.  
  10. sinusoid = (2**15 - 1) * np.sin(2.0 * np.pi * frequency * np.arange(0, duration) / float(samplerate))
  11. samples = np.array(sinusoid, dtype=np.int16)
  12. if nchannels > 1: #copy mono signal to two channels
  13.     samples = np.tile(samples, (nchannels, 1)).T
  14. sound = pg.sndarray.make_sound(samples)
  15. sound.play()
  16.  
  17. time.sleep(duration/float(samplerate))
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement