Wednesday, November 24, 2010

Improving Codec2 Decode Speeds with Alternate FFT Algorithms

Codec2 operates nicely in real-time on a modern-class laptop, but I've been trying to push it into other devices. Real-time encoding and decoding on PIC32s will need to wait for a 16 bit integer version (which can make use of Microchip's DSP library), but how about ARM hardware? I ported the code to a Nokia N800 (400MHz ARM11), and it works nicely, but the decoding is choppy after a while because it just can't spit out audio in real time. Decoding will need about a 2x speed up. I've been able to get pretty close to that by swapping out Dave's Fast Fourier Transform function with a different one licensed under the GPL.

Friday, November 19, 2010

Codec2 across the network

Using a recent version of Ubuntu, we can use netcat to glue together some network transport of Codec2, preliminary to getting it on the airwaves. (Since Linux makes ax.25 <-> TCP/IP doable, we're theoretically half way there if we can get c2 within the network context.)

Monday, November 15, 2010

Festival Speech Synthesis and Codec2

Here'a a bash script that takes as its first argument a string of quoted text. It then passes this through the festival text-to-sound processor and plays two versions of the result. The first version is unprocessed; the second version has been encoded with codec2 and then decoded.

The results are generally impressive. But I hope this might be some help in improving the codec. For instance, the roughening of sibilants like 'sss' in English (which becomes something like a 'sh' under codec2) is easily reproduced with festival.

To use this script, change the first line to point to the directory in which your c2enc file resides, save the script as, say, 'tts-codec2.sh' and then issue the command 'chmod a+x tts-codec2.sh' so that the script is executable. Then run it on the command line with 'tts-codec2.sh "Salmon steaks grill beautifully."' You'll hear the non-codec2 version, then the codec2 version.

CODEC2_HOME=/home/brucerob/Codec2/codec2/src
TFILEA="/tmp/$(basename $0).$$a.tmp"
TFILERAW="/tmp/$(basename $0).$$.raw"
echo $1 | text2wave | sox - -r 8000 -t raw -s -2 $TFILERAW 
play -r 8000 -t raw -s -2 $TFILERAW
$CODEC2_HOME/c2enc $TFILERAW $TFILEA
$CODEC2_HOME/c2dec $TFILEA $TFILERAW
du -sh $TFILEA
play -r 8000 -t raw -s -2 $TFILERAW

Saturday, November 13, 2010

Codec2 Bash Scripts

Here's a bash script to round-trip a 8000Hz, 16-bit signed raw audio file through codec2. It takes the input file name and output file name as arguments:

CODEC2_HOME=/home/brucerob/codec2-2010-11-11/src
TFILE="/tmp/$(basename $0).$$.tmp"
$CODEC2_HOME/c2enc $1 $TFILE
$CODEC2_HOME/c2dec $TFILE $2

Here's a sox command to get a wav file (or whatever) into the proper raw format for codec2:
sox input.wav -r 8000 -t raw -s -2 output.raw

Friday, November 12, 2010

Codec2 Improvements

David VK5DGR is actively improving Codec2 in a process that he describes on his website. Until I became interested in this process, I hadn't realized how developing a codec is a pretty qualitative and subjective process.

Anyway, some recent patches to the alpha code aim to get rid of crackles from the encoding, and I think I can provide evidence that they have done just that. Last weekend I recorded myself describing my QTH, etc. in typical long-winded ham fashion. I then encoded and decoded this raw audio file to see how intelligible it was after being passed through Codec 2. The result was quite impressive. I think the greatest criticism could be the clicks that appear on my name, 'Bruce' and when I draw my breath in early in the QSO.

After reading that the recent changes aimed to eliminate those noises, I updated my repository, rebuilt the code, and then round-tripped this same file. Listen to the new file, and you'll hear that it has fewer distracting clicks, especially in the two sections I mentioned.

If you are testing Codec2, consider recording your audio files with a boom mike or something similar, not with a mic that will pick up echos and ambient noise. Currently the codec suffers quite a bit if such distractions are around. This is interesting, of course, and important, but unless you are planning to test these problems, you might want to have them set aside for now.

Monday, November 8, 2010

Fun with Codec2

 Here's a uuencoded, 511 byte message in Codec2. It is a full sentence!

begin 644 hello.c2
M&]&*F(K<H"O0CJB;_^`ATN[HOOK@L)#.[YYJX+*RQ.V>:F"YDLS*GFK@`=:L
MJ;9;8.UQCJFV2>#M4XJIMLC@XU:,N;++8*56KJN>R^"[]J[.MLK@MI3D[YKN
MX!-2K.Z?_6`+4:SJGMS@K=>.[Y;L0"-1K.R^U*`I$>[L_^7@)Q&,[I[%(*,1
MK.R[YL##$83N_^;@1_&,[)KF0`/1C.Z;<F#%4(3NO^)@'9&,[)KCX,.0BNZ>
MX^`(].KKFM-@!+"N^8K1($C\C.N*P4`,-8[IOE#@6?&.V8Y'P`_PCLB&5.!H
MEH[.AEU@T/*.SX9.X/+RCLV&SF#R](K+ADI@\MR.Z8;*X/+]BJF&RN#TMXB9
MA\M@_I&+^X_I8/_PB_^.Z6#_T(N]NDE@^=:/_;II8.GTC_6Z:V#KO.G]BDE@
MZ9RO_XYK8.N<K?J.RV#MG.N:CTM@Y+Y+F8=*8.K*QYJ+;^#JSN::C^[@YD+'
MF8YM8.1"0XFO[>#J0,6ZB^S@`,V[N_)<X++J[?^V3<":E*2)BL[@;["LZ+O?
MX(7PC$JJS^"!\*Q.BDW@AY"FROK-X)22XFRWS>"YEL(D_\W@\][B!+?,P`"V
MP":W5"`8EL(,F]3@`M3"+X_4X`I\PBZ/5>`F?L(DI5?@/`K")*]6H`P^P"2/
0UF`8?.(OCM)@&%3";H_2X```
`
end

Codec2 on Pic32: First Steps

In the dynamic field of digital ham radio projects, Codec2 just might be the most exciting one of all. A very low-bandwidth voice-to-digital codec has any number of uses: in fact, it is so important to future digital radio infrastructure that the D-Star architecture ended up using a proprietary codec for this purpose. Of course, D-Star's black-box chips are not most ham's style; we like to tinker; and in some contexts, like SDR radios and satellite communications, it's very difficult to work with locked-in hardware and code.

Enter David,  VK5DGR. He is  using his Ph.D. research to produce a patent-free voice codec for radio amateurs, with loud cheering from Bruce Perens, who has long championed this idea. The code is recently out in alpha , compressing to 2500 bps. It built quite happily on my Linux box, and the c2enc and c2dec applications will convert from and to 8000 bps, 16 bit signed RAW audio, producing very intelligible results.

Since I had a PIC32 chip on the bench, I decided to set aside work on the qrpTracker and see how far I could get in porting Codec2 to the PIC32. It isn't working yet, and I think we'll need integer math to get there, but I've made some progress.