Finally sound output to both cards

January 28, 2009

This was the last migration regression I have had since I left windows for linux. I have one integrated sound card and a USB FM radio transmitter, both have worked individually since day 1, but getting both working at the same time has not been easy. The past week I’v spent perhaps 20 hours to get a .asoundrc that does this, I have to say that the official ALSA documentation may be the worst I’v seen this far and the unofficial isn’t much better, so I had to read lots of e-mails in the ALSA-users mailing list looking for ppl with similar problems and get my own solution built up by small bits and peace’s from the answers there, the usual answer to my question ‘how can i get the same output on 2 sound cards’ was almost always ‘you don’t want it, they will go out of sync, fast’ while this is indeed true I don’t care about that issue since sending the signal through FM it would always be out of sync compared to cables anyway. If anyone wants the same thing and need to know how I did it, here’s my .asoundrc

pcm.!default {
type plug
slave.pcm "quad"
route_policy duplicate

ctl.!default {
type hw
card mb

pcm.quad {
type multi;
slaves.a.pcm "mb";
slaves.a.channels 2;
slaves.b.pcm "usb";
slaves.b.channels 2;

bindings.0.slave a 0
bindings.1.slave a 1
bindings.2.slave b 0
bindings.3.slave b 1

pcm.mb {
type dmix
ipc_key 1024
slave {
pcm "hw:0"
period_time 0
period_size 2048
buffer_size 65536
buffer_time 0
periods 128
rate 48000
channels 2

pcm.usb {
type dmix
ipc_key 2048
slave {
pcm "hw:1"
period_time 0
period_size 2048
buffer_size 65536
buffer_time 0
periods 128
rate 48000
channels 2

ctl.mb {
type hw
card 0

ctl.usb {
type hw
card 1


while gnome screensaver is running; do

January 21, 2009

2 nights ago my lovely friends on IRC dicided to talk about me, as I have a loud highlight sound I eventually woke up, 4 AM, not verry pleasent, so I thought that there must be a good way to solve this. I realized that turning the highlights off when I went to bed would not work and the away systems I found only worked if I was inactive on IRC but I still want the highlights if Im surfung the web.

After a few minutes of googeling I was thinking about /proc/interrupts but I have USB mouse and keyboard so I can’t find out if Im active at the computer that way, but I thought ‘how does gnome-screensaver do it?’ (I still don’t know that). More googeling and man page reading it turns out that I can run

gnome-screensaver-command -q

and it will tell me if the screensaver is running or not. Great, I only have to make a little script that check if the screensaver is running or not and run it once a minute in cron. The script worked fine when I tested it, but when placed in cron I got an error:

** Message: Failed to connect to the D-BUS daemon: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed.

Huh? Well google results said the DBUS_SESSION_BUS_ADDRESS was wrong, of course.. cron and environment variables.. Here my google searches failed me, or perhaps I didn’t look hard enough, but I turned to the great ArchLinux communety (thanx goes to Antti_Alien@freenode)(yes I left Ubuntu and installed Arch about a week ago) and here is what I came up with

IFS=`echo -en "\n\b"`

# Get the PID for existing screensaver process.
PID=$(pgrep gnome-screensav)

# Find DBUS session bus for this session and export it.
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ 2>/dev/null`
sleep 1

i=$(gnome-screensaver-command -q | head -1);
if [ $i = "The screensaver is inactive" ];
if [ -e /var/lock/screen_saver_a.lock ];
rm /var/lock/screen_saver_a.lock
exit 0
exit 0
echo $crap_var > /var/lock/screen_saver_a.lock

Very simple, very efficient. It checks if the screensaver is running and creates a file with some crap inside it. if no screensaver is running it removes that file. So all I had to do now was edit my highlight event so it looks for the file. Works like a charm.

I havent thought of any other use for this yet but if I need it I know it’s easy.

Generate playlists

September 3, 2008

One thing I was missing in ARAS 1.2 was the ability to play jingles or station IDs after a set number of music tracks but with playlist support it wasn’t that hard to do anyway. I’ll show how I’v done, it’ll look a bit chopped up but this way it’s easier to understand for the non bash gurus and to fit other needs.

First, create playlists:

find /home/novus/music -type f -iname *.ogg | sed -e 's/\/home\/novus\//file:\/\/\/home\/novus\//' > /home/novus/music.m3u
find /home/novus/jingles -type f -iname *.ogg | sed -e 's/\/home\/novus\//file:\/\/\/home\/novus\//' > /home/novus/jingles.m3u

This will first find all URIs for filesnames ending with .ogg in /home/novus/music and /home/novus/jingles (recursively) and then substitute /home/novus/ with file:///home/novus/ (this is needed or ARAS will not work, at all) and send it to /home/novus/music.m3u & /home/novus/jingles.m3u

Those playlists would be absolutely ok to play with ARAS, but we want them combined.

and random:

shuf /home/novus/music.m3u > /tmp/randommusic.m3u
shuf /home/novus/jingles.m3u > /tmp/randomjingles.m3u

and now let the “magic” begin:

sed -e 'i\\n\n\n' /tmp/randomjingles.m3u > /tmp/spacedjingles.m3u

here we’v taken the randomized jingles playlist and inserted 4 CRLF (new line) before each original line in /tmp/randomjingles.m3u (i\ is one line and each \n after is one line)

paste /tmp/randommusic.m3u /tmp/spacedjingles.m3u > /tmp/mixeduglyplaylist.m3u

here we paste the files together to one file, containing 2 fields, 1st field is the music and the 2nd is the jingles and empty lines. the 2 fields are separated with a single TAB

sed -e 's/\t/\n/g' /tmp/mixeduglyplaylist.m3u > /tmp/stilluglyplaylist.m3u

and here we replace all TABs with a new line

final thing we need to do before it’s finished is to remove all blank lines

sed '/^$/d' /tmp/stilluglyplaylist.m3u > /home/novus/playlist.m3u

so now we have a playlist that’ll play 5 random songs in /home/novus/music/ and then one jingle in /home/novus/jingles 5 songs, 1 jingle and so on.

one thing you need to keep in mind is that you don’t “run out of” jingles or music. if the music collection is 400 songs and if you want a jingle after every 5 songs you need to have 80 jingles (400/5) (or at least 80 URIs to jingles in u’r jingle playlist before adding the empty lines)

another thing to keep in mind is that ARAS isn’t forgiving on spaces in URIs, I solved it simply by running the rename perlscript (which you should have in one of u’r bin dirs)

WARNING! be careful where you are when running it!

~/music$ rename 's/ /_/g' *
~/music$ rename 's/ /_/g' */*
~/music$ rename 's/ /_/g' */*/*

that will rename every file and dir in current dir and 2 levels down


August 27, 2008

I used to work at the local community radio station and still keep in touch to see how things go there, they had to cut back on the music hours during the summer due to increased licence fees and I suggested to have a computer playing Creative-Commons music playing during the night. Getting the music haven’t been any problem but finding Linux software that would fit the specs:

* simple to use.
* reliable.
* creating log-files.
* ability to put jingles and station IDs in between music tracks.
* being able to handle big music collections.

About 3 weeks ago I stumbled across ARAS (1.0 at that time) which looked really promising, it missed the options of log-files and it wasn’t possible to put jingles in between tracks, but it looked promising enough that I sent an e-mail to the developer (Erasmo Alonso Iglesias) with a wishlist and 3 days ago a new version was released that had what I was hoping for: log-files creation and m3u playlist support, so now whats left is only testing and some bash script writing for playlist creation.

Control individual sound channels

August 8, 2008

I got a surround sound card on my motherboard so there’s 4 out ports and the monitor speakers is connected to one, wireless headphones to one, normal speakers to one and a radio broadcast device to the last and I got fed up with having to open the volume control every time I wanted to change volume on one of the channels so I started to look in the repos for a console mixer program that I could use to change volume and found that amixer would be perfect for my needs, and it was really simple too.

To show status of a mixer just run amixer this will show the default card. I had to change to card 0 which for some reason isn’t the default so it’s amixer -c 0 that will show the status for card 0. To change volume the syntax is as follows.

amixer -c N set <SCONTROL> <PARAMETER>

N = card number, if your mixer shows as it should when amixer is run without parameters -c N is not needed
<SCONTROL> = Simple mixer control, the channel, you will see it when you run amixer (inside the single quites)
<PARAMETER> = how you want to change the volume (other things can be changed too) I use 5%+ and 5%-

so an example would look like: amixer -c 0 set Master 5%+

and I added keyboard shortcuts, for that just use your favorite shortcuts manager (like xbindkeys & xbindkeys-config)

Please just disappear

August 5, 2008

I while ago I installed soma (soma-suite) on my ubuntu desktop and about a week ago something went horribly wrong, every time I do something with packages I get prompted with an error regarding soma. After asking for help on the ubuntu forums (post) all I’v managed so far is to get rid of one error just to get a new one. The old windows way of format-reinstall is something I just will refuse to do, becourse it’s too much work to get my (almost) perfect desktop back up and running + I know that it’s solvable, I just don’t know how. yet

Hello world!

August 4, 2008

So I finally decided to do as everyone else.. start a blog! I guess it’ll mainly be about computer tinkering but don’t be surprised if I throw something completely unrelated on here too.

about me:

25 years old (in 9 days) living in Sweden (Eskilstuna to be exact) computer geek migrated to GNU/Linux a few months ago and feel like a complete noob sometimes and Hammarby fan season card holder for the football (soccer for you ppl across the pond) club and goes to a few hockey/bandy/handball games during the winter. Working hard in a bakery, which it’s time to leave for now.