Saturday, March 17, 2012

change the gnome screen dim timeout...

A quick and dirty script to change the timeout of gnome3's overactive screen dimming when on battery...

#!/bin/sh
echo "Usage: setscreendimtimeout [seconds]"
gsettings set org.gnome.settings-daemon.plugins.power idle-dim-time $1
As you can see I've named it setscreendimtimeout and put it in my ~/bin dir (and of course made it executable with chmod +x).

Test it out with setscreendimtimeout 2 and see if your system is even more annoying - then set something reasonable for your use...

Monday, October 17, 2011

Amazon Video

If you're a linux user and a Netflix user frustrated by Netflix refusal to release a player compatible w/ linux, look into Amazon's offering - so far the unlimited watch (with a prime account) show selection is somewhat limited when compared to netflix's catalog, but what is available works perfectly... Much better than Netflix running in a windows virtualbox in my experience...

Tuesday, October 11, 2011

Stream Audio to Airport Express from Ubuntu...


Some time ago I posted here about how to stream sound from a Mac to an Airport Express router, but lately I've moved to working in Ubuntu Linux, so I needed to tweak my procedure...

At some point this whole mess will be obsolete, because there already exists a PulseAudio module implementing the RAOP as a sound device, so you can direct sound from your system as a whole or an application out to your airport express... however, so far, on my installation (Ubuntu 11.04 and lately 11.10 beta) it's buggy and doesn't work well at all for me.  I experimented with playing music from iTunes in a virtualbox installation of Win7, but, while it worked alright, the music would pause every minute or so - irritating... The setup I'm describing here works quite well for me...

I decided to try to set this up using much the same structure as I used for the mac hack, so I'm grabbing the sound feed from the machine and piping it into JustePort (running in mono since it's a .NET executable) which handles sending it to the airport express router.  This turned out to be pretty simple once I figured out what device to grab the sound from and how to spew it down the pipe (since Ubuntu isn't using ESD)...

What you need to do is grab the output channel monitor which you should be able to determine by looking at the results from:
pactl list | grep monitor
which will return some results which look something like:
Monitor Source: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
Name: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor 
            device.class = "monitor"

Now, using parec, on the monitor device we just determined, we can send raw sound data wherever we need it like this...
parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
which we can then pipe through JustePort.exe to the airport express. Like so:

parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | mono ~/bin/JustePort.exe - 192.168.1.100 -0
  To break that down a bit...
parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | mono path/to/JustePort.exe - 192.168.1.100 -0
reads the sound data from the monitor
pipe to send it to JustePort
runs JustPort using mono
input to JustePort is stdin (from the pipe)
IP of the airport express router
Volume in -dB - (I find this connection is quieter than the dvd player attached directly to the stereo, so I crank this all the way to 0 rather than allowing it to stay at the default of -30)

There are a couple of downsides to this technique...
  • there is a lot of latency (a couple of seconds at first, but it seems to grow over time, like the buffer is filled faster than it empties).
  • all sounds from the computer will be sent, not just your music - I'm sure this would be fixable by some more advanced work (I'd love to create a virtual device just for this purpose)
You'll gain some insight and on-board volume control through the use of  pavucontrol...

Thursday, September 15, 2011

Netflix freezing on Virtualbox? Try different DNS settings...

Looking for a way to run "Watch Instantly" on my linux box (since I hated having to reboot into Windows just to watch a show, I virtualized my Win 7 installation using vmware's standalone converter.  I was never able to try running this virtualized windows on vmware server, due I think to issues with 64 bit firefox not being able to install vmware's plugin - no worries, I created a virtualbox VM booting off of the converted virtual drive, et viola - I could watch Netflix... kinda.


Problem was, that Netflix would lock up within seconds or minutes, halting all playback.  Reloading the page would start the video again (not exactly where I left off - usually back a bit) but it basically rendered netflix unusable... not cool. I tried reinstalling Silverlight, and a few tweaks to the VM configuration, but to no avail... further googling indicated that perhaps DNS settings could lead to lock ups like I was seeing (though that makes no sense to me).  I set Ubuntu to use Google's dns servers (8.8.8.8, 8.8.4.4) and amazingly, this seems to have fixed my problems - at least for today.  I'll update here if this setup starts to fail...

Tuesday, July 12, 2011

Kupfer Focus Fix...

So, this blog has been semi-abandoned for a long time, but since it's my de-facto tech blog, and I found a novel fix to something, I figured I'd post up...

So I'm no longer running OS X, (as I'm sure you gathered since you got to this post by searching for kupfer focus),  and am loving the Natty Narwhal (Ubuntu GNU/linux 11.04). Found a great app called Kupfer which duplicates Quicksilver's functionality... very handy - invoke the app with a hot key and quickly launch an app/document/song/etc. with a few quick keystrokes.

