MIDI in Linux via Wine and embedded in the browser

Wow, maybe I should start using this blog!  Anyway, here’s a few interesting things to do in Linux if you are still stuck on MIDI.

A few days ago I was thinking about the old days and looking at my old archives of my webpages from 1997 and prior.  Back then one of the cool things we were doing was to embed MIDI sound files into your page so when it opened up in the browser the MIDI would start playing automatically.  It’s still possible to playback embedded MIDI natively on Linux with Firefox.  The basic steps are as follows:

1) Install mozplugger and timidity

1a) You actually need to configure timidity to use proper soundfonts (assuming you don’t have a MIDI board in your computer). I’m not going to go into this since it’s documented very well elsewhere, start here if you are using Ubuntu, but I don’t recommend going too far with that help page. Only the section about “Installing Timidity” is important. There are lots of posts on Ubuntu forums and Linuxquestions forums as well to help you. The key is to get a good sounding set of soundfonts otherwise the instruments sound weird.

1b) I also don’t recommend running Timidity as a daemon on a Linux box that uses Pulseaudio. Use a tool such as sysv-rc-conf to remove it from your runlevels so it doesn’t start with the OS.

2) Edit the file /etc/mozpluggerrc and basically delete everything in that file except type in (or edit) the following:

audio/mid:midi,mid:MIDI audio file
audio/x-mid:midi,mid:MIDI audio file
audio/midi:midi,mid:MIDI audio file
audio/x-midi:midi,mid:MIDI audio file
controls noisy stream: timidity "$file"

Basically what you are doing is to tell mozplugger to act as a Firefox plugin only for MIDI files.

3) Restart Firefox and do about:plugins in the address bar to make sure you see mozplugger acting as the plugin for MIDI files. Navigate to a webpage with an embedded MIDI such as this page and test it out.

4) If it doesn’t work and you don’t see the 3 play buttons and don’t hear the music, download a MIDI from somewhere on the Internet and try to play it like “timidity xxxx” in a shell and see what it spits out.

———————————————————————————————

There are two other really cool MIDI programs that are native to Windows but I figured out a way to get them running via Wine and I just think they are really cool so I wanted to share.  Both of these programs are like “environmental sounds” generators like those old school bedside radios you used to see from Sharper Image or the places in the mall that sell expensive off-beat stuff.

Aire Freshener by Peter Hirschberg

Syntrillium’s Wind Chimes

Apparently Syntrillium was bought out by Adobe and Adobe decided not to proceed with development of most of their software such as Wind Chimes or the venerable Cool Edit Pro that many old school computer geeks will fondly remember.  They also had a lot of other really cool software like screen savers that moved to the rhythm of music and stuff like that.  That was really cutting edge back in the mid-90′s.

In order to run these programs in Linux via Wine it’s not so easy to just install the programs and expect them to work with Wine’s Alsa-Midi device.  At least it didn’t work for me that easy.  What I finally discovered to get these programs to work is to first make Wine to see the Timidity MIDI mappers via Alsa.  In order to accomplish this, I created some simple scripts to load Timidity as an Alsa sequencer and then run the programs with Wine.

Firstly, I recommend installing these programs into their own Wine environment so as to not mess with your existing main Wine directory under /home/xxxx/.wine and to avoid any potential problems. In order to use a special “sandbox” Wine environment you specify the WINEPREFIX environment variable something like this: env WINEPREFIX=/home/xxxx/bin/chimes/ wine setup.exe
That will install the program into a Wine environment in /home/xxxx/bin/chimes/ After you get all this figured out it’s on to making and testing the scripts. Below is my script for the Syntrillium wind chimes program.

#!/bin/bash
timidity -iA & disown
export WINEPREFIX="/home/xxxx/bin/chimes/"
cd /home/xxxx/bin/chimes/drive_c/chimes/
wine ./chimes.exe &
wait
killall timidity

Basically what this does is to start up a Timidity Alsa sequencer, then Wine is called to execute the Windows chimes binary, then Timidity is killed after you close the chimes program. Here is my script for the Aire Freshener program (I didn’t use a special Wine environment for this one).

#!/bin/bash
timidity -iA & disown
cd "/home/xxxx/.wine/drive_c/Program Files/Aire Freshener 2.0/"
wine "Aire Freshener.exe" &
wait
killall timidity

Hope you enjoy some old school MIDI on Linux!

