Archives June 2012

ALSA Loopback for Fun and Profit

So I finally got the ALSA loopback working with gstreamer. Key is to use ALSA's plugs to get the right format on both sides of the capture:

{% for spk in cards %}
pcm.spk{{spk}} {
  type plug
  slave{
    pcm "hw:Loopback{{spk}},0,0"
    rate 48000
    format S16_LE
  }
}
pcm.monitor{{spk}}_snoop {
  type dsnoop
  ipc_key 68659{{spk}}
  slave{
    pcm "hw:Loopback{{spk}},1,0"
    format S16_LE
  }
}
pcm.monitor{{spk}} {
    type plug 
    slave.pcm "monitor{{spk}}_snoop"
}
{% endfor %}

pcm.!default {
 @func getenv
 vars [ DISPLAY_ALSA_DEVICE ]
 default spk1
}

And then the only wrinkle left is that you really want to use:

alsasrc device ...

Continue reading

Really Dumb HTML5 Video Tag Back-end

So you want to create a stupid-and-dirty HTML5 video tag to allow you to monitor a (local-only) multicast stream from your (Django + Nginx) web site?  Not something to be seen by "real people", but a way for you to see if anything is broadcasting?

This is a pretty simplistic thing, again; do *not* do this on a production site!

@permission_required( 'videostream' )
def video( request, channel=None, scale=2 ):
    """Stream video content to the client"""
    uri = 'udp://%s:%s'%( channel.target_ip, channel.target_port )
    width,height = [int(x)//scale for x in channel.resolution.split('x') ]
    def stream( ):
        command = [
            'gst-launch',
                '-e',
                '-q ...

Continue reading

Alsa Loopback Devices for Fun, but not yet profit...

So you want to be able to capture the output of N Alsa "devices" (think N separate programs). It seems like the correct solution to this should be an Alsa loopback device... so, here's how to create them.

  • Add snd-aloop to your /etc/modules
  • Add a file named /etc/modprobe.d/alsa-aloop.conf (content below)
  • Create a .asoundrc that makes it easy to reference the loopbacks...

The aloop conf file looks much like a dummy conf file:

options snd-aloop index=1,2,3,4,5,6,7,8 enable=1,1,1,1,1,1,1,1 pcm_substreams=4 ...

Continue reading

How can an audio server take up 900MB of RAM?

So we want to capture the (alsa) output of processes and pipe it into an mpeg-ts stream.  Except gstreamer's alsasrc can't do "monitor", so we wind up having to do a pulsesrc... which brings the server to its knees in a few minutes with memory exhaustion for no reason I can fathom.

Annoying part is that I'm not even trying to deal with that part of the system (the encoding or capture), I'm just trying to confirm that the audio is getting produced properly by streaming it to something I can actually hear.  9am meeting tomorrow ...

Continue reading

Experience has some value... and risk

Each time I sit down to help someone relatively new to coding I find myself somewhat awe-struck at how much I've "forgotten".  Just install nginx with gunicorn and django in a virtualenv.  Package up your code with a setup.py using distribute.  Run your unittests with Nose.  Use sphinx and embedded doctests.

You tell someone that kind of thing and they come back with "what's a unit test?" or "how do I get to the server's GUI?" (hey, they use Windows, how quaint) and you realize that all this stuff is just sitting back there in the ...

Continue reading

Daily archives

Previous month

May 2012

Next month

July 2012

Archives