Radio-4-Matic - part 1 - introduction
posted in Electronics by Cargo Cult on Monday January 7 2013
So, there have been vague hintings at a Raspberry Pi project I've been building. It's been functional for a while in its time-travelling lunacy - but first, what the hell is it?
Something one encounters in these western United States of America is the lack of BBC Radio 4. Or rather, the lack of proper live Radio Four, the excellent iPlayer Radio providing invaluable on-demand capability. "But Adam," I hear you cry, "you can already listen to live BBC radio over the internet! Why can't you use that?"
Timezones. It's live radio, but all the timing is wrong. Namely, the written-in-stone Radio 4 schedule must not, under any circumstances, be allowed to become misaligned from the rising and the setting of the sun. How could anything (or anyone) remotely British even think of operating normally if the Friday evening comedy gets broadcast on Friday morning, or if the Book at Bedtime arrives early in the evening? Or heaven forbid, if Woman's Hour escapes from its usual 10am ghetto?
So, short of removing both the North American continent and the Atlantic Ocean in order to make Seattle a suburb of Plymouth, we're going to have to take the existing internet radio streaming and add a timezone-busting delay. Oh, and then wrap the whole thing in a suitably middle-class casing complete with a Royal warrant of appointment. Luckily, we moved west of the Prime meridian, so we can get away without using actual time travel.
Cue the Radio-4-Matic.
Outwardly, it looks like a typical old British radio, permanently tuned into Radio 4. At 6pm, it provides the Six O'Clock News. Only the 6pm is Seattle-time, not London-time. Waking up can be accompanied by the Today Programme. All very civilised.
Hardware-wise, it's an eBay-acquired 1970s Roberts transistor radio, containing a bog-standard 256MB Raspberry Pi running Raspbian (actually, this exact Pi helped Raspbian get going). The radio has been modified so that the LW, MW and SW buttons provide line-in audio from the Pi's analogue audio-out - VHF still operates as a conventional radio (currently tuned to NPR, no less). Purists may be relieved to hear that hardware modifications to this vintage radio involved snipping one racism-carrying wire from the AM tuner before soldering in two others. Should be completely reversible in about ten minutes, including time waiting for the soldering iron to heat up. I originally intended to replace everything except the speaker, but after discovering how easy it was to pipe in new audio, and how awesome it sounded, I simply didn't have the heart...
Software-wise, it operates a slightly-illicit transatlantic SSH SOCKS tunnel, with the faintly-dodgy get_iplayer and rtmpdump grabbing the radio stream, piping data to ffmpeg for remuxing the AAC-compressed audio from FLV into ADTS. This gets stored on the Pi's SD card as timestamped .aac files, with the basically-ubiquitous mplayer used for playback, started with an appropriate delay - with all of the previous utilities marshalled together with a hideously hacky script written in ... PHP. Stop laughing. Non-blocking file IO and POSIX process management in a command-line program written in PHP? Ohyes! I'm going to rewrite in Python at some vague point in the future. But it's already super-resilient against any particular subsection choking, dying or getting stuck. It'll also probably cope with daylight-savings changes. Probably. It also doesn't record things unnecessarily, such as the World Service overnight.
It's still rather hacked-together (I'm waiting for a USB WiFi dongle to arrive, along with a 12V power supply and a DC-to-DC step-down power supply, to remove all the wires hanging from the back) but it's most definitely functional, and useful. The end result will be a radio and nothing but a radio - except one with this magical eight-hour delay...
I'll be documenting the precise hacks involved, both software and hardware - but for now, it's nice to actually describe this thing!
I'll also eventually get round to fully documenting the Timelapse-o-Tron™ one day, too...
Edit 2013-01-09: Now with part 2, hardware!
Edit 2013-01-11 (just): ... and part 3, software. Phew.
Edit 2013-01-12: ... and a surprise appearance on Radio 4 itself. Eek.
Edit 2013-06-30: ... a somewhat belated upgrade to make the whole thing run on mains electricity. Blinking heck batteries last a long time in 1970s hardware.
Article comments (now closed)
2. ps
Posted by phuzz at 4:48AM, Monday January 7 2013
(ps, Hackaday would probably want to see this http://hackaday.com/)
3. I entirely approve
Posted by parm at 11:56AM, Monday January 7 2013
Although I assume when you say "It also doesn't record things unnecessarily", I assume you include "You and Yours" in that.
4. Vintage
Posted by Cargo Cult at 11:57PM, Tuesday January 8 2013
phuzz: The second article in the series is about to go live - it turned into a bit of a love-letter to old radios, but that was part of the point of this whole project. Please excuse my verbiage! ;-)
I'll throw links at people when the third (software-related) article is up. Friday? Maybe.
parm: I may have to add special programme-guide-parsing code to remove Quote Unquote. *shudder*
5. You might be interested in my github project
Posted by Ben at 3:32AM, Wednesday January 9 2013
https://github.com/benlancaster/BBCRadioProxy
Very crude at the moment, but a simple NodeJS proxy for the playlist files provided by the BBC that makes them compatible with MPD (or whatever else might want to consume BBC streaming radio)
Means you get a decent quality AAC file back too without any transcoding
6. An alternate twist
Posted by Nate at 11:25AM, Wednesday January 9 2013
Would be recording it at the times you usually listen to the radio - e.g. 5am-7am whilst getting ready for work, then 5pm-10pm for afternoon listening... this would reduce the amount of load on the rPi and the amount of potential disk space needed - just overwrite the files with the next recording of that period. Would be good to see the code of how you have done this - I may do it similar and have my rPi hooked up to an FM transmitter...
7. In fact
Posted by Nate at 11:36AM, Wednesday January 9 2013
It's already very simply possible: http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter
8. Faintly dodgy!
Posted by Matt at 6:32PM, Wednesday January 9 2013
Using get_iplayer without a proxy got me banned from all of bbc for just over a month.
9. Publicity zomg
Posted by Cargo Cult at 10:26PM, Wednesday January 9 2013
Ben: Ooh, interesting. I've wondered about adding PVR-like ability for when I've missed something. Easily retrieving specific programmes could be handy. Thanks!
Nate: It's already got time-ranges in there (currently 6am-12noon, 6pm-1am) - when mplayer finishes playing one file, the control script spots that, deletes the file and waits until it's time for the next one to play. Even without that, a full day of 128kbps audio would be a bit over a gigabyte - plenty of space with a 16GB SD card! Processor utilisation is ~15% when both playing and recording simultaneously - most of that audio playback. (Does omxplayer use the GPU to decode AAC? Need to investigate...)
Pi transmitter? I read about that shortly after originally hacking line-in into the radio. Possibly easier, but the FCC might have complained. But I love the idea of broadcasting realigned Radio 4 into a tiny corner of the colonies...
Matt: What did you *do*? Ah, um, a *friend* has been using get_iplayer for years and not had any problems. Fortunately.
Anyway, hello all! I'll try to get the all-important, eye-blistering code posted on Friday...
10. TFTD
Posted by tomh at 1:08AM, Thursday January 10 2013
Lovely project. Any chance you could get it to switch to Radio 3 for five minutes at 7:45ish? :)
11. Wonderful, any chance of adding time advance?
Posted by hoaredge at 3:54AM, Thursday January 10 2013
Fantastic result for those on the east side of the Pacific, and behind GMT. Can a PI manage the magic of time travel, and get Radio 4 to the correct time for those of us in Australia, without listening to yesterday's news????
Try listening to Today at bedtime to get you mixed up. Still, Radio National is a good alternative....
12. 12v
Posted by Sam at 9:21AM, Sunday January 13 2013
Just wondering what you'd need 12v for? The Pi runs on 5v right? What else is there? The Roberts' audio section?
Depending on the current load, might it be better to convert 5v to 12v instead? And have the whole thing powered from either a 5v plug, or the USB plug?
(BTW over here it's the "Greenwich Meridian", not "prime".)
13. Re: 12v
Posted by Cargo Cult at 10:40AM, Sunday January 13 2013
Sam: With DC, it's much easier to go from a higher voltage to a lower one - and since the radio needs 12V at some unspecified (possibly pretty high) current, it seems best to have the 5V Pi and WiFi piggybacked on to that rather than the other way round. Power-wise, if the radio were to peak at, say, 5W when the volume's turned up, that's a whole USB adapter gone there.
The radio's definitely not a shy, retiring little squeaker. Turn the volume up, and my flat fills with rich, chunky sound. This thing's really good for playing music through, too - I got the Airplay hack working on it the other day:
http://jordanburgess.com/post/38986434391/raspberry-pi-airplay
I need to look into having the Radio 4 output mute itself when an Airplay client connects. At a guess, I can probably do it with pulseaudio and the run-commands-on-connect-and-disconnect thingy in shairport, but that's something for the future.
Thanks!
14. Nice!!
Posted by Zdeevo at 4:31PM, Sunday January 13 2013
Awesome project! I've just completed the aux-in mod shown here on exactly the same radio. Sounds so good. I've got a Pi sitting waiting for a home and this old Roberts might be it. Thanks for the pointers and congrats on an excellent mod.
15. gps
Posted by Bas[tiaan] at 11:10PM, Sunday January 13 2013
Hi Adam, what a jolly nice hack this is. Like the php bit tw!
Do you plan on adding gps fpr utter portability across all 'western' timezones?
16. Re: Nice!!, gps
Posted by Cargo Cult at 10:04PM, Monday January 14 2013
Zdeevo: Thanks! I have a feeling prices are rising on eBay for such radios. Please send photos when you're done - I'd love to see other, similarly hacked radios.
Bas[tiaan]: The hack seems so ... *right*. You have to know Radio 4 to really 'get' it, but it seems enough people do...
Regarding the GPS thing - there were some thoughts on just that on the Raspberry Pi forums. Seems that IP-based geolocation would do the trick - maybe depending on an external service, but if you've got an internet connection you might as well use it!
http://www.raspberrypi.org/phpBB3/viewtopic.php?p=255470#p255470
17. How do you get BBC in the USA?
Posted by JohnElectron at 5:36AM, Tuesday January 15 2013
I tried to watch a BBC Gerry Rafferty special here in the USA and the BBC rejected me saying that I could not access the site out of the country. Can someone please tell me how to listen to BBC programming in the USA? I need that step first. Thanks. Wonderful looking Roberts radio - I am jealous of just your original hardware, yet alone the 21st century addition.
First step: how to get access to BBC programmes in the States?
18. Re: How do you get BBC in the USA?
Posted by Cargo Cult at 9:22PM, Tuesday January 15 2013
JohnElectron: The television stuff on iPlayer is all region-locked for licensing and bandwidth reasons. (It's possible to get round the checks, but it's highly dodgy.)
Radio should work everywhere (excluding the occasional sporting thing, again for licensing reasons) - I just checked the following (after a quick search) and it worked fine with my US Comcast IP address:
http://www.bbc.co.uk/iplayer/episode/b01bwbqq/Celtic_Connections_Bring_It_All_Home_Gerry_Rafferty_Remembered/
Give it another go, it might have just been some transient thing!
The Roberts radio - £25 on eBay. Plus about £30 transatlantic postage. (Ouch.) Prices on eBay UK seem all over the place, but I think I got a pretty good deal.
19. Radio 4 timeshift
Posted by gvnmcknz at 2:08PM, Thursday January 17 2013
A man after my own heart!
And considerably more technical expertise to boot!!
Pip pip!
(and a few more Pips for the timesignal!)
21. Does it operate continuously?
Posted by Brian at 6:43AM, Friday February 15 2013
Might be a silly question, but I understand the recording works on a timer, only recording the hours you want - so that means the pi is "on" even when the radio itself is "off" ?
And what about the playback, is there a way to only run mplayer when the radio is on, or is it continuously playing? Or just playing at the times for which it has recorded? Can it play one aac file at the same time that it's streaming and saving another?
PS/ Congrats on this great hack!
22. Re: Does it operate continuously?
Posted by Cargo Cult at 11:45PM, Saturday February 16 2013
(Thanks for the compliments!)
It's always in one of four states - recording, but not playing back; playing back but not recording; simultaneously recording and playing back; or not doing anything except waiting to do something else.
The recording is vaguely independent from the playback - it adds newly recorded sections to a queue, which get played when appropriate. Once a section has been played, the file gets deleted and the entry removed from the queue.
The Pi remains powered up all the time, but its power consumption is pretty negligible. A big, power-hungry device it most definitely isn't!
23. Specification of the adapter.
Posted by 3shoot at 12:48PM, Saturday March 16 2013
Fantastic project. I have just got one with the same model. Luckily It also works for me even it was sold as untested item. I want to find a adapter that fits the radio, could you tell me the specs of yours?
24. Re: Specification of the adapter.
Posted by Cargo Cult at 11:06PM, Saturday March 16 2013
3shoot: nice one! There seems to be quite the squadron of internet-enabled Roberts R707s roaming this planet.
My particular radio has a hole drilled in one of the wooden side-panels, but with a blank plastic stopper instead of a power connector - I won't be much use with connector information there. In another comment, a Campi notes that if you are going to connect it up to a power supply, a linear one might be best:
https://hylobatidae.org/?action=articleinfo&id=53#comment_id_93
(I went and bought what I thought would be a suitable power supply, but it's *switched* - however, the batteries I originally bought for the radio a few months ago are *still going strong*, so I haven't got round to connecting up the power supply yet. I am lazy.)
In another note - the clocks changed in Seattle-land last weekend, but not in the UK - so there's currently a seven hour time difference. My crappy coding worked just fine, adjusting accordingly - now to see if it still works when the clocks eventually change in Britain-land as well...
Article is now closed for commenting.
1. Nice!
Posted by phuzz at 4:46AM, Monday January 7 2013
Nice hack, I'm glad you didn't hurt the radio, we used to have a pretty similar model in our kitchen for years, which became so familiar that seeing a Roberts radio without a drip of paint on the grill looks wrong.
Personally I enjoy the timegap, it feels just fine to hear an aussie accent telling me it's night-time, just around lunch.
(Don't the beeb have plans to effectively sell access to iplayer abroad?)