Audiophile wireless headphones for free

Here’s a neat idea. MPD (Music Player Daemon) has added opus streaming support. Opus allows absolutely excellent quality audio to be compressed down to a stream size that would be considered “low quality” for mp3. BSPlayer for Android has the ability to play opus streams. I compiled and installed the latest version of MPD on my internet facing workstation, disabled remote access to mpd control, and created a http opus stream for output. With a Mpd client on my workstation to control the music playing, and BSPlayer connected to the http stream, I have nearly CD quality audio on my wired headphones (connected to my Android phone), playing music from (and controlled by) my desktop. Yeah, it’s not really wireless, but it’s a lot easier to slip a phone into my pocket and walk away than it is to do that with my desktop computer. The neat thing, is, the “range” of my “wireless headphones” is basically infinite as it goes over the internet.

Configuration notes:

  • Opus-tools and opus-tools-dev are installed so that mpd is compiled with opus streaming support.
  • libsamplerate dev package needs to be installed so it can be used for sample converting between 44.1 (CD audio) and 48Khz (soundcard audio). Without it, sound quality was terrible, with aliasing and artifacts.
  • be sure to check the output when running ./configure. Things with a “-” sign rather than a “+” sign are not being compiled in due to lack of dev packages.
  • Point BSPlayer to http://machine_address:8000 and ensure that the network buffer (in settings) is on high.

Here are the necessary config lines from mpd.conf:

# Only allow mpd control connections on local machine (or SSH tunnel)
bind_to_address "localhost"

# Opus http output (In my own testing, I cannot tell 128kb opus from CD audio, on 96kb,
#                 I could hear slight distortion on complex music (orchestral strings especially)
audio_output {
        type            "httpd"
        name            "Opus shout stream"
        encoder        "opus" 
        port        "8000"
#       bind_to_address    "0.0.0.0"        # optional, IPv4 or IPv6
#       quality        "5.0"            # do not define if bitrate is defined
        bitrate        "128000"            # do not define if quality is defined
#       format   "48000:16:2" #Disable to use input file format
        max_clients    "2"            # optional 0=no limit
}

# Use a very good algorithm to convert CD audio to Soundcard audio sample rates. 
# See mpd.conf man page
samplerate_converter        "0" # MPD's best, most CPU intensive algorithm.

Leave a comment

Filed under Science and Skepticism

Opus Audio Codec

Opus is a relatively new audio codec (like Mp3). It’s Free, open source, part of future web standards, and is astoundingly good at compressing audio down into small file sizes while maintaining good sound quality. Lots of software plays it (Firefox, Chrome, any audio player on Linux that uses Gstreamer, etc). Unfortunately, most of the CD ripping and audio converting programs don’t yet do so. Also, on Android, as far as I know, only Bsplayer will play it so far (though cSipSimple can use it as a VOIP codec!).

Anyway, here is a  script I wrote that simplifies using ffmpeg’s ‘avconv’ and the opus-tools package to convert virtually any file to opus. I have used this for converting long lecture recordings down to a small filesize and cramming more music on my limited phone space:

https://github.com/JasonLocklin/bin/blob/master/opusconv

Leave a comment

Filed under Science and Skepticism

Digital TV antenna in Kitchener-Waterloo

It’s been a little over a year since Canadian broadcasters switched from the blurry, static fil220px-Family_watching_television_1958led old analogue TV system to the modern, digital broadcast standard known as ATSC. Public “information” advertisements have convinced many people that the days of putting up an antenna and getting free TV are over, or somehow illegal. This couldn’t be further from the truth! The new digital TV (DTV) standard means high quality, high definition TV without static or blurriness. That is, if you can get it. Some places, like Toronto or Hamilton, have dozens of strong signals. That means people in those areas can use cheap antennas to pick up every Canadian and American channel for free. Here in Kitchener-Waterloo, however, bringing in more than a few channels requires some work.

