Testing audio from command line

Al Mak posted Apr 21 '17, 22:12:

I'm new at Raspberry Pi, but I've got everything setup with SSH and it appears to be running as expected. The problem I have is that the RPi wont power my MPK49, and I am waiting for a power supply to arrive. In the meantime, is it possible for me to test my DAC and samples by triggering a wav file from a command line? I placed one on my USB, so I can see it under /media. Seems like a simple thing, but I'm coming up blank.

AlexM posted Apr 22 '17, 12:06:

Perhaps the easiest thing to do is edit the samplerbox.py file so that it plays a note, or notes on startup.

First remount as read-write by entering the command: mount -o remount,rw /

Now open the script: nano SamplerBox/samplerbox.py

Right near the bottom, and under the line LoadSamples() add in this block of code (paste using SHIFT+INSERT):

time.sleep(1) # let the samples load first
def play_note(midinote, velocity=127):
    global playingnotes, samples
    playingnotes.setdefault(midinote, []).append(samples[midinote, velocity].play(midinote))

def stop_note(midinote):
    global samples
    if midinote in playingnotes:
        for n in playingnotes[midinote]:
        playingnotes[midinote] = []

play_note(midinote=40, velocity=127)

If you want to get a bit crazy, replace those last 3 lines with the following to play a sequence of notes:

for i in xrange(40, 60): # play notes 40 through to 60

A bit of a workaround, but it should do the trick! :)

AlexM posted Apr 22 '17, 12:10:

Oh and CTRL-X and Y to save changes.

You'll also need to stop the samplerbox.py script which is autorun on startup:

systemctl stop samplerbox
and re-run your new modified version:
python SamplerBox/samplerbox.py


  (not published)
  I want to post as guest