m.daae
Posts: 22
Joined: Thu Apr 02, 2015 4:59 pm

MIDI in - Audio Out - ALSA in the middle (?)

Thu Apr 16, 2015 11:29 pm

I have a two-octave MIDI/USB keyboard "LPK25" and a more-or-less generic C-Media USB audio interface. They are both recognised ... I think ...

Code: Select all

[email protected] ~ $ lsusb 
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 007: ID 0d8c:0014 C-Media Electronics, Inc. 
Bus 001 Device 004: ID 09e8:0076 AKAI  Professional M.I. Corp. LPK25 MIDI Keyboard
Bus 001 Device 005: ID 046d:c404 Logitech, Inc. TrackMan Wheel
Bus 001 Device 006: ID 413c:2107 Dell Computer Corp. 

Code: Select all

[email protected] ~ $ cat /proc/asound/cards 
 0 [LPK25          ]: USB-Audio - LPK25
                      AKAI professional LLC LPK25 at usb-bcm2708_usb-1.3, full speed
 1 [Device         ]: USB-Audio - USB Audio Device
                      C-Media Electronics Inc. USB Audio Device at usb-bcm2708_usb-1.2, full speed
 2 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA
I did modify a conf file at one point based on some information I found on the c-media site. I can't seem to find that information since plugging in the LPK25 so I don't know if I screwed something up by including that (new) device in the power-up sequence.

I would like to play around with some sample code on the ALSA site but .... I'm constantly amazing myself with my own ignorance: I have no idea -- and this is getting to be a pretty familiar refrain ;) -- what to do next to verify that MIDI is coming in and audio out is directed at my C-Media device.

TIA !

m.daae
Posts: 22
Joined: Thu Apr 02, 2015 4:59 pm

Re: MIDI in - Audio Out - ALSA in the middle (?)

Wed Apr 22, 2015 10:41 pm

I have half of the problem sort-of solved. It turns out amidi (an alsa utility) has a -d option that simply dumps the MIDI stream from the MIDI keyboard onto the screen... and mine just worked with "amidi -d" ... no port setting was required (which is a tiny source of confusion for me). The good news is amidi is open source (duh) and I may be able to unravel the code enough to find out what's going on with that. The challenge for me is just, at least temporarily, forgetting MSWindows and embracing the linux way of the world.

I am still in the dark regarding what to use for testing the non-standard audio out device. Maybe aplay will come to the rescue. Is there a standard .wav file with known parameters that could be used here?

TIA,
m.daae

User avatar
Douglas6
Posts: 4672
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: MIDI in - Audio Out - ALSA in the middle (?)

Wed Apr 22, 2015 11:49 pm

My go-to test for ALSA is

Code: Select all

aplay /usr/share/sounds/alsa/Front_Center.wav
If you've made no changes, that will play on the audio jack (possibly HDMI, if your monitor / TV is plugged in and has sound capabilities). To direct it to the USB soundcard, an easy hack is to modify /etc/modprobe.d/alsa-base.conf

Code: Select all

sudo nano /etc/modprobe.d/alsa-base.conf
and change the following line from '-2' to '0', so it looks like this

Code: Select all

options snd-usb-audio index=0
When you're ready to turn those MIDI inputs into ALSA output, a good standby soft(ware) synth(esizer) is fluidsynth:

Code: Select all

sudo apt-get install fluidsynth

m.daae
Posts: 22
Joined: Thu Apr 02, 2015 4:59 pm

Re: MIDI in - Audio Out - ALSA in the middle (?)

Thu Apr 23, 2015 10:38 pm

Douglas6 wrote:My go-to test for ALSA is

Code: Select all

aplay /usr/share/sounds/alsa/Front_Center.wav
If you've made no changes, that will play on the audio jack (possibly HDMI, if your monitor / TV is plugged in and has sound capabilities). To direct it to the USB soundcard, an easy hack is to modify /etc/modprobe.d/alsa-base.conf

Code: Select all

sudo nano /etc/modprobe.d/alsa-base.conf
and change the following line from '-2' to '0', so it looks like this

Code: Select all

options snd-usb-audio index=0
When you're ready to turn those MIDI inputs into ALSA output, a good standby soft(ware) synth(esizer) is fluidsynth:

Code: Select all

sudo apt-get install fluidsynth
Thanks! I already did a mod to the conf file based on information I found on the Pluggable Website (the distributor of the USB sound interface) The file looks like this:

Code: Select all

