Page 1 of 1

Timidity output device

Posted: Mon Jan 14, 2019 10:22 am
by johnlane
I'm experimenting with MIDI on a Pi, I'm using a PiDac for audio output. I have a working setup using FluidSynth but wanted to try Timidity. However, I've been RTFM for some time on this but i cannot find an option to specify the output device. I need to specify the PiDac instead of the default output device.

For example, Fluidsynth allows me to specify this using a command-line argument "-o audio.alsa.device=hw:1"

I can't find out how to do that with Timidity, if anyone knows then I'd appreciate a pointer...

Re: Timidity output device

Posted: Mon Jan 21, 2019 9:47 am
by tvjon
Your DAC looks pretty good. I don't have such, but I've just plugged in a cheap C-media usb audio "card", & now my old midi keyboard is playing through it, so hopefully this will work for your nice DAC. Perhaps you could confirm that, so we can all know what to expect if we buy similar?

So, find out where it lives in the grand scheme of ALSA:

$ cat /proc/asound/cards

0 [ALSA ]: bcm2835_alsa - bcm2835 ALSA
bcm2835 ALSA

1 [CameraB409241 ]: USB-Audio - USB Camera-B4.09.24.1
OmniVision Technologies, Inc. USB Camera-B4.09.24.1 at usb-3f980000.usb-1.5, hi

2 [Interface ]: USB-Audio - USB Uno MIDI Interface
M-Audio USB Uno MIDI Interface at usb-3f980000.usb-1.3, full speed

3 [Loopback ]: Loopback - Loopback
Loopback 1

4 [Device ]: USB-Audio - USB PnP Sound Device
USB PnP Sound Device at usb-3f980000.usb-1.2.4, full speed


So, it's device 4

Let's tell timidity that:


$ timidity -iA -Os plughw:4

Press some key on the midi keyboard, & the corresponding sounds appear in my headphones plugged into the C-media.

Re: Timidity output device

Posted: Tue Jan 29, 2019 9:48 pm
by johnlane
Hi, thanks for your reply, but I can't get it to work. It works just fine with Fluidsynth but I cannot get sound out of Timidity (through the Dac, I can get sound via the onboard audio).

My /proc/asound/cards

Code: Select all

0 [ALSA           ]: bcm2835_alsa - bcm2835 ALSA
                      bcm2835 ALSA
1 [IQaudIODAC     ]: IQaudIODAC - IQaudIODAC
                      IQaudIODAC
When I launch Fluidsyth, like below, it works fine:

Code: Select all

fluidsynth --server --audio-driver=alsa -o audio.alsa.device=hw:1 /usr/share/soundfonts/FluidR3_GM.sf2
When, I launch Timidity, like below, it doesn't work (it runs, but no sound):

Code: Select all

timidity -iA -Os plughw:1
For completeness, my timidity.cfg

Code: Select all

soundfont /usr/share/soundfonts/FluidR3_GM.sf2
I have tried searching for any info elsewhere on the web that shows use of "plughw" with Timidity but cannot find anything.

Re: Timidity output device

Posted: Tue Jan 29, 2019 11:12 pm
by tvjon
In more detail, here's the sequence of events for me (in different terminals, but doesn't affect the sequence)

$ cat /proc/asound/cards
0 [ALSA ]: bcm2835_alsa - bcm2835 ALSA
bcm2835 ALSA
1 [CameraB409241 ]: USB-Audio - USB Camera-B4.09.24.1
OmniVision Technologies, Inc. USB Camera-B4.09.24.1 at usb-3f980000.usb-1.5, hi
2 [Interface ]: USB-Audio - USB Uno MIDI Interface
M-Audio USB Uno MIDI Interface at usb-3f980000.usb-1.3, full speed
3 [Loopback ]: Loopback - Loopback
Loopback 1
4 [Device ]: USB-Audio - USB PnP Sound Device
USB PnP Sound Device at usb-3f980000.usb-1.2.3, full speed


/usr/local/share/timidity/timidity.cfg

contains

soundfont /home/pi/midi/soundfonts/TimGM6mb.sf2


$ aconnect -l
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 24: 'USB Uno MIDI Interface' [type=kernel,card=2]
0 'USB Uno MIDI Interface MIDI 1'



$ timidity -iA -Os plughw:4
Requested buffer size 32768, fragment size 8192
ALSA pcm 'default' set buffer size 32768, period size 8192 bytes
TiMidity starting in ALSA server mode
Opening sequencer port: 128:0 128:1 128:2 128:3