Posted in Audio, Wine | Tagged , , , , , , , , , , , | 1 Comment

Gulf of Mexico BP Oil Gusher/Spill Webcam List

Here is a VLC/mplayer compatible (pls) playlist of 10 live webcams showing the action at the bottom of the Gulf of Mexico. Just copy and paste the text below into a .pls file and open it with your favorite player.


File1=mms://a1686.l9789245685.c97892.g.lm.akamaistream.net/D/1686/97892/v0001/reflector:45685
Title1=Skandi Neptune
Length1=-2147483648
NumberOfEntries=10
Version=2
File2=mms://a288.l9789244287.c97892.g.lm.akamaistream.net/D/288/97892/v0001/reflector:44287
Title2=mms://a288.l9789244287.c97892.g.lm.akamaistream.net/D/288/97892/v0001/reflector:44287
Length2=-2147483648
NumberOfEntries=10
Version=2
File3=mms://a839.l9789244838.c97892.g.lm.akamaistream.net/D/839/97892/v0001/reflector:44838
Title3=Oceaneering International III
Length3=-2147483648
NumberOfEntries=10
Version=2
File4=mms://a567.l9789246566.c97892.g.lm.akamaistream.net/D/567/97892/v0001/reflector:46566
Title4=Osprey-230
Length4=-2147483648
NumberOfEntries=10
Version=2
File5=mms://a1031.l9789255030.c97892.g.lm.akamaistream.net/D/1031/97892/v0001/reflector:55030
Title5=Viking Poseidon
Length5=-2147483648
NumberOfEntries=10
Version=2
File6=mms://a1236.l9789237235.c97892.g.lm.akamaistream.net/D/1236/97892/v0001/reflector:37235
Title6=Canyon
Length6=-2147483648
NumberOfEntries=10
Version=2
File7=mms://a459.l9789222458.c97892.g.lm.akamaistream.net/D/459/97892/v0001/reflector:22458
Title7=Oceaneering
Length7=-2147483648
NumberOfEntries=10
Version=2
File8=mms://a1176.l9789247175.c97892.g.lm.akamaistream.net/D/1176/97892/v0001/reflector:47175
Title8=Oceaneering International
Length8=-2147483648
NumberOfEntries=10
Version=2
File9=mms://a1146.l9789221145.c97892.g.lm.akamaistream.net/D/1146/97892/v0001/reflector:21145
Title9=Osprey-230
Length9=-2147483648
NumberOfEntries=10
Version=2
File10=mms://a1524.l9789235523.c97892.g.lm.akamaistream.net/D/1524/97892/v0001/reflector:35523
Title10=Canyon
Length10=-2147483648
NumberOfEntries=10
Version=2

Posted in Uncategorized | Tagged , , , , , , | 1 Comment

Linux Scanner Recorder (rev 3)

In the past I posted a few tips and scripts for doing voice operated audio recording (VOX) under Linux.  I’ve done more research on this over time and now have what I believe to be a more refined version as well as finally figured out how to make a timed script with the help of folks from LinuxQuestions.org.

#!/bin/bash
read -p "How many seconds to run? ==> " count_secs
if [[ $count_secs -gt 0 ]]
then
rec -r 22050 -c 1 -p | sox -p OUTPUT.mp3 silence 1 0.1 1% -1 0.5 1% &
my_PID=$!
sleep $count_secs
kill -15 $my_PID
fi

When you run the above script it will ask you to input the total recording time in seconds, then end itself when that time expires. I’ve hard coded the sox command to output a 22 kHz, mono, 32 kbps MP3 file. There are still many many ways to modify and improve this script, but this is working for my needs now.

I’ve also learned a lot more about how to use the “silence” option in sox thanks to this blog post which I suggest you read to understand how to tweak the parameters.  The way I hardcoded the volume thresholds and silence detection time works well to my ear as far as cutting silence from scanner radio traffic. YMMV.

I have one other revised script which first uses arecord and then sends the output to sox for trimming.  The method below has an advantage in that you can more finely tweak the initial capture parameters.  The disadvantage to this method is that there is a second separate processing step with sox, instead of doing it all in one shot as in the first script.