Myths about Digital “Over The Air” TV

  1. “OTA doesn’t exist anymore”
    Most broadcasters in Canada are owned by cable/satellite companies, so they don’t explicitly advertise that their channels are available for free over the air, but they do broadcast all the primary networks in Canada entirely for residential reception -and they collect advertising dollars to pay for it.
  2. “OTA TV is illegal”
    This seems to come from confusion with the grey market satellite that used to be common in Canada. Basically, people purchased Free to Air (FTA) satellite equipment designed for the *Legal* use of  watching  the FTA channels available on various satellites (Mostly international and religious channels). They would then *illegally* use that equipment to decode encrypted channels intended for pay services only. This is entirely unrelated to over the air TV (broadcast from large towers near cities), which has always been free and legal in Canada.
  3. “You need a digital antenna”
    Antennas are designed for frequencies, not what is carried on that frequency. As always in Canada, over the air TV is broadcast on VHF and UHF channels.   1-13 are VHF and the rest are UHF. Many areas do not have VHF channels, so you may only need a UHF only antenna. The classic indoor “rabbit ear” works for VHF and the “loop” type wire antennas work for UHF. Outdoor antennas should also be selected based on whether you need UHF, VHF, or Both. Most of those plastic covered “digital” antennas are garbage. If the antenna claims more than about 15db of gain, they are using a built-in preamp and are using that to “fudge” the numbers. If they do this I can guarantee the antenna is not worth your money. You can consult this forum for a list of the best antennas available.
  4. “You need a digital converter box”
    Only to use an old TV. Most new TVs have digital tuners. If your remote control has a decimal button (i.e., for entering channel 13.1), then it has a digital tuner.  You can also use a tuner card in a computer rather than a converter box.
  5. “You need 100+ channels to make TV watchable, OTA only gives a handful”
    Half true. OTA will give you at most a few dozen channels. In KW, I “only” get 11-12. However, on cable, many of the channels just duplicate content or show it at different times. Take the money you save on a subscription cost and buy or build a digital PVR/DVR. A PVR makes each channel 24 times more useful :-).

First, check the predicted signal strengths from TVfool using my coordinates here. You can use Google maps to find your coordinates. Locate your house, right click on the location of your house and select “What’s here?” The new search term becomes the coordinates. The output is kind of technical, but basically channels in green can be received with something indoor, yellow and red channels require an outdoor antenna and the rest are just there to tease you. Googling the callsign can give you more info about which channel is actually which. Note the “Real” channel tells you whether you need a UHF or VHF antenna to receive a particular channel (<14 is VHF).

I learned most of what I know about OTA on the Digital Home Forum.

My Setup in Kitchener-Waterlo

In KW, TVO, Global, and CTV are local and can be picked up by any old piece of wire. The local VHF channels (Global and CTV) are so strong it doesn’t really matter whats used. Stations from Toronto (CBC, french CBC, CityTV, Omni 1 and 2) are UHF, so in KW, you can get most of the channels via a UHF only antenna pointed at Toronto. Depending on how high your house is, you may be able to get away with a small antenna on a wall. I’m low, so I have a big UHF beam antenna on the roof. For some lucky locations in KW, such as those at higher elevation with SSW view, Buffalo stations are receivable with a rooftop antenna. I have no chance at many of these American networks, but occasionally can catch a glimpse of PBS.

My antenna is an Antenna’s Direct 91XG mounted on a 5 foot tripod on my roof. This is basically the highest gain (i.e., strongest, most directional) UHF antenna available. It’s on a rotor so that I can swing it over to point to Buffalo, or Hamilton -though I have found that I don’t use it enough to need it. I have a CM7777 preamp up there. The preamp basically amplifies the signal (and the noise) so that the signal loss along the long coax down to the basement is negligible. Preamps are only useful when you have a long cable like I do. The coax is connected to a grounding block before entering the basement. It is connected to the house ground outside to avoid static or minor surges from coming into the house and affecting my equipment. I have an HDhomerun tuner connected. This provides two digital tuners on my home Ethernet for my networked PVR to record from.

Reliable Channels:

  • CTV Baden
  • TVO Kitchener (also TVO Toronto, but it’s the same as Kitchener)
  • CBC Toronto
  • CityTV Toronto
  • Omni 1 Toronto
  • Omni 2 Toronto
  • CBC (French) Toronto
  • Global Toronto
  • CTS Hamilton

Unreliable Channels:

  • Global Toronto (Ch 6 repeater in Kitchener)
  • CW Buffalo
  • CHCH Hamilton

