Make Firefox Use ALSA Loopback

What other apps and distros do you use to round out your studio?

Moderators: khz, MattKingUSA

Post Reply
GraysonPeddie
Established Member
Posts: 617
Joined: Sun Feb 12, 2012 11:12 pm
Location: Altha, FL
Contact:

Make Firefox Use ALSA Loopback

Post by GraysonPeddie »

Is there any way to make Firefox use ALSA Loopback? I don't want to use PulseAudio.

When I start to play The Talos Principles in Steam, I heard a lot of cracking-- maybe it's choppiness, but when I killall pulseaudio and use ALSA loopback instead, I start to play a game and all of that crackling/choppiness is gone. I think that games from Steam are outputting through ALSA Loopback, but if I use Firefox and watch YouTube videos through HTML5, I get no sound. Start cadence-pulse2loopback again, and now I get sound.

Here's another one: Kodi/Plex. If PulseAudio is running, I can only see PulseAudio as default and Loopback through PulseAudio. Stop Kodi/Plex, killall pulseaudio, and now I can use HDMI directly through Kodi/Plex.

Should I show .asoundrc? I think it is controlled by Cadence, but I could be wrong.

If I can get Firefox to cooperate with ALSA Loopback (snd_aloop), I'd gladly get rid of PulseAudio completely. Besides, PulseAudio does not have a place in my computer.

Update: The following two commands worked:

Code: Select all

firefox | aplay -Dcard:Loopback --format=S32_LE -r 48000
firefox | aplay -Dplughw:0,1 --format=S32_LE -r 48000
This video has sound:
https://www.youtube.com/watch?v=bvAHtmu8YO4

However, this video did not have sound played through aplay:
https://www.youtube.com/watch?v=L1ZqhvRCjEE

To work around the problem, I ran PulseAudio and both of the videos' sound are working.
--Grayson Peddie

Music Interest: New Age w/ a mix of modern smooth jazz, light techno/trance & downtempo -- something Epcot Future World/Tomorrowland-flavored.

User avatar
thetotalchaos
Established Member
Posts: 183
Joined: Mon Sep 29, 2014 8:29 pm
Contact:

Re: Make Firefox Use ALSA Loopback

Post by thetotalchaos »

Hi GraysonPeddie

Here is a good article that allows you to unleash the full potential of HTML5 video in firefox (38 or later). Can't say that it will solve your problem on 100% but at least you can watch Youtube live streams without the flash malware ;)

http://www.linuxveda.com/2015/04/02/ena ... fox-linux/

I am using Pulseaudio on Archlinux (Parabola GNU/Linux-Libre to be exact) with Gnome 3.16 and i don't have any issues whatsoever, only benefits. The only software that has the potential to mess up my sound is actually Cadence (nevertheless falkTX rules), so i am using Qjackctl and Patchage instead. By the way Parabola has RT kernel and bunch of pro-audio related goodies in their official repositories, staff not officially included in Arch.

Best regards Totalchaos
Check out my latest music album The girl with the stars in her eyes
https://totalchaos-music.bandcamp.com/a ... n-her-eyes

emarsk
Established Member
Posts: 96
Joined: Wed Jul 27, 2011 3:50 pm

Re: Make Firefox Use ALSA Loopback

Post by emarsk »

My ~/.asoundrc looks like this:

Code: Select all

ctl.!default { type hw; card 2 }

## ALSA JACK PCM PLUGIN
## http://jackaudio.org/faq/routing_alsa.html
## http://www.alsa-project.org/main/index.php/Asoundrc
pcm.jackplug {
	type plug
	slave { pcm "rawjack" }
	hint { description "JACK Audio Connection Kit" }
}
pcm.rawjack {
	type jack
	playback_ports {
		0 system:playback_1
		1 system:playback_2
	}
	capture_ports {
		0 system:capture_1
		1 system:capture_2
	}
}
pcm.!default { type plug; slave { pcm "rawjack" } }
and I get Firefox working through Jack with no hassle (both videos work for me).
You need to install the jack alsa-plugin, libasound module, or whatever is called in your distro.
Please, avoid some common spelling errors:
http://theoatmeal.com/comics/misspelling

GraysonPeddie
Established Member
Posts: 617
Joined: Sun Feb 12, 2012 11:12 pm
Location: Altha, FL
Contact:

Re: Make Firefox Use ALSA Loopback

Post by GraysonPeddie »

I suppose I will have to back up my .asoundrc, as that might prevent ALSA Loopback from working.

Code: Select all

