I have a Raspberry Pi 2 and a set of speakers connected to the 3.5mm headphone jack. I've got most audio coming out of my speakers by running
amixer set name='PCM Playback Route' 1
. pygame.mixer
works absolutely wonderfully without doing anything special. However, when I try to run my pygame.midi
code I hear nothing.
I don't think it's a problem with my code personally. If I run python -m pygame.examples.midi --output
, I see the graphical piano, no errors are thrown, but I hear no audio out.
I'm running Ubuntu Mate on my pi, but this thread makes it seem like that's not the issue.
-
My code just reads input from my MIDI keyboard, and tries to play the output, I will post it on github if it is useful for resolving my issueLuke Taylor– Luke Taylor2015年12月05日 23:54:44 +00:00Commented Dec 5, 2015 at 23:54
3 Answers 3
I solved it by running sudo apt-get install timidity
and then changing my outport port from 0 to 3.
I had a similar problem with pygame
. However, I found that my issue was completely unrelated. This may be the case for you as well.
The problem is likely not a product of an issue with the pygame.midi
, so much as it lies with the fact that your raspberry pi may be configured to forward its audio output to the HDMI cable connection.
I found that a fix can be arranged with two simple commands:
Typing the following commands tells us what our audio output is configured to:
amixer cget name='PCM Playback Route'
My output was this: (your's should be similar)
numid=3,iface=MIXER,name='PCM Playback Route'
; type=INTEGER,access=rw------,values=1,min=0,max=2,step=0
: values=0
If the last line (value) is 0, the audio output is configured to the HDMI. Changing this value to 1
can easily allow the sound output to go through the 3.5mm audio jack!
Do this using this command:
amixer cget name='PCM Playback Route' 1
And that is all that there should be to it!
-
it should be 'cset' instead of 'cget' in the last block of code :)Sylvain– Sylvain2017年03月12日 18:30:26 +00:00Commented Mar 12, 2017 at 18:30
Probable cause of the problem can be in the output port mismatch.
Type aconnect -i
to display a list of the readable input ports. These are the ports which provide incoming MIDI data.
$ sudo aconnect -i
response should have something like:
client 0: 'System' [type=kernel]
etc....
client 20: 'USB MIDI Interface' [type-kernel, card=1]
0 'USB MIDI Interface MIDI 1'
Type aconnect -o
to display a list of the writable output ports. These are the ports which send outgoing MIDI data.
Again; response should have something like:
client 20: 'USB MIDI Interface' [type-kernel, card=1]
0 'USB MIDI Interface MIDI 1'
Finally, type aconnect 14:0 20:0
to establish a bridge between the RaspberryPi port [14] in my case and the MIDI OUT port [20] {my case}.
$ sudo aconnect 14:0 20:0
Type aconnect -x
to remove all connections when finished. Individual connections can be removed using the -d option. If you ever need usage information about aconnect
, just type aconnect -h
or man aconnect
.
Good Luck!
-
1The OP solved the problem by running
sudo apt-get install timidity
and then changing the outport port from 0 to 3. Just read his old answer.Ingo– Ingo2019年03月09日 20:39:13 +00:00Commented Mar 9, 2019 at 20:39