Todo:

So far, I am not entirely happy with the setup. The VHF channels sometimes break up severely and I think it has something to do with the very strong signal overloading the preamp. The Toronto UHF signals occasionally also break up somewhat. I would also like to pick up CTV2 from London. It would also be nice if CHCH London was more reliable -it has a strong signal, but my UHF antenna kills it most of the time.

I have purchased a UHF/VHF duplexor, so I can connect a separate VHF antenna *after* the preamp (critically, the duplexor passes power for the preamp to the UHF side). This way only the weak UHF signals will be amplified. The CM7777 also has a built in duplexor, so I can use that to totally disable all VHF input to the preamp and devote all of it’s power to UHF (perhaps making them more reliable as well). By permanently mounting the VHF antenna pointing toward London, CTV, Global, CHCH Hamilton and CTV2 London should be always strong and clear, regardless of where the UHF antenna is pointing. This is the main benefit to having a separate antennas in KW -a single VHF/UHF antenna would not be able to pick up Toronto and Hamilton/London at the same time. Unfortunately, CHCH is supposed to switch to UHF at some point in the future, at that point I might have to swing the UHF around to receive it depending on it’s strength.

CTV2 London is receivable with a simple dipole (rabbit ears) at my antenna height according to tvfool, however, without a preamp, I need several db of gain to overcome the line loss getting to my tuner. Furthermore, I don’t want to build something and find out it is too knife-edge to work perfectly all the time. So I’m building a Yagi antenna specifically for CH10. Yagi’s are basic antennas that are relatively easy to build, small-ish, very effective, but really only good for one channel. Fortunately, all the other channels, including CHCH london, are quite strong so any VHF Yagi will pick them up just fine regardless of it’s design frequency.

Homebrew VHF antenna

I have settled on building one based on VK5DJ’s Yagi calculator with 2 directors and 1 reflector. That gives me an antenna approximately  2.5 feet long and about that wide, with 6.5db of gain over a dipole. Calculating all of the losses amongst the coax and various connections, I should have at least 4db of surplus signal (i.e, more than double the signal strength needed at the tuner). Of course this also gives a little bit of wiggle room if my antenna is not perfect. Hopefully this will be enough to have 100% reliable signal from London, and avoid all the current problems with the strong VHF channels. Fortunately we have a Metal Supermarkets here in Kitchener, so I have some very nice pieces of aluminium for the boom, reflector and directors, and a nice heavy piece of copper ribbon for the driven element. I will make further posts here when I build it, including pictures.

Also, I would also like to make a single point ground on the inside like this.

25 Comments

Filed under Fun Projects

Asterisk home PBX

Current setup:

Old Acer Aspire One with cracked screen running PBX in a flash.
The kids pulled the netbook off a shelf and cracked the screen, so I though rather than spending the time and money to try to repair the screen, I would just use it as a PBX server. PBX in a flash installs everything required from a USB stick along with a suite of web interfaces for managing the system, the PBX utilities, and even phone calls, voice-mail and phone book.

I use Acanac as the primary trunk for our home phone number and outbound calls. The system has several other trunks for more “fun” purposes including a special-purpose google-talk account so that we can call home from Gmail, a free voip account with Callcentric  for voip calls (Acanac does not allow actual VOIP-to-Voip calls via SIP URI), enum-lookup, and sipbroker connections.

As extensions, I have a SPA-2102 connected to a DECT-6.0 cordless phone with 3 headsets, and a Gigaset S675IP cordless VOIP phone effectively providing two separate “lines” in the house. My Android phone has cSipSimple installed so it can seamlessly switch back and forth between being and extension on the home PBX via WiFi and cell service. Though Android phones do SIP VOIP natively, cSipSimple adds some more features. I use the “Traveling man” feature of PBX in a flash so that my phone can automatically connect to the PBX from any WiFi access point and act as a “remote” extension. The PBX also rings both my wife’s cellphone (Blackberries don’t do VOIP), and my android phone via cell when wifi is not available. The call-hunt features make this all work great when someone calls our home number.

Todo: currently there is a burst of static on the remote end when the S675 makes a call. I would like to somehow get my Google contacts migrated into the Asterisk phonebook and S675 to improve calling and caller ID readout.

