Wednesday, December 19, 2012

Codec2 and modem on a raspberry pi?

Encouraged by early success with FreeDV digital voice with codec2 it occurs to me that a great project would be to build the equivalent of these AOR digital voice modems. Looks like they sell for US$449 so to build something functionally equivalent based on a $38 Raspberry Pi is very attractive.

There's an interesting thread on the codec2 mailing list about running codec2 on a raspberry pi.

I imagine AOR are not too pleased about this prospect - if they are watching the road ahead, they would be working to build codec2 right in and they will pick up a potentially interesting early adopter market.

Looks like I'm not alone and ON1ARF is already working on this. Although he's using a pandaboard for decoding at this point.

We are at a fascinating time in Amateur Radio.

Update - audio on Raspberry Pi

Downloading and installing codec2 on the raspberry pi couldn't be simpler:

  • sudo apt-get install subversion
  • svn co https://freetel.svn.sourceforge.net/svnroot/freetel/codec2-dev codec2-dev
  • cd codec2-dev
  • ./configure
  • make
To get the play utility, install sox:
  • sudo apt-get sox

The test that encodes and then decodes out to the rpi's built-in audio works great:
  • cd src
  • ./c2enc 1400 ../raw/hts1a.raw - | ./c2dec 1400 - - | play -t raw -r 8000 -s -2 -
Next step, where I'm a bit stuck at the moment, is to record audio from an external USB headset. I plugged it in and you can list devices as follows:
  • arecord --list-pcms
My USB Headset is a little Sennheiser one, so I get:

$ arecord --list-pcms
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=headset
    Sennheiser USB headset, USB Audio
    Default Audio Device
front:CARD=headset,DEV=0
    Sennheiser USB headset, USB Audio
    Front speakers
surround40:CARD=headset,DEV=0
    Sennheiser USB headset, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=headset,DEV=0
    Sennheiser USB headset, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=headset,DEV=0
    Sennheiser USB headset, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=headset,DEV=0
    Sennheiser USB headset, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=headset,DEV=0
    Sennheiser USB headset, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=headset,DEV=0
    Sennheiser USB headset, USB Audio
    IEC958 (S/PDIF) Digital Audio Output


Copy the device name from the list above and use it in arecord and aplay below. To record 10 seconds of audio from the USB headset:

  • arecord -D sysdefault:CARD=headset -d 10 test.wav
To play that back to the USB headset:
  • aplay -D sysdefault:CARD=headset test.wav
I can hear my voice but it sounds terrible. It would be an abuse of codec2 to use it as input. Any tips would be appreciated!


10 comments:

Anonymous said...

Hi there,

I tried this too, and audio was terrible when recorded.

I found some suggestions on the web to use a higher sampling rate. e.g. specifying the 'dat' option even though it's only a mono input:

arecord -D sysdefault:CARD=Set -f dat -d 10 test5.wav
Recording WAVE 'test5.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo

My recorded test file was better, but sort of 'warbly'. Perhaps it will get better with later Pi software.

73,

Andrew ZL3AME

Anonymous said...

Hello again,

I also got good results using the plughw interface:

arecord -D plughw:1,0 test7.wav

This gave me a 8kHz mono file, which is probably what is needed.

73,

Andrew
ZL3AME

Peter Marks said...

Thanks Andrew.

Unknown said...

Hi Guys, My name is Craig callsign is ZS5F and i want to setup a raspberry pi as a fdmdv modem for my club members. basically what i am wanting to do is put the raspberry pi into a plastic box with a speaker and 3 connectors one for an external speaker one for a mic with the ptt and one for the radio. In simple a box to plug into our club members hf radios and allow us to use fdmdv. any comments are much appreciated.

Thanks in advance
Craig

Unknown said...

Hi I want setup fdmdv or similar accepted codec 2 for digital voice communication on hf. I have a rasperry pi which i want to setup and install in a box with 3 connectors. 1 for mic with ptt, 1 for external speaker and 3 for aux connector on hf radio or mic and speaker connecter on hf radio. Can you point me in the right direction.

Thanks in advance

73's de ZS5F
Craig

Unknown said...

Hi There,

I would like to setup a raspberry pi for fdmdv / codec 2 use on hf. basically i want to put a pi in a box and have 3 connectors on the box. one for mic/ptt one for external speaker and one for radio.

Any advise would be greatly appreciated.

73's de ZS5F
Craig

Peter Marks said...

Craig,

I would like to do the same thing as you. I've had a go but ran in to problems with audio input on the Rasberri Pi using a usb audio adapter.

If I figure it out, I'll post here, if you figure it out, please let me know.

Peter

Unknown said...

Hi Peter,

Do you still have a copy of the image file that you used on the pi. It would be nice to start from where you left off.

Thanks
Craig

Anonymous said...

Advise for Craig:
-pse add power jack. LOL. And more - connectors should be configured "through" in a way that one should be able to disconnect the "transparent box" as opposed to AOR "Black box" and use the same mic for direct /via box operation in a matter of seconds. It enhances mobility and field operation. Also I don't know a thing 'bout Pi power supply requirements, but a good advise is to utilise a PSU with 10.8 - 14.4V input range for emergency mobile operation, and output all the required voltages. If Pi is as power efficient as it claims to be, one could drop in a set of 3 lithium 18650 batteries and a charging controller, enabling portable operation for some hrs.

Well, this is the first "OMG SWAG I need to have this NOW!" moment I have had since the purchase of my FT-950.

I don't know a thing about linux programming but I'll follow this up.

This is amazing. A raspberry for CODEC2! I am a donator for codec2 (Papadopoulou is my wife, she has the credit card on her name lol) and I support the project from the early begginings back in 2009 any way I can.

de SV9OFO

Flavio said...

I can't even install it on the RPI
I added the two lines to /etc/apt/sources.list deb http://files.freedv.org/debian/ stable main
deb-src http://files.freedv.org/debian/ stable main
But when I do sudo apt-get update
I get GPG error: invalid KEYEXPIRED
Failed to fetch:http://files.freedv etc..
When I type sudo apt-get install freedv.
I get
E:Unable to locate package freedv.
Does anyone know what I'm doing wrong?

73,

Flavio VE2ZFP