Permalink
Browse files

Each sound gets its own channel. Switch sampler tester to wave files.

  • Loading branch information...
mrichardson23 committed Oct 8, 2012
1 parent 1d21b0f commit 9a3c95295ca88ab9b4228ef59c6fb4a16fc1050c
Showing with 14 additions and 17 deletions.
  1. +10 −13 pygame-sampler2.py
  2. +4 −4 test-sampler.py
View
@@ -1,36 +1,33 @@
import pygame.mixer
-from time import *
+from time import sleep
import RPi.GPIO as GPIO
-import sys
+from sys import exit
GPIO.setmode(GPIO.BCM)
GPIO.setup(7, GPIO.IN)
GPIO.setup(8, GPIO.IN)
GPIO.setup(9, GPIO.IN)
pygame.mixer.init(48000, -16, 1, 1024)
-pygame.init()
soundA = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Center.wav")
soundB = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Left.wav")
soundC = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Right.wav")
-soundChannel = pygame.mixer.Channel(1)
+soundChannelA = pygame.mixer.Channel(1)
+soundChannelB = pygame.mixer.Channel(2)
+soundChannelC = pygame.mixer.Channel(3)
print "Sampler Ready."
+
while True:
try:
if (GPIO.input(7) == True):
- soundChannel.play(soundA)
- sleep(soundA.get_length())
+ soundChannelA.play(soundA)
if (GPIO.input(8) == True):
- soundB.play()
- sleep(soundB.get_length())
- soundB.stop()
+ soundChannelB.play(soundB)
if (GPIO.input(9) == True):
- soundC.play()
- sleep(soundC.get_length())
- soundC.stop()
+ soundChannelC.play(soundC)
sleep(.01)
except KeyboardInterrupt:
- sys.exit()
+ exit()
View
@@ -2,12 +2,12 @@
from time import *
import sys
-pygame.mixer.init(48000, -8,2,15000)
+pygame.mixer.init(48000, -16, 2, 1024)
pygame.init()
-soundA = pygame.mixer.Sound("/usr/share/sounds/KDE-Im-Cant-Connect.ogg")
-soundB = pygame.mixer.Sound("/usr/share/sounds/KDE-Im-Message-In.ogg")
-soundC = pygame.mixer.Sound("/usr/share/sounds/KDE-Im-Message-Out.ogg")
+soundA = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Center.wav")
+soundB = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Left.wav")
+soundC = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Right.wav")
print "Sampler Ready."

0 comments on commit 9a3c952

Please sign in to comment.