LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   problem: MIDI sound heard on wrong playback device (https://www.linuxquestions.org/questions/linux-software-2/problem-midi-sound-heard-on-wrong-playback-device-694570/)

opc 01-02-2009 04:38 PM

problem: MIDI sound heard on wrong playback device
 
Hello,

I recently got an M-Audio MobilePRE USB audio capture box. It works very nicely. It can record audio into Audacity, or into Ardour and Rosegarden via JACK. Playback from the same programs or with Amarok also works well. As does playback with Hydrogen via JACK. I therefore set it as the default soundcard using
Quote:

asoundconf set-default-card <Card name>
So far so good.

The problem is MIDI sound is not being sent to this new card. For example, in Rosegarden, the Audio tracks are played on the USB device but all the MIDI sounds are played back on the on-board soundcard. I would like to hear both on the USB device. The searching I've done on the subject has only confused me more. It must be the way ALSA, Timidity or JACK are configured on my system, but I don't know what to look for.

In JACK, I have experimented by connecting the General MIDI device output from Rosegarden to each of the four Timidity ports to no avail.

I am using Kubuntu 8.04.1 "Hardy" with Linux version 2.6.24-22-generic (buildd@vernadsky) (gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)) #1 SMP Mon Nov 24 18:32:42 UTC 2008. The PC is a ThinkPad R40.

Timidity is started at boot time as:
Quote:

/usr/bin/timidity -B2,8 -Os -iAD

The output from "cat /proc/asound/cards" is:
Quote:

0 [I82801DBICH4 ]: ICH4 - Intel 82801DB-ICH4
Intel 82801DB-ICH4 with AD1981B at irq 11
1 [Camera ]: USB-Audio - Camera
Camera at usb-0000:00:1d.7-1.5, full speed
2 [Academic ]: USB-Audio - MobilePre Academic
M Audio MobilePre Academic at usb-0000:00:1d.7-3.1, full speed
Similarly, "aplay -l" shows:
Quote:

**** List of PLAYBACK Hardware Devices ****
card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 0: Intel ICH [Intel 82801DB-ICH4]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 4: Intel ICH - IEC958 [Intel 82801DB-ICH4 - IEC958]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: Academic [MobilePre Academic], device 0: USB Audio [USB Audio]
Subdevices: 0/1
Subdevice #0: subdevice #0
The output from "lsmod |grep snd" is:
Quote:

snd_rtctimer 4640 2
snd_usb_audio 83936 5
snd_usb_lib 18432 1 snd_usb_audio
snd_hwdep 10500 1 snd_usb_audio
snd_intel8x0 35356 3
snd_ac97_codec 101028 1 snd_intel8x0
ac97_bus 3072 1 snd_ac97_codec
snd_pcm_oss 42144 0
snd_mixer_oss 17920 1 snd_pcm_oss
snd_pcm 78596 7 snd_usb_audio,snd_intel8x0,snd_ac97_codec,snd_pcm_oss
snd_seq_dummy 4868 0
snd_seq_oss 35584 0
snd_seq_midi 9376 0
snd_rawmidi 25760 2 snd_usb_lib,snd_seq_midi
snd_seq_midi_event 8320 2 snd_seq_oss,snd_seq_midi
snd_seq 54224 21 snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_seq_midi_event
snd_timer 24836 4 snd_rtctimer,snd_pcm,snd_seq
snd_seq_device 9612 5 snd_seq_dummy,snd_seq_oss,snd_seq_midi,snd_rawmidi,snd_seq
snd 56996 30 snd_rtctimer,snd_usb_audio,snd_usb_lib,snd_hwdep,snd_intel8x0,snd_ac97_codec,snd_pcm_oss,snd_mixer_o ss,snd_pcm,snd_seq_dummy,snd_seq_oss,snd_rawmidi,snd_seq,snd_timer,snd_seq_device
soundcore 8800 1 snd
snd_page_alloc 11400 2 snd_intel8x0,snd_pcm
usbcore 146412 7 usb_storage,libusual,snd_usb_audio,snd_usb_lib,ehci_hcd,uhci_hcd
Any help in routing MIDI sound to the external USB soundcard will be greatly appreciated.

Thanks!
opc

opc 01-04-2009 06:18 AM

configure ALSA to route MIDI to USB sound device
 
Update: Rosegarden with QSynth works, however there is the following error:
Code:

ALSA lib pcm_dmix.c:874:(snd_pcm_dmix_open) unable to open slave
Can't open pcm device 'default'.
Couldn't open ALSA pcm device (`s')

I am suspecting that ALSA is not configured correctly.
The following is heard on the USB audio device:
Code:

aplay test.wav
but the following is heard on the on-board sound card:
Code:

aplaymidi -p 128:0 test.mid
where "aplaymidi -l" shows:
Code:

Port    Client name                      Port name
 14:0    Midi Through                    Midi Through Port-0
128:0    TiMidity                        TiMidity port 0
128:1    TiMidity                        TiMidity port 1
128:2    TiMidity                        TiMidity port 2
128:3    TiMidity                        TiMidity port 3

Port 128:1 is also heard on the on-board card. Using MIDI ports 128:2 and 128:3 do not produce any sound on any card.