$ aconnect -l
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 24: 'USB Uno MIDI Interface' [type=kernel,card=2]
0 'USB Uno MIDI Interface MIDI 1'
client 128: 'TiMidity' [type=user,pid=2698]
0 'TiMidity port 0 '
1 'TiMidity port 1 '
2 'TiMidity port 2 '
3 'TiMidity port 3 '


$ aconnect 24:0 128:0


$ aconnect -l
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 24: 'USB Uno MIDI Interface' [type=kernel,card=2]
0 'USB Uno MIDI Interface MIDI 1'
Connecting To: 128:0
client 128: 'TiMidity' [type=user,pid=2489]
0 'TiMidity port 0 '
Connected From: 24:0
1 'TiMidity port 1 '
2 'TiMidity port 2 '
3 'TiMidity port 3 '


Now I have sound via the usb audio "card".

Do you have similar for the aconnects?

Re: Timidity output device

Posted: Wed Jan 30, 2019 8:15 pm
by johnlane
Hi, here's my output:

Code: Select all

# cat /proc/asound/cards

 0 [ALSA           ]: bcm2835_alsa - bcm2835 ALSA
                      bcm2835 ALSA
 1 [IQaudIODAC     ]: IQaudIODAC - IQaudIODAC
                      IQaudIODAC
 2 [Interface      ]: USB-Audio - USB MIDI Interface
                      USB MIDI Interface at usb-3f980000.usb-1.3, full speed


# grep ^soundfont /etc/timidity++/timidity.cfg
soundfont /usr/share/soundfonts/FluidR3_GM.sf2

# aconnect -l
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 24: 'USB MIDI Interface' [type=kernel,card=2]
    0 'USB MIDI Interface MIDI 1'

# timidity -iA -Os plughw:1
Requested buffer size 32768, fragment size 8192
ALSA pcm 'default' set buffer size 32768, period size 8192 bytes
TiMidity starting in ALSA server mode
Opening sequencer port: 128:0 128:1 128:2 128:3

# aconnect -l
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 24: 'USB MIDI Interface' [type=kernel,card=2]
    0 'USB MIDI Interface MIDI 1'
client 128: 'TiMidity' [type=user,pid=351]
    0 'TiMidity port 0 '
    1 'TiMidity port 1 '
    2 'TiMidity port 2 '
    3 'TiMidity port 3 '

#  aconnect 24:0 128:0

# aconnect -l
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 24: 'USB MIDI Interface' [type=kernel,card=2]
    0 'USB MIDI Interface MIDI 1'
        Connecting To: 128:0
client 128: 'TiMidity' [type=user,pid=351]
    0 'TiMidity port 0 '
        Connected From: 24:0
    1 'TiMidity port 1 '
    2 'TiMidity port 2 '
    3 'TiMidity port 3 '


(play keyboard, no sound)

(stop Timidity)

# fluidsynth --server --audio-driver=alsa -o audio.alsa.device=hw:1 /usr/share/soundfonts/FluidR3_GM.sf2

 aconnect -l
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 24: 'USB MIDI Interface' [type=kernel,card=2]
    0 'USB MIDI Interface MIDI 1'
client 128: 'FLUID Synth (369)' [type=user,pid=369]
    0 'Synth input port (369:0)'

# aconnect 24:0 128:0

# aconnect -l
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 24: 'USB MIDI Interface' [type=kernel,card=2]
    0 'USB MIDI Interface MIDI 1'
        Connecting To: 128:0
client 128: 'FLUID Synth (369)' [type=user,pid=369]
    0 'Synth input port (369:0)'
        Connected From: 24:0

(play keyboard, sound emitted)


Re: Timidity output device

Posted: Thu Jan 31, 2019 8:45 am
by tvjon
John,

I don't have any I2S based audio kit, so will try to get one at some point. However I bought a DAC, but USB based, so not too dear, & indeed that line:

timidity -iA -Os plughw:4

does not let any audio appear from its output!

$ cat /proc/asound/cards
0 [ALSA ]: bcm2835_alsa - bcm2835 ALSA
bcm2835 ALSA
1 [CameraB409241 ]: USB-Audio - USB Camera-B4.09.24.1
OmniVision Technologies, Inc. USB Camera-B4.09.24.1 at usb-3f980000.usb-1.5, hi
2 [Interface ]: USB-Audio - USB Uno MIDI Interface
M-Audio USB Uno MIDI Interface at usb-3f980000.usb-1.3, full speed
3 [Loopback ]: Loopback - Loopback
Loopback 1
4 [DAC ]: USB-Audio - USB Audio DAC
Burr-Brown from TI USB Audio DAC at usb-3f980000.usb-1.2.3, full speed

