Skip to main content

Posts

Showing posts from March, 2011

It's not that hard to manage expectations (with Perl)

Developers with a background in Ruby on Rails and PHP are familiar with the concepts of mocking objects and setting expectations on them. The good news is that these powerful techniques for unit testing are available for Perl as well. Should I add you can find them on CPAN ? Before an example though, just a simple explanation about the topic. Unit testing “is a method by which individual units of source code are tested to determine if they are fit for use” (Wikipedia). It’s a common practice to perform unit testing in isolation ; in other words you focus testing on the source code, limiting as much as possible the interaction across modules or systems. It’s almost always practically impossible to test a class without instantiating other classes on which it depends or interacts. What can be done is mocking objects : creating “empty objects” that emulate the external behaviour of real objects. They must be able to “fool” the class under test and allow the creation of an exhaustive set ...

A gentle introduction to G.729

G.729 is an 8 Kpbs audio codec, standardized by ITU , and called also CS-ACELP: Coding of Speech using Coniugate-Structure Algebraic-Code-Excited Linear Prediction , as that’s the algorithm used for audio compression. It has two extended versions: G.729A (optimized algorithm, slightly lower quality) and G.729B (extended features, higher quality), and it's popular in the VoIP world because combines very low bitrate with good quality (but alas is not royalty-free). G.729A takes as input frames of voice of 10 msec of duration, sampled at 8KHz and with each sample having 16 bit : This gives a frame size of 80 samples: 8000 sample/sec * 10 * 10e-3 sec/frame = 80 samples/frame The output is 8 Kbps, so each encoded frame is represented by 10 Bytes: 8000 bit/sec * 10 * 10e-3 sec/frame = 80 bit/frame = 10 Bytes/frame Quality Considering its bit rate, G.729 has an excellent perceived quality ( MOS ). Under normal network conditions G.729A has MOS 4.04 (while G.711 u-law, 64 kbps, has 4.4...

Test::Harness, or a lesson about wheels not to be reinvented

Let’s say you have your unit tests in place, using something not particularly esoteric as Test::More . Good. Now you want something to give some color to your output, so green is Good , red is Bad and you have a quicker feedback. Time ago I wrote a quick shell script to run all the unit tests, interpret the output (in TAP format), print on screen some color output and stop the tests if something fails. The core was: function check_test_result() { red='\e[0;31m' green='\e[0;32m' end='\033[0m' result=`perl $1`; echo "$result" perl -e '{ my $input = join(" ", @ARGV); if ($input =~ /not ok/m) { exit 0; } exit 1; }' $result if [ $? -eq 0 ] then echo -e "$red Not all tests passed. FAILURE$end" exit -1 else echo -e "$green All tests passed. SUCCESS$end" fi } This works as soon as the unit tests fail (printi...