# ------------------------------------------------------
# Custom asoundrc file for use with snd-aloop and JACK
#
# use it like this:
# env JACK_SAMPLE_RATE=44100 JACK_PERIOD_SIZE=1024 alsa_in (...)
#

# ------------------------------------------------------
# playback device
pcm.aloopPlayback {
  type dmix
  ipc_key 1
  ipc_key_add_uid true
  slave {
    pcm "hw:Loopback,0,0"
    format S32_LE
    rate {
      @func igetenv
      vars [ JACK_SAMPLE_RATE ]
      default 44100
    }
    period_size {
      @func igetenv
      vars [ JACK_PERIOD_SIZE ]
      default 1024
    }
    buffer_size 4096
  }
}

# capture device
pcm.aloopCapture {
  type dsnoop
  ipc_key 2
  ipc_key_add_uid true
  slave {
    pcm "hw:Loopback,0,1"
    format S32_LE
    rate {
      @func igetenv
      vars [ JACK_SAMPLE_RATE ]
      default 44100
    }
    period_size {
      @func igetenv
      vars [ JACK_PERIOD_SIZE ]
      default 1024
    }
    buffer_size 4096
  }
}

# duplex device
pcm.aloopDuplex {
  type asym
  playback.pcm "aloopPlayback"
  capture.pcm "aloopCapture"
}

# ------------------------------------------------------
# default device
pcm.!default {
  type plug
  slave.pcm "aloopDuplex"
}

# ------------------------------------------------------
# alsa_in -j alsa_in -dcloop -q 1
pcm.cloop {
  type dsnoop
  ipc_key 3
  ipc_key_add_uid true
  slave {
    pcm "hw:Loopback,1,0"
    format S32_LE
    rate {
      @func igetenv
      vars [ JACK_SAMPLE_RATE ]
      default 44100
    }
    period_size {
      @func igetenv
      vars [ JACK_PERIOD_SIZE ]
      default 1024
    }
    buffer_size 32768
  }
}

# ------------------------------------------------------
# alsa_out -j alsa_out -dploop -q 1
pcm.ploop {
  type plug
  slave.pcm "hw:Loopback,1,1"
}
--Grayson Peddie

Music Interest: New Age w/ a mix of modern smooth jazz, light techno/trance & downtempo -- something Epcot Future World/Tomorrowland-flavored.

GraysonPeddie
Established Member
Posts: 617
Joined: Sun Feb 12, 2012 11:12 pm
Location: Altha, FL
Contact:

Re: Make Firefox Use ALSA Loopback

Post by GraysonPeddie »

Well, at least I can get sound through ALSA-to-JACK plugin, which is what Cadence generated:

Code: Select all

pcm.!default {
    type plug
    slave { pcm "jack" }
}

pcm.jack {
    type jack
    playback_ports {
        0 system:playback_1
        1 system:playback_2
    }
    capture_ports {
        0 system:capture_1
        1 system:capture_2
    }
}

ctl.mixer0 {
    type hw
    card 0
}
But I don't understand why I don't get sound using Loopback in Firefox.
--Grayson Peddie

Music Interest: New Age w/ a mix of modern smooth jazz, light techno/trance & downtempo -- something Epcot Future World/Tomorrowland-flavored.

GraysonPeddie
Established Member
Posts: 617
Joined: Sun Feb 12, 2012 11:12 pm
Location: Altha, FL
Contact:

Re: Make Firefox Use ALSA Loopback

Post by GraysonPeddie »

falkTX wrote:the loopback option needs to have the bridge tool running (alsa_in/out or zita_a2j/j2a).
also make sure their ports are connected to the system ports.

one thing to note is that you need to restart alsa apps (like firefox) after you change the asoundrc file.
Okay:

(Loop) zita: does not work with two videos I linked above.
(Loop) alsa_out: works with the first video, but not the second video.
(ALSA-JACK): works with both videos.

Now the only issue I have is Steam games when using ALSA-to-JACK bridge without a loopback in between. I don't get any sound at all. So I switched to ALSA Loopback and the games that I have all worked with sound.

So, in order to work around the problem, I will have to switch between these two:

ALSA -> Loop -> JACK (Games)
ALSA -> JACK (Firefox)

Another application I've tried is GNOME Music (part of GNOME 3.16) which worked with both.

Update as of 11:20: Ha... This is strange. Both of the videos when using Loopback seem to be working! I don't know why... Maybe it could be GStreamer or something?
--Grayson Peddie

Music Interest: New Age w/ a mix of modern smooth jazz, light techno/trance & downtempo -- something Epcot Future World/Tomorrowland-flavored.

Post Reply