I plan on using the other port on the SPA, or another old ATA that I have, to add “fun” phones to the kid’s rooms. I will use a “digital receptionist” set up so the kids can listen to pre-recorded stories/music, call each other or other extensions in the house, or perhaps family members (time-of-day restricted). I have to find some cheap fun-looking kids phones for this purpose.

Leave a comment

Filed under Fun Projects

Autogenerated CV and academic webpage

So, I had this crusty old academic web page and CV that were perpetually out of date and a pain to change. I thought they still looked okay stylistically (though the html still uses tables..), but that got me thinking about ways to have the info in nice, neat text files, and have the CV and website rebuild it’s self whenever that info is changed. The added benefit is that keeping all this information in neat lists in plain text files makes it not only very easy to update, but easy to use for scholarship and other types of applications. Well, here’s the dirt…

The first thing I did was create a git repository out of all the files. This allows me to have a copy of all the website files on any computer, and keep them in sync, while maintaining a history in case I mess something up and want to check an old version. I have been using git for everything I do recently and don’t know how I lived without it. I even added the repo to my public account at github, so anyone can see the source files.

The next step was to copy all sections from my CV and website to various markdown files. Markdown is basically a way of marking up plain text files that looks like how someone would structure an email -but is standardized so that a computer can interpret it. Here is a sample:

## Education

[University of Waterloo](http://www.uwaterloo.ca/): 

* [**Ph.D., Cognitive Neuroscience**](http://psychology.uwaterloo.ca), (Expected completion December 2013)
    + Thesis Topic: Perception and Action Biases under Saccadic and Prism Adaptation.
    + Adviser: [Professor James Danckert](http://psychology.uwaterloo.ca/people/faculty/jdancker/index.html)
    + Area of Study: The neuroanatomy and psychophysics of human action and perception.

Excuse the longlines (I use a soft-word-wrap on my text editor for markdown).

I then stripped my website and CV files (html and LaTeX files) of their content -leaving only the formatting and header/contact information. Where the content was, I simply included a line with the tag $body$ -thus creating a template.

To create the html and LaTeX files each time I want to update the content, I used Pandoc. Pandoc is a program that can convert markdown (and various other formats) in to a range of other formats. In one command, it can take, for example, all my markdown files, convert the markup to LaTeX, and splice them into my template file replacing the $body$ tag mentioned earlier and output an up to date CV in LaTeX. The same is done to create the HTML web page. I opted to use sed to tweak the markup Pandoc exported (I used custom list environments in my LaTeX template to adjust spacing, etc). Of course I don’t mess around with all these commands when I want to update things, they are all placed inside a makefile. You can view it here.

In practice, now that this is set up, I have a copy of my website/cv files on all my computers. Whenever I want to update the info, I open this directory on whichever computer I’m on, and run “git pull” to make sure these files are up to date. Then I open one of the markdown files and update the simple text list -adding a new line for a new publication, or TA, etc. I save the file and run “make”. Git will ask me for a comment (these make it easier later on to go back and find old versions), and then everything is rebuilt and updated both at Github and on my academic website.

If you are interested in seeing the final product, here is the compiled CV and Website.

 

Leave a comment

Filed under Free Software

RStudio is officially awesome

Ok, Rstudio is officially awesome. I had tried it back when it was fresh and buggy and saw that it had promise, but re-trying it today has just left me floored. It is fully set up to work with Sweave documents -providing the necessary LaTeX and R syntax highlighting at the same time, as well as handling a single root document (if you’re analysis files are split up) and includes one click run/compile to PDF.  It also integrates nicely with GIT so I can easily version my source files right in Rstudio. It’s also fast -every operation is snappy and the interface just looks beautiful.  While it lacks the “wizards” many other R Gui’s have for common operations (like statistical tests, or data imports from other programs), it has plenty of convenience functions for working with graphics, package and workspace management,  running, folding, commenting, etc. chunks of code. The only minor gripe I have is the inability to change the layout of the panes -on my widescreen monitor I would prefer to have three columns and use the full height of the screen as that works best for the console and script editor (I stay <80 characters wide).

Leave a comment

Filed under Behavioral Neuroscience and Psychophysics Research, Free Software