I just don't understand ALSA. As stated above, I used the asoundconf command to set the default card, but the files in /proc/asound show the original order. Such as the contents of /proc/asound/cards shown above. Nowhere in /etc/modprobe.d is there a reference to "major-116", so I don't know where the default card gets set.

So I guess my new question is if anybody knows where I can find a single source that can explain how ALSA works. I am unable to piece together a "big-picture" from what I've found so far. There are many disparate sources of information, some more than 5 years old. I would gladly RTFM, I just can't find it.

I'll keep plugging away.

-opc

opc 01-08-2009 03:08 PM

Update:

I now understand that when the default card is set using `asoundconf set-default-card <Card name>`, the change is made locally, at the user level. So when the system starts, the default card is not set to the USB device until the user logs in. The impact is that the Timidity daemon is started during the boot process so it gets "fixed" to the original sound card, which in my case is the on-board card. When I log in once the boot process has completed, the default card is changed per the commands in ~/.asoundrc and ~/.asoundrc.asoundconf, but timidity is oblivious to this change. Hence why MIDI tracks are heard via the on-board sound device, and all other audio is heard on the USB device.

The temporary work around:

The quick work-around is to restart the timidity daemon after logging in.
Code:

sudo /etc/init.d/timidity restart
This works to some extent. Now `aplaymidi -p 128:0 test.mid` is heard on the USB device. However, Rosegarden spits out "unable to open slave" errors and still won't play MIDI through Timidity. Rosegarden will play MIDI through QSynth, but there are lots of warnings of sequencer buffer overruns and lost events.

Somewhat more permanent solution:

Per the advice from https://help.ubuntu.com/community/SoundTroubleshooting, I updated /etc/modprobe.d/alsa-base so that my preferred sound card had index 0. I used
Code:

cat /proc/asound/modules
to get the module names. I have two modules with identical names (snd-usb-audio). However, looking at
Code:

cat /proc/asound/cards
the device of interest was consistently number 2 after several reboots. So I added the following to the bottom of /etc/modprobe.d/alsa-base
Code:

options snd_usb_audio index=3
options snd_usb_audio index=0
options snd_intel8x0 index=1

In my case, the first USB device is the web cam. So I am assigning it to index 3, then my preferred device to index 0 and finally the on-board card to index 1.

The only limitation is that the order is not fixed. If I remove or replace the web cam, or introduce another USB audio device like say a USB microphone, the order will change and this file will need to be manually changed again.

For all intents and purposes I was able to solve my problem. Through my frustration I have grown a little and learned a few things. But I still feel that I am lacking knowledge of the fundamentals of ALSA. I just need time and continued tinkering, I guess.

The next step is to get Rosegarden to work with Timidity, but this is beyond the scope of this thread.

Some of the links that helped:
http://alsa.opensrc.org/index.php/FAQ
http://www.thepenguin.org.uk/alsa/
http://alsa.opensrc.org/index.php/.asoundrc
http://ubuntuforums.org/showthread.php?t=619638
http://ubuntuforums.org/showthread.p...=disable+sound


Hope some of this may be useful to others.
-opc

Shadow_7 01-08-2009 05:51 PM

The easy answer is the re-index your soundcard modules so that the mobile pre is card 0. 0 is always default for applications that do not use alsa natively. And other apps that just don't know any better.

Answer B is to use the defaults.pcm.card 2 in your .asoundrc (which it sounds like alsaconf probably setup).

Although if it's just Midi you're worried about, you can run Timidity to use Jack. Easier said than done in some cases. I had to recompile timidity for that option on my distro (debian).

# timidity -iA -Oj

(and maybe some other options)

thorkelljarl 01-08-2009 07:29 PM

To simplify

If you don't use it, you might also go into your BIOS and see if you can disable the on board sound chip. My mother board manual recommends this if I install a sound card. Thereafter there's only one source for linux to deal with.

opc 01-21-2009 04:48 AM

Thanks for the replies. My system module died so I've been out of commission for a couple of weeks. I'm borrowing a laptop with Ubuntu Hardy. Not surprisingly, the same problem exists.

Nonetheless, I do have a fix for using Timidity with Rosegarden. As Shadow7 states in his post, Timidity must be run with the Jack option '-Oj'. Here is what I do now every time I log in:

1. sudo killall timidity
2. ...
3. qjackctl &
4. ALT-F2 and then type in the command 'timidity -iA -B2,8 -Oj -s 48000'

I run all audio applications with a sample rate of 48000 Hz because I read somewhere that this and setting the periods per buffer to 3 are optimal for USB sound devices.

Note: I am now running Linux kernel 2.6.24-23-rt #1 SMP PREEMPT RT Thu Nov 27 20:37:26 UTC 2008 i686.

For the second issue regarding re-indexing the sound cards, the challenge is that I have multiple devices with the same module name. The M-Audio and the Webcam have the snd-usb-audio module name. Maybe there is a way to rename modules for easier boot-time manipulation. This will be the subject of different thread. The current solution is to limit the devices that register as snd-usb-audio to one.

Thanks for the tip thorkelljarl. Alas, I cannot disable the on-board sound card in the bios.

Cheers,
-opc

EDIT: There is no need to kill pulseaudio (step 2 above). This step was left over from some of the troubleshooting I was doing. Everything works fine with pulseaudio running.


All times are GMT -5. The time now is 12:09 AM.