Super cool but I found that on any later presses of my hotkey combo, kupfer would indeed launch, but focus would not shift to it's window, so keystrokes would still go to the last focused app (pretty much eliminating the advantage of kupfer since I'd have to use the mouse to focus the window and at that point I could probably just have launched the app or document the traditional GUI manner). After trying to focus the kupfer window with  xwit and wmctrl (failures for me, though someone who knows what they're doing would possibly have more luck) I thought why not just launch a new instance of Kupfer every time I want to use it... simple, just made a shell script which kills any current instance of Kupfer, and then launches it anew, allowing it to live for 45 seconds before killing it for good and exiting:
#!/bin/sh
killall kupfer
kupfer &
sleep 45
killall kupfer
Made that script executable and call that with the hot key combo - works every time...


 Update: Heh - a couple of days later, I found Gnome Do... Focus works properly.

Wednesday, January 2, 2008

Send Equalized Sound to Airport speakers on the cheap

Ok, here’s how I’ve setup my MacBook to stream audio through AU Lab for processing (EQ) and then out to my Airport Express –like airtunes, but for all sound, not just iTunes content (Airfoil works better for this, but It’s not as much fun, and it costs money)

BTW aside from the AU Lab EQ, I found all of this how-to info using Google. It seemed that most people describing this were in the Bearded Unix Guru catagory and kept describing it as "easy" whereas I was finding it "$%@# confusing" so once I figured out a system for doing what I wanted I thought I'd try to spell it out for other muddlers like myself. If my descriptions seem too long winded, I'm not writing that part for you, I'm writing it for your mother. If my *nix skills seem weak...that's 'cause I'm no good at unix... etc. etc. If you find/know of a better way, please let me know. Pieces of my email address are found at the bottom of the post.

Ok, let's get started...

First of all you’ll need these programs:
  • Soundflower - http://www.cycling74.com/products/soundflower
  • AU Lab – found at /Developer/Applications/Audio/ after you’ve installed "Developer Tools" from your Mac OS X Install disc
  • Enlightened Sound Daemon - http://www.tux.org/~ricdude/overview.html
  • JustePort - http://nanocr.eu/software/justeport/
  • Mono - http://www.mono-project.com/Downloads - used to run JustPort on your mac
A bit about structure… the idea here is to pipe sound from any program (probably not iTunes as it can do this natively) to AU Lab, run it through whatever filters in AU Lab (a graphic EQ for me) and then pipe it from there out to an airport express connected to external speakers of some kind. The sound will follow this path:
OUTPUT -> Soundflower 16ch -> AU Lab -> soundflower 2ch -> esdrec -> JustePort -> Airport Express
Note: Soundflower 2ch and 16ch will be bundled into one Aggregate Device

To start, install all those programs listed previously. Install Mono before trying to compile JustePort ‘cause it’s a C# program being compiled and later run by Mono (I think there may be a way to compile JustePort so that it runs natively on mac os, but I couldn’t figure it out so in my example we’ll be running JustePort like this:
> mono /path/to/JustePort.exe
Much of what the kind of stuff we’re going to do with soundflower and Audio MIDI Setup is explained in more detail in the previous post here so read through that for a more detailed explanation. I’m going to go a little fast with that stuff…

Blatant plagiarism of my last post:
We’re going to need an input of sound into AU Lab and an output for our modified sound (after the equalizer). Strangely, as far as I can tell, AU Lab can only work with what it sees as one device at a time, luckily Audio MIDI Setup has a method of bundling devices together to create “Aggregate Devices”. This is the only step for which you need to be Admin, so for this step, change to your Admin account and open “Audio MIDI Setup”. Now Choose “Open Aggregate Device Editor” from the “Audio menu.

We need to provide a pipe into AU Lab and a pipe from there to esdrec so we’ll check “use” for “Soundflower (2ch)” and “Soundflower (16ch)”, name this device anything you like (or leave it as the default “Aggregate Device” – this is what I’ll call it for the rest of this post). When you’ve done this, click done, and make sure your “Aggregate Device” now appears in the dropdowns Audio MIDI Setup – don’t select it now, just make sure it appears (if you select it and forget you’ll wonder why your sound is broke in your admin account). If your new Agg. Device exists and your Outputs are set to Built-in, it’s time to exit this program, log out Admin and return to your normal account.

You now have all the pieces needed to implement this system. Now let’s do it. Eventually we’ll discuss using an applescript to automate the steps. For instance, I can run an applescript and all my sound will be routed to my stereo, and run a different one, and all sound will be returned to my built-in speakers. But first we’ll do the steps manually in order to understand them better.

Start some music playing at a moderate volume and leave that running in the background.

In Audio MIDI Setup select Soundflower (2ch) as the default input and the default output. Your music will now go quiet although the program is still running, any normal sound played by any program on your mac is going into Soundflower (2ch) and any program which can take in sound (to record it for instance) will get that same sound piped right in. Now open a terminal window and type
/path/to/esdrec | path/to/mono /path/to/JustePort.exe - 10.0.1.1 -30

(i.e. /usr/local/bin/esdrec | /usr/bin/mono /usr/local/bin/JustePort.exe - 10.0.1.1 -30)

you should get output like this:

opening socket, format = 0x00002021 at 44100 Hz
using device Soundflower (2ch) for output:
with sample rate 44100.000000, 2 channels and 32-bit sample
using device Soundflower (2ch) for input:
with sample rate 44100.000000, 2 channels and 32-bit sample
JackStatus: connected
JackType: analog

And your computers sound should now be coming out of your speakers attached to your Airport Express.

To understand the above command, let’s look at the parts:
  • esdrec – outputs from the sound device's current input.
  • “ | “ – a pipe sending the output from esdrec to JustePort
  • mono – allows us to run the C# windows executable JustePort
  • JustePort – The program sending the data over the wifi to your airport
  • - 10.0.1.1 – an argument to JustePort – this is hopefully the ip of your airport (it tells JustePort where to stream your sound)
  • - 30 – this is the optional volume setting for JustePort which is unnecessary as -30 db is the default volume, but you can change the sent volume by changing this: -0 is loudest -144 is the quietest

ok…done deal, unless you want to control the volume and add a graphic EQ in which case we’ll use AU Lab similarly to the EQ instructions in the last post.

Now, with your system still how we left it (sending sound to your airport) go into Audio MIDI Setup, and change the default output to Soundflower (16ch). Your sound should go quiet because so far nothing is using sound from SF(16ch).

more self plagiarism follows…

Open AU Lab – at the create new document dialog:
choose “Aggregate Device” from the Audio Device dropdown menu. Under the output tab grab the red box and make sure it’s on the channels 1&2 (which shoud be the group of 2 channels -- you should also see an adjacent group of 16 channels) now click the “Inputs” tab, and then click Add Input – a red box should appear – drag this red box until it’s on channels 3&4 which are the first 2 channels of the 16 channel portion, now you can click OK to create the document

At this point you should have an Untitled window with some controls and your music and sound should come back on (as long as you left it playing and left JustePort running in your terminal. At this point save the current document so you don’t have to configure it again (it will be saved with the extension ".trak" and doubleclicking this file in the future will open it in AU Lab - very handy). In the left column you’ll see the heading “Effects” and three dropdown menus – These can be used to apply all sorts of effects, but the basic need is an equalizer, so choose AUGraphicEQ and play around. I recommend opening up the iTunes equalizer and copying presets from there onto the 10-band EQ - be sure to save any EQ settings you like.

Alright. Hopefully this works for you so far. To quit sending sound to the Airport and return it to your machine:
  • in Audio MIDI Setup set Default Output and Input menus to "Built-in"
  • in the Terminal window which is still piping esdrec into JustePort type ctrl-c to halt this process. Alternatively you can just close the terminal window or quit terminal
that's it.

Now that the system's been setup, the steps to send sound back to your airport are
  • in Audio MIDI Setup set Default Output to "Soundflower (2ch)" and Default Input to "Aggregate Device"
  • in Terminal enter
    /path/to/esdrec | path/to/mono /path/to/JustePort.exe - 10.0.1.1 -30
  • open your saved AU Lab file ( mySavedFile.trak or whatever you named it) - this will launch AU Lab
  • in Audio MIDI Setup set Default Output to Soundflower (16ch)
Note: The in Audio MIDI Setup, Default Input must be set to "Aggregate Device" and Default Output must be set to "Soundflower (2ch) at the time that esdrec is called -- otherwise, esdrec will choose the wrong input and your sound will never get to JustePort. After this has been set and the esdrec | mono... call has been made then you can change the default output to Soundflower (16ch) and open your saved AU Lab configuration.

Not too bad to save $25 (remember airfoil) but it's even easier if you automate it with an AppleScript.

For this applescript to work you'll need to go to System Preferences -> Universal Access and check "Enable access for assistive devices" which allows applescript to do "GUI scripting"

Open the AppleScript editor and paste the following into it. Next, modify any file paths needed to conform to your machine (i.e. esd may be found at /usr/bin/esd or /usr/local/bin/esd or wherever you put it when you compiled it. Likewise for esdrec, yourFile.trak, mono, and JustePort.) Then save the applescript with whatever name you'd like (I named mine sound2Airport and sound2Normal)-- In the applescript save dialog choose "Application" from the File Format dropdown so that you can just double click on the applescript to run it.
--------begin applescript

-- Note: on MIDI setup page "Properties For" must be left set to "Built-in Output" or
-- "Soundflower (2ch)" for script to execute properly

-- we use this function to set the popup wndows
-- I don't remember who I plagiarized this function from
-- but credit goes to them...

on setPopUp(x, y)
tell application "System Events"
tell process "Audio MIDI Setup"
tell window "Audio MIDI Setup"
tell tab group 1
tell pop up button x
click
tell menu item y of menu 1 to click
end tell
end tell
end tell
end tell
end tell
end setPopUp

--first we tell AMS to set necessary output and input
tell application "Audio MIDI Setup" to activate
setPopUp(6, "Soundflower (2ch)") -- Default Output to start esd
delay 0.3
setPopUp(7, "Aggregate Device
") -- Default Input
delay 0.3

-- now we start the Enlightened Sound Daemon while the Input and Output are set correct
--this way esdrec will use the correct channels later
do shell script "/usr/bin/esd &> /dev/null & " --esd must be started with SF_2ch selected and

-- now we set Output to SF16
tell application "Audio MIDI Setup" to activate
setPopUp(6, "Soundflower (16ch)") -- Default Output for Playing through AU Lab
tell application "Audio MIDI Setup" to quit

-- now we open our saved AU Lab track and then pipe the sound out through JustePort
do shell script "open Users/josh/Scripting/Sound/sound2Airport/ControlSound2Airport.trak" -- AU Lab for EQ and volume
do shell script "/usr/bin/esdrec | mono /usr/bin/JustePort.exe - 10.0.1.1 -20 &" -- pipe the sound to airport

---------------end applescript

the AppleScript to return settings to normal is much more simple... save this one as an application also...

------------- begin applescript
-- Note: on MIDI setup page "Properties For" must be set to "Built-in Output" or
-- "Soundflower (2ch)" for script to execute properly - dunno why
on setPopUp(x, y)
tell application "System Events"
tell process "Audio MIDI Setup"
tell window "Audio MIDI Setup"
tell tab group 1
tell pop up button x
click
tell menu item y of menu 1 to click
end tell
end tell
end tell
end tell
end tell
end setPopUp



tell application "Audio MIDI Setup" to activate
delay 0.3
setPopUp(6, "Built-in Output")
delay 0.3
setPopUp(5, "Built-in Output")
delay 0.3
setPopUp(7, "Built-in Input")
delay 0.1
tell application "Audio MIDI Setup"
quit
end tell



do shell script "killall mono"
do shell script "killall esd"


tell application "AU Lab" to quit

-------------- end applescript


A Note on these applescripts: I'm no bloody good at writing applescripts so if YOU are good at writing the them and you see a better way to do something please let me know so I can modify the posted code. Actually that goes for pretty much all of the above... I don't really know what I'm doing so y'all let me know if you know a better way.

I can be reached at
jp.
random
@GOOGLESEMAILSERVICE.com <- hopefully the spambots can't figure it out...and you can.

Monday, December 31, 2007

A free graphic equalizer for all mac sound

Problem – you’re streaming music from some web site (i.e. Pandora) and it could use a little EQ tweaking but your browser doesn’t have an EQ and OS X lacks a system EQ…

I found a (somewhat kludgy) way to use AU Lab to create a graphic EQ or do other filtering on any sound playing on your mac. Here's it...

What you need:
so…
  • Install soundflower – restart required
  • Install Developer Tools from your os x install disk (if you haven't already done so)
A little about soundflower:
This program creates virtual sound input and output devices that are available to any program that can choose which sound device to use. SF provides two pipes for our use, one with two channels (think stereo), and one with 16 channels and audio programs simply see these as audio devices they can play to or get input from. Essentially SF allows us to pipe sound between programs (as long as those programs can look for audio devices).

Unfortunately most software doesn’t allow us to select which sound device to output to, so in order to steal the sound output of our browser, we need to redirect the sound output of our whole computer. Luckily, using “Audio MIDI Setup” (found in /Applications/Utilities) this isn’t that hard…

Open /Application/Utilities/Audio MIDI Setup. Under the “Audio Devices” tab you’ll see various dropdown menus. These are fairly self-explanatory. Whichever device is selected under each menu is where the system will send to or receive from. You’ll notice that each menu is probably set to Built-in.

As an experiment, start some music playing from any program you’d like and leave it playing in the background… now in Audio MIDI Setup select “Soundflower (2ch)” from the Default Output menu… Your music should become silent now, but if you check, it’s still playing. The silence is because instead of being routed to your speakers, the sound is routed into the two channel pipe of Soundflower.

We’re going to need an input of sound into AU Lab and an output for our modified sound (after the equalizer) to our ordinary speakers. Strangely, as far as I can tell, AU Lab can only work with what it sees as one device at a time, luckily Audio MIDI Setup has a method of bundling devices together to create “Aggregate Devices”. This is the only step for which you need to be Admin, so for this step, switch to your Admin account (you can leave you normal account logged in, we'll be right back) and open “Audio MIDI Setup” (from the Utilities Folder). Now chose “Open Aggregate Device Editor” from the “Audio" menu.


click for larger image

We need to provide a pipe into AU Lab and a pipe from there to our speakers so we’ll check “use” for “Soundflower (2ch)” and “Built-in Output”, name this device anything you like (or leave it as the default “Aggregate Device” – this is what I’ll call it for the rest of this post). When you’ve done this, click Done, and make sure your “Aggregate Device” now appears in the dropdowns Audio MIDI Setup – don’t select it now, just make sure it appears (if you select it and forget, you might later wonder why your sound is broke in your admin account). If your new Aggregate Device exists and your Outputs are set to Built-in, it’s time to exit this program, log out of your Admin account and return to your normal user (you do have one don’t you?)

Now in your regular account with your music playing, in Audio MIDI Setup select Soundflower 2ch as your default output.
Open AU Lab – at the create new document dialog:



  • Choose “Aggregate Device” from the Audio Device dropdown menu
  • Under the output tab grab the red box (it drags back and forth) and make sure it’s on the which ever stream is not the “Soundflower…stream” probably “Stream 2” (maybe "Stream 1")
  • Click the “Inputs” tab, and then click Add Input – a red box should appear labeled “Soundflower Input Stream 1”
  • Click OK to create the document

At this point you should have an Untitled window with some controls and your music and sound should come back on. If that's the case, save the current document so you don’t have to configure it again. In the left column you’ll see the heading “Effects” and three dropdown menus – These can be used to apply all sorts of effects, but you came here for an equalizer, so choose AUGraphicEQ and play around. I recommend opening up the iTunes equalizer and copying presets from there onto the 10-band EQ - be sure to save any EQ settings you like.

Your system volume keys (F3, F4, and F5) won’t work and your volume should be the same as it was when you switched the default output in Audio MIDI Setup so you can control volume from within whatever program is making the sound and/or from the volume sliders within AU Lab. I’m no audio expert, but generally you don’t want to boost a weak signal too much so if you need louder sound I’d recommend first turning up the sound output from the program and after that you can increase your system volume by opening Audio MIDI Setup, setting the default output to “default output”, changing your system volume, and then changing the dropdown back to Soundflower 2ch and your sound will be routed back to AU Lab and it’s EQ.



Disclaimer - This works on my MacBook Core 2 Duo running 10.4.11 and I've no idea what systems it won't work on. Also be advised that if you "do it wrong" and create a feedback loop in AU Lab you can create some nasty feedback, which so far hasn't damaged my speakers, but it gets pretty loud so be careful.

p.s. I've also used this plus more to push sound out to my Airport Express speakers with great results and I'll post on that sometime when it's not 3:08 a.m. (well it might be but it wont be this 3:08)