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

Moderator: flatmax

Post Reply
Red
Posts: 1
Joined: Wed Sep 05, 2018 12:13 am

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

Post by Red » Wed Sep 05, 2018 12:45 am

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()

JerryH
Posts: 1
Joined: Thu Oct 25, 2018 10:54 am

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

Post by JerryH » Thu Oct 25, 2018 11:12 am

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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests