2
votes

I want to play youtube videos and programmatically direct firefox's audio out to a particular sound card.

I think I would do something like firefox | aplay -D hw:x,y. Yields:

Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono aplay: set_params:1059: Sample format non available Available formats: - S16_LE

Trying firefox | aplay -D hw:1,0 -f S16_LE -c 2

Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 8000 Hz, Stereo Warning: rate is not accurate (requested = 8000Hz, got = 44100Hz) please, try the plug plugin

Finally, firefox | aplay -D plughw:1,0 -f S16_LE -c 2

Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 8000 Hz, Stereo

The command-line suggests that it worked, but audio came out of hw:0,0 (the default).

Do I need to make my own plugin? Or do I need to force alsa to take 44100Hz?

Also, I refuse to use pulse since the memory leak bug makes it crash often.

2

2 Answers

6
votes

I'm pretty sure flash always uses the default sound card, so you need to change pcm.default. You could do so by editing ~/.asoundrc and adding something like:

pcm.!default {
    type hw
    card 0
    device 2
}

Of course, that affects all apps, but I believe can also set ALSA_CONFIG_PATH (in the environment) to specify a different file, so you could do it for just Firefox.

The ALSA FAQ indicates there are ALSA_PCM_CARD and ALSA_CARD environment variables that may work as well.

These variables actually work because they're part of the default also config in /usr/share/alsa/alsa.conf:

    @args.CARD {
            type string
            default {
                    @func getenv
                    vars [
                            ALSA_PCM_CARD
                            ALSA_CARD
                    ]
                    default {
                            @func refer
                            name defaults.pcm.card
                    }
            }
    }

So, you should be able to do this:

ALSA_PCM_CARD=1 ALSA_PCM_DEVICE=3 firefox

using the appropriate card and device numbers from your system. Or of course you could add your own environment variable (or other conditional check) into your ALSA configuration.

0
votes

Flash uses its own output config, independent of Firefox. Define FLASH_ALSA_DEVICE before running your browser, it tells Flash what ALSA PCM to use instead of the default.