#!/bin/bash
#USAGE: ./sox_vox_recorder.sh xxx output.mp3
#USAGE: Records from line-in for xxx seconds to output.mp3, then detects and trims silence
TIME=$1
OUTPUT=$2
arecord -f S16_LE -c1 -r22050 -t raw -d ${TIME} | lame -r -s 22.05 -m m -b 64 - ${OUTPUT} ;
sleep 1 ;
sox ${OUTPUT} ${OUTPUT}_processed.mp3 silence 1 0.1 1% -1 0.5 1% ;

I can see lots of tweaks to both of these scripts, such as capturing with OGG, or making a case-selection menu to choose capture parameters, and so forth. Maybe I’ll play with this in the future.

Posted in Audio, pulseaudio, sox | Tagged , , , , , , , , , , , | 2 Comments

Soft-Telecine PAL to NTSC MPEG2

Thought I’d post this as I haven’t found all this information in one place.  Sometimes I like to take random movies I’ve downloaded off the net and encode and burn them to standard NTSC DVD.  The problem is a lot of the videos you find are from PAL (25 fps) source and/or they use out of the ordinary aspect ratios like 2.45:1 or 1.91:1.  These two issues can give you major headaches when trying to get them onto DVD and preserve the proper aspect ratio and smooth frame rate.

There’s a number of solutions to these problems which I’ll outline below.

Convert “Any” PAL to NTSC MPEG2-PS (DVD), Soft-Telecine method

mencoder INPUT_PAL.avi -vf scale=720:480,harddup -srate 48000 /
-af lavcresample=48000 -ovc lavc -oac lavc -of mpeg -lavcopts / vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800: /
vbitrate=5000:keyint=15:vstrict=0:acodec=ac3:abitrate=224: /
aspect=16/9 -mpegopts format=dvd:tsaf:tele_src=25: /
tele_dest=30000/1001 -o OUTPUT_NTSC.mpg

This “soft-telecine” method flags the frames for 25 fps to 29.97 fps to make the file NTSC compliant without changing the actual frame rate.

Dealing with the Aspect Ratio problem

The mencoder command above is incomplete because if you’ll notice it assumes you have a source already encoded at 720×480 with a pixel aspect of 1:1 and a display aspect of 16:9.  Of course this is never the case, so you need to make a few modifications.  We need to do some simple math.

Example:  Source file has a display aspect of 2.45:1 and a resolution of 640×261.

Desired output is NTSC-DVD with 16:9 display aspect:  (480)*(16/9)=854, and (854)/(2.45)=349, so we’ll encode to 720×350 and pad/expand the remainder to 480.

mencoder uses the expand method, portions of the above command line would therefore be modified like this “-vf scale=720:350,expand=720:480″ and make sure the -lavcopts part has “aspect=16/9″ in it somewhere.

If you happen to prefer ffmpeg, it uses the padding method and you would achieve the same thing by having the following in the command line “-s 720:350 -padtop 65 -padbottom 65 -aspect 16:9″.

Posted in Uncategorized | Tagged , , , , , , | 1 Comment

Karmic + IVTV 1.4.1 + Pulseaudio + MythTV = Ubungo

I just updated my main box to Karmic this past week.  This is a 32 bit box that was first installed with Hardy.

Overall it looks like they improved a bunch of stuff.  I noticed a lot of stupid annoyances with Gnome/Nautilus are gone now, and the new Pulseaudio stuff looks good.

I use this box as my main PC as well as MythTV frontend/backend with one other PC on the network as a frontend only.  My capture card is the Hauppauge PVR-250.  I run a heavily patched version of 0.21-fixes from SVN built to my needs.  For Karmic I had to update it to r20877 due to some weirdness with glibc 2.10+, anyway that was the easy part…

After compiling and attempting to run it, I wasn’t getting any audio, and the video was choppy.  My first thought was to blame pulseaudio due to the debug messages I was getting and also the fact that if I changed my “profile” in the new gnome-volume-control panel it would make audio come and go, but this fact actually turned out to be a semi red herring.

After a little investigating I discovered to my surprise that grabbing video directly from the PVR-250 via “cat /dev/video0 > output.mpg” was also producing the same screwed up video/audio as Myth live TV.  Then I checked the behavior of my frontend only machine, same problem there…  Strange, what could be causing this?  IVTV it must be.  Jaunty had IVTV module v1.4.0, Karmic has v1.4.1 which appears to be non-stable at the present time.

So I wanted to try and compile a 1.4.0 module for Karmic but couldn’t find the source on the IVTV page, so I gave up on that.  Anyway long story short, I ended up solving these very strange problems by doing the following:

