Page 1 of 1

How can I map buttons triggering sounds on specific Octo outputs?

Posted: Wed Sep 05, 2018 12:45 am
by Red
Hello, I am in need of some assistance from someone smarter than me.
My intention is to press a button that is wired to a GPIO on the raspberry pi 3 B+, and having it play a sound on a specific output on the Octo.
So if I have four buttons, then each button will be mapped to its own dedicated Octo output.

What I have attempted thus far using python
My proof of concept is trying to play a sound on channel 1 and output on the Octo channel 1 when pressed, and a different sound on channel 8 ont the Octo channel 8 when released. The issue here is both sounds play out of the same Octo output.
Here's the source for my experiment:

import pygame
from gpiozero import Button
from signal import pause

pygame.mixer.pre_init(44100, -16, 1, 512)
pygame.mixer.init()
pygame.mixer.set_num_channels(8)
pygame.init()

drum1 = pygame.mixer.Sound('samples/drum_bass_hard.wav')
drum2 = pygame.mixer.Sound('samples/drum_cymbal_hard.wav')

channel1 = pygame.mixer.Channel(0)
channel8 = pygame.mixer.Channel(7)

btn = Button(4)

def play_chan1():
channel1.play(drum1)

def play_chan8():
channel8.play(drum2)

btn.when_pressed = play_chan1
btn.when_released = play_chan8

pause()

Re: How can I map buttons triggering sounds on specific Octo outputs?

Posted: Thu Oct 25, 2018 11:12 am
by JerryH
I too have an interest in this kind of setup, but from what I've been able to discern, pygame doesn't allow you to direct channels to individual outputs does it?

Rather, you may have to look into something like pyPortAudio

Re: How can I map buttons triggering sounds on specific Octo outputs?

Posted: Sun Jan 27, 2019 7:54 am
by Verona
To save people from a load of searching and disappointment:
pyPortAudio is deprecated. Too many problems with the pablio layer in Portaudio, plus various platform-specific horror stories. Please try fastaudio instead
I can find nothing helpful on the subject of fastaudio. Sadly.