problem: MIDI sound heard on wrong playback device
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
problem: MIDI sound heard on wrong playback device
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
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:
/usr/bin/timidity -B2,8 -Os -iAD
The output from "cat /proc/asound/cards" is:
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
Update: Rosegarden with QSynth works, however there is the following error:
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:
but the following is heard on the on-board sound card:
aplaymidi -p 128:0 test.mid
where "aplaymidi -l" shows:
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 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.
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.
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.
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).
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.
Last edited by thorkelljarl; 01-08-2009 at 07:30 PM.
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
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.
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.