1)  I found out that for some very strange reason, the ivtv module needs to be re-loaded AFTER the mythbackend is started!  WTF!  and why does this fix the problem?  Any feedback on this would be appreciated.  Does it have something to do with this weird new Karmic thing where they start all the init programs in strange order to improve the boot speed?

2)  Declare EXPERIMENTALLY_ALLOW_PULSE_AUDIO=1 in my .profile.

All is well again.  Now to go enjoy Karmic.

UPDATE: I finally figured out what was giving me the problem with ivtv, it’s PEBKAC. Back in Feisty (I think) I added the command “v4l2-ctl -b off” to my mythbackend init script. I did this as a workaround to an Xv rendering playback bug with VLC and recordings made from PVR cards with the VBI closed-captioning enabled. Anyway, I guess with the newer ivtv module it screws things up, because now I removed that command and all is back to normal.

Posted in Myth TV, pulseaudio | Tagged , , , , , | 1 Comment

Spikes in xorg and Jerky Video in MythTV and VLC….

This might be of some use to folks running Gnome 2.24 in Ubuntu or Fedora or whatever.  I was recently trying to debug a very annoying problem where every minute or so my MythTV playback would get jittery with a corresponding CPU spike in xorg usage.  The same thing would happen in other video players like VLC.  It didn’t make any difference what kind of output rendering was being used.

It turns out this extremely annoying problem is due to stupid gnome-screensaver!  At least it was on my machine.  Take a look at this.  It’s supposed to be fixed in Gnome 2.26+.  Well, I just thought I’d put this one out there, because it’s very difficult to debug, and I see occasional posts about jittery video playback in Linux.  Of course, a great majority of those problems are due to proprietary video drivers though.

Posted in Uncategorized | Tagged , , , , , | 2 Comments

VOX Recording in Linux (part 2)

After I made my last post about how to do line-in recordings from your scanner radio with silence detection and cutting, also known as VOX recording in the old days, I started looking at SoX the Linux Sound eXchange CLI audio processing application. Using SoX is a lot slicker than my arecord-mp3splt-mpgjoin method. It lets you do the recording, silence detection, and mp3 encoding in one line, and it puts everything into one audio file, no muss no fuss.

Here are some examples:

rec -r 44100 -p | sox -p OUTPUT.mp3 silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d

rec -r 22050 -c 1 -p | sox -p OUTPUT.mp3 silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d

The first one will give you a 44.1 kHz, stereo, 128 kbps MP3. The second one will give you a 22.05 kHz, mono, 32 kbps MP3.

The rec command does the recording, -r specifies the sampling rate and -c sets the amount of audio channels, “-p” means the input is piped to another command. The sox pipe also needs a “-p” to tell it that its input is coming from a pipe, in this case the rec command.

The crypt CLI switches in the piped sox command “silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d” is what does the silence detection and trimming. It means to cut silence from the beginning of the file and parts within the middle and end. “xx:xx:xx.x” is in hh:mm:ss.s format and tells sox the minimum duration to consider valid audio. In my examples I have this set to 0.5 seconds for valid audio. The “-45d” means -45dB and is the minimum valid audio level to do trimming. In other words, if you were to say -100d, basically everything would be considered valid and there would be no trimming, you will need to play with this depending on your input levels.

I made a test for almost 2 hours with my scanner connected and scanning the aircraft bands. I ended up with a 22 minute file. Very nice!! Now I’d say we have a very nice Linux-style “scanner recorder” program, and it’s a hell of a lot slicker than anything you’d find in Windows.

If you are a Debian or Ubuntu user, you will need to compile your own version of SoX if you want to encode to MP3. This bug explains that the version of SoX in the Debian repos was compiled without MP3 support. Anyway, all you need to do is download the latest source, make sure you have all the build deps (apt-get build-dep sox), make sure you have the libmp3lame and libmp3lame-dev packages installed, then just do ./configure, make, make install.

When you do the ./configure you’ll see a list at the end of the output of what capabilities will be compiled into sox, just make sure that it says you will have MP3 support. Your compiled version will go into /usr/local by default, so you don’t need to uninstall the repo version of sox, since that one is in /usr and programs in /usr/local always take precedance. You can verify that by doing “which sox” after installing it and it should show you “/usr/local/bin/sox”.

Posted in Audio | Tagged , , , , , , , , , , | 7 Comments