Archive for May, 2008

USB speakers for my Alix board

May 15th, 2008 | Category: Linux

Because I needed USB speakers for my Alix board, I’ve made a quick search on geizhals.at and ordered what seemed the most reasonable to me: a pair of Techsolo TL-2020 USB speakers. They were USB powered (+), the price was some 10 Eur (+) and the power 10W (+). (If you stop reading here: don’t order them, read the conclusion!)

After plugging them into my Linux laptop they seemed to work. When I used them with my Alix board, the first strange thing that appeared was that they went into an undefined state (power led permanently off) when I turned on the desk lamp (wtf?).

The next and bigger trouble was, that I was able to bring them into an undefined state (garbage sound and/or power led off) by permanently starting and stopping playback in 1 second intervals during some hour. This worked reproducibly. The playback was done using my own player coded against the OSS API and talking to the snd-pcm-oss, snd-usb-audio kernel drivers.

First I’ve suspected the USB sound driver and tried to do some debugging, but without much luck.

Because this misbehavior was unacceptable for me, I decided to order some other USB speakers, but this time I was more carefully choosing the brand and model. The NSLU2-linux guys were recommending some USB sound chips as being known to work and the page at least mentions Logitech V10 speakers. Using another google search I’ve found a howto on making those speakers work with gentoo, so apparently someone has made them work under Linux. And using yet another google search, I’ve discovered that at least some revision of the V10 speakers used one of the chips the NSLU2-linux guys recommended as known to work.

Although they were more expensive (30 Eur), I’ve decided to order them because of their apparent good reputation. They work flawlessly. The test that brought the techsolo speakers down in one hour was unable to bring the logitech speakers down during 2 days.

Conclusion

  • Logitech v10 USB speakers work flawlessly for me with Linux.
  • I don’t recommend Techsolo TL-2020 USB speakers to be used with Linux.
4 comments

Compile-time algorithms with C++ templates

May 15th, 2008 | Category: C++

Recently, I was traveling in the train with a friend and we were talking about programming languages. So I’ve told him why C++ is among my favorite languages and what I think are its killer features. One of them were templates, and I mentioned that while java generics are implemented only by inserting cast byte code instructions at the right places, C++ templates are a turing-complete functional programming language.

He looked very surprised about that, so I have written a small example for demonstration, the compile-time factorial algorithm

#include <iostream>

// general formula for all N
template<int N>
struct factorial {
    static const int value = N * factorial<N - 1>::value;
};

// specialization for 0
template<>
struct factorial<0> {
    static const int value = 1;
};

int main() {
    typedef factorial<7> fac;
    std::cout << fac::value << std::endl;
}

The nice thing about this compile-time algorithm is, that its run-time complexity is O(1), as the generated machine code only prints the result (5040), which is computed at compile-time:

105                            .loc 1 18 0
106 0083 C745F8B0              movl    $5040, -8(%ebp)
106      130000
107                            .loc 1 19 0
108 008a 8B45F8                movl    -8(%ebp), %eax
109 008d 89442404              movl    %eax, 4(%esp)
110 0091 C7042400              movl    $_ZSt4cout, (%esp)
^^ std::cout
110      000000
111 0098 E8FCFFFF              call    _ZNSolsEi
^^ std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
5 comments