So, I changed that line to:

$ timidity -iA -Os audio.alsa.device=hw:4

& I now have audio.

Can you try that please, & also:

$ timidity -v

What's your command line to get omxplayer to play an audio file through your DAC?

Re: Timidity output device

Posted: Thu Jan 31, 2019 9:06 pm
by johnlane
Hey, well passing "audio.alsa.device=hw:1" didn't work for me. But this did:

Code: Select all

$ TIMIDITY_PCM_NAME=hw:1 timidity -iA -Os
Found that when searching the net for "audio.alsa.device", it does not appear to be documented on the man page.

My version of Timidity is "TiMidity++ version 2.15.0", I am running ArchLinux and I don't have OMXPlayer.

Re: Timidity output device

Posted: Thu Jan 31, 2019 10:41 pm
by tvjon
Good find.

It also works for my DAC, so that means at least for the IQ, & possibly other cards running timidity, a specific syntax is necessary, hmmm.

$ timidity -v
TiMidity++ version 2.14.0

omxplayer doesn't need X, so if you wanted to test it at some point, you could install it. Besides audio it's a good player for some videos, as it uses RPi's gpu so isn't stressing the cpu.

Re: Timidity output device

Posted: Fri Feb 01, 2019 9:32 am
by johnlane
I thought I'd have a trawl through the source code and, from what I can tell (at least with the 2.15.0 sources), the only way to control the output device is to use the "TIMIDITY_PCM_NAME" environment variable.

I could not find any mention whatsoever of neither "plughw" nor "audio.alsa.device" anywhere within the sources. And "TIMIDITY_PCM_NAME" is mentioned only in one place, in the function

Code: Select all

static char *get_pcm_name(void)
{
  char *name;
  if (dpm.name && *dpm.name)
    return dpm.name;
  name = getenv("TIMIDITY_PCM_NAME");
  if (! name || ! *name)
    name = "default";
  return name;
}
It's used as the "name" parameter given to the ALSA API snd_pcm_open function which takes a value formed according to this specification. So you should be able to use the descriptive name returned by "aplay -L" (upper case) instead of the hw:X,Y returned by "aplay -l" (lower case). Haven't tested this though - will do tonight!

I think it's odd that there is neither command-line argument nor config file parameter available to specify the output device, and that the only way available is to use an environment variable.

Re: Timidity output device

Posted: Fri Feb 01, 2019 11:36 am
by tvjon
You beat me to it. As you have it working now, I was going to check that when less busy. There's other versions on Github too.

I already had looked at the output of aplay -L, but thinking about it, probably not tried it with the Burr-Brown.

Anyway, this does work, so hopefully will for you.

Zipped aplay attached.

$ timidity -iA 200 -Os CARD=DAC

Requested buffer size 32768, fragment size 8192
ALSA pcm 'default' set buffer size 32768, period size 8192 bytes
TiMidity starting in ALSA server mode
Opening sequencer port: 128:0 128:1 128:2 128:3

That method does have the advantage that when it moves position it should still be found.

The problem though is inconsistency. Such will not work for specifying the output card to play an audio file.
For example:

$ mplayer -ao alsa:device=CARD=DAC "Track01.mp3"

MPlayer 1.3.0 (Debian), built with gcc-6.2.1 (C) 2000-2016 MPlayer Team
...
libavformat version 57.56.101 (external)
Mismatching header version 57.56.100
Audio only file format detected.
==========================================================================
Opening audio decoder: [mpg123] MPEG 1.0/2.0/2.5 layers I, II, III
AUDIO: 44100 Hz, 2 ch, s16le, 192.0 kbit/13.61% (ratio: 24000->176400)
Selected audio codec: [mpg123] afm: mpg123 (MPEG 1.0/2.0/2.5 layers I, II, III)
==========================================================================
[AO_ALSA] alsa-lib: pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM CARD:DAC

Same problem using other players.



"I think it's odd that there is neither command-line argument nor config file parameter available to specify the output device, and that the only way available is to use an environment variable."

Yes, yet my Burr-Brown DAC *does* work with the command lines I've posted in previous posts. So there is another variable, the sound card.