# autoloader aliases
install sound-slot-0 /sbin/modprobe snd-card-0
install sound-slot-1 /sbin/modprobe snd-card-1
install sound-slot-2 /sbin/modprobe snd-card-2
install sound-slot-3 /sbin/modprobe snd-card-3
install sound-slot-4 /sbin/modprobe snd-card-4
install sound-slot-5 /sbin/modprobe snd-card-5
install sound-slot-6 /sbin/modprobe snd-card-6
install sound-slot-7 /sbin/modprobe snd-card-7
# Cause optional modules to be loaded above generic modules
install snd /sbin/modprobe --ignore-install snd && { /sbin/modprobe --quiet snd-ioctl32 ; /sbin/modprobe --quiet snd-seq ; : ; }
install snd-rawmidi /sbin/modprobe --ignore-install snd-rawmidi && { /sbin/modprobe --quiet snd-seq-midi ; : ; }
install snd-emu10k1 /sbin/modprobe --ignore-install snd-emu10k1 && { /sbin/modprobe --quiet snd-emu10k1-synth ; : ; }
# Keep snd-pcsp from being loaded as first soundcard
options snd-pcsp index=-2
# Now :
options snd-usb-audio index=0
# Was options snd-usb-audio index=-2
# Added : 
options snd_bcm2835 index=1
# Prevent abnormal drivers from grabbing index 0
options bt87x index=-2
options cx88_alsa index=-2
options snd-atiixp-modem index=-2
options snd-intel8x0m index=-2
options snd-via82xx-modem index=-2
But I don't see the USB sound interface listed as "alsa" - and so I'm still kind'a confused ...

User avatar
Douglas6
Posts: 4672
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: MIDI in - Audio Out - ALSA in the middle (?)

Thu Apr 23, 2015 11:20 pm

Did you try the aplay command? It should be working. The changes you made forced the USB soundcard to index 0, which becomes the default ALSA device, meaning that you don't need to specify a device name for aplay or other audio software, it will use the default device.

You can list the ALSA devices with 'aplay -L' It should look a little like this at the beginning (My USB card, a Logitech USB Headset, is called 'Headset')

Code: Select all

$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=Headset
    Logitech USB Headset, USB Audio
    Default Audio Device
sysdefault:CARD=Headset
    Logitech USB Headset, USB Audio
    Default Audio Device
Again, you can crank up the volume using the 'alsamixer' command.

m.daae
Posts: 22
Joined: Thu Apr 02, 2015 4:59 pm

Re: MIDI in - Audio Out - ALSA in the middle (?)

Fri Apr 24, 2015 9:59 pm

Douglas6 wrote:Did you try the aplay command? It should be working. The changes you made forced the USB soundcard to index 0, which becomes the default ALSA device, meaning that you don't need to specify a device name for aplay or other audio software, it will use the default device.

You can list the ALSA devices with 'aplay -L' It should look a little like this at the beginning (My USB card, a Logitech USB Headset, is called 'Headset')

Code: Select all

$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=Headset
    Logitech USB Headset, USB Audio
    Default Audio Device
sysdefault:CARD=Headset
    Logitech USB Headset, USB Audio
    Default Audio Device
Again, you can crank up the volume using the 'alsamixer' command.
aplay is not being very nice at all:

Code: Select all

[email protected] ~ $ aplay /usr/share/sounds/alsa/Front_Center.wav
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
aplay: main:682: audio open error: No such file or directory
and ... I can't figure out how to select my USB audio interface for alsamixer - the default seems to be my USB MIDI Keyboard which is at the top of the list... and not audio at all really. I was somewhat successful with

Code: Select all

Speaker-test -Ddefault:Device -c 2
though the volume was low and that brings me back to alsamixer. ouch .

User avatar
Douglas6
Posts: 4672
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: MIDI in - Audio Out - ALSA in the middle (?)

Fri Apr 24, 2015 10:42 pm

Ah, sorry, I see now. Your MIDI device is also a USB 'sound card' as far as ALSA is concerned, and IT is grabbing the default index 0. SImple, we just need to be a little more specific in the alsa-base.conf. First you need the vendor and product IDs of your cards. List them with lsusb: (I've plugged in an AKAI MIDI keyboard along with my Lgoitech sound card):

Code: Select all

$ lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 005: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 006: ID 046d:0a0b Logitech, Inc. ClearChat Pro USB
Bus 001 Device 007: ID 09e8:0072 AKAI  Professional M.I. Corp.
The IDs are the vendor:product IDs, so, my sound card and keyboard vendor IDs are 0x046d, 0x09e8 and the product IDs are 0x0a0b,0x0072

Now, edit /etc/modprobe.d/alsa-base.conf again, and change that line to look like this: (use your own vendor and product IDs):

Code: Select all

options snd-usb-audio index=0,1 vid=0x046d,0x09e8 pid=0x0a0b,0x0072
You can remove the 'options snd_bcm2835 index=1' line, or change it to '2'.
Reboot. That will put the sound card at index 0 (the default), and the MIDI keyboard at index 1. Remember that your MIDI device is no longer the default, so MIDI software like amidi will need the device (port) specified explicitly, e.g.

Code: Select all

amidi -p hw:1,0 -d
Hope that's clear.

m.daae
Posts: 22
Joined: Thu Apr 02, 2015 4:59 pm

Re: MIDI in - Audio Out - ALSA in the middle (?)

Sat Apr 25, 2015 11:19 pm

Douglas6 wrote:Ah, sorry ... Hope that's clear.
Quite clear. Thank you very much (again!)

Speaker-test is still working and now Front_Center.wav is working as shown (!)
On to the next challenge: build some alsa demo code and see if the USB Midi keyboard will drive a virtual synth (the actual code) and play over the head phones

-m.daae

Return to “Graphics, sound and multimedia”