Playing the Smile song on VESNA

26.06.2013 17:53

A while back I was writing about wireless microphone simulation with VESNA. The reason back then was to be able to use remotely-accessible sensor nodes as targets for spectrum sensing experiments. However when I was writing the direct digital synthesis code it occurred to me that transmitting just a stationary tone is slightly boring. Basically nothing was preventing me from transmitting something more fun.

Since playing back recorded audio has somewhat prohibitive storage requirements for a low-powered sensor node I decided to try with a software music synthesizer. If microcomputers in the 80's were able to do it, there should be no reason why a modern ARM CPU couldn't. I've never actually written a synthesizer before and as usual when playing with sound or graphics experimenting with this code was incredibly exciting.

In the end I implemented a 6-channel wavetable synthesizer. Since now I was more concerned with audio quality than correct spectral envelope I replaced the 2-bit quantization with 1-bit and added delta-sigma modulation. This way I was able to exploit the high bit-rate supported by the CC1101 transceiver to get 4 effective bits of audio signal resolution since delta-sigma moved some quantization noise above audible frequencies. The best (subjective I guess) compromise between resolution and sample rate was at 25 kHz audio sample rate and 16x oversampling.

The most complicated thing in all of this was actually figuring out how to interpret time information in a MIDI file. There's a lot of information about this floating around but in the end understanding how to convert all of those weird music units into seconds and milliseconds took way more time than I thought.

VESNA audio synthesis demo block diagram.

It turns out that the 72 MHz Cortex M3 CPU on VESNA runs such a synthesizer without a breaking a sweat. The limiting factor was interrupt load because the streaming of data to CC1101 had to be done with software bit-banging. Since this use case wasn't exactly planned for VESNA no integrated serial bus peripherals are connected to GPIO lines that are used by CC1101 for data streaming. The software implementation handles at most 400 kbps while the transceiver goes up to 800 kbps, which would allow for one additional bit of audio signal resolution.

At high bit rates the size of the synthesis buffer also starts getting problematic. Since you want the buffer to cover at least a few periods of the lowest audio frequency you quickly run out of 96 kB of RAM on VESNA if the baseband rate is significantly higher than the audio rate.

Anyway, hacking on this has been seriously enjoyable. It was one of those side projects that give you strange looks at the office and are hard to explain to someone without giving a fair amount of background information. But in the end there's just something fundamentally fun about having at your fingertips the power to convert 50 remote devices into wireless microphones transmitting a happy song sung by a cartoon pink pony (because seriously, what else would you want to transmit over a city-wide sensor network?)

You can see a short video demonstration above which should give you an idea of what kind of audio quality is possible with this setup.

Audio synthesis source code is hosted on GitHub if you are curious about the details. Also, if you'll be in Köln two weeks from now, look for my lightning talk about this hack at SIGINT 2013.

Posted by Tomaž | Categories: Code | Comments »

Decline and fall of Kiberpipa

08.06.2013 16:50

I guess by this time it's a well known fact around here that Ljubljana's hackerspace Kiberpipa has come to the end of its days, at least in its current place and form. A farewell party has been held, good byes have been said and all it remains now is to start unplugging the server rack.

If you haven't been following the news, the simple story is that Kiberpipa's parent organization twice removed decided to convert the place into a restaurant. Destruction of a hackerspace is merely a collateral damage in a grand scheme of converting an old building full of non-profit student and art organizations into a very for-profit hotel in a sweet spot near the center of the city. As it's usual in such cases there's also a back story that involves removing opposition through legalistic procedures and suspicions of personal interests. It was all done under cover and the community found this out only after the contracts have been signed through rumors, hearsay and digging through meeting minutes. An official statement has only been made when media started asking questions even though Kiberpipa had a representative that should be kept up to date with such things.

Kiberpipa storage room.

I'm not and never was involved in the internal politics of Kiberpipa's tenuous relationship with its masters. For me, Kiberpipa was foremost a place to go to after lectures and later after work where I could meet the kind of people that enjoyed idly chatting about technology and various other geeky topics instead of sports events and daily politics. As I was involved in Kiberpipa from the start I did use to have daily responsibilities there, like administration of servers and taking care of network security. Kiberpipa was also the place of my attempt at running a serious free software project. Many hours were spent at weird hours in a cramped server room and I learned a lot from these jobs, but unlike other hackerspaces, Kiberpipa's attractiveness was rarely about having access to equipment that I wouldn't have otherwise. It was foremost the social aspect that kept me returning to the place. I found many valuable personal connections that later led me to start ups and other interesting volunteering work.

That said, Kiberpipa never felt like a tightly knit community. People that frequented the place or used its name on projects were always divided into groups that did not communicate well with each other. Contrary to most other hackerspaces, Kiberpipa was from the start tied to a relatively large non-profit that ran several other, mostly artistic operations, under control of the Student organization of the University of Ljubljana. For majority of my time in Kiberpipa they were kind of a fuzzy entity that only showed itself only when it exercised its power over some official aspect of the organization or left the place in ruin after an unannounced party. Ties between the more technical hacker crowd and arts communities were rarely relaxed. Often there was an unusual reversal of roles where artists were the ones supplying money through various public grants and technical people perceived as moochers playing with their toys. In its early days there was also a strong political activism side to Kiberpipa with which I didn't particularly identify myself either.

Kiberpipa server room.

When a rare project that involved collaboration happened, it was often setup and discussed outside of general channels like the member's mailing list. It's not surprising then that in all years of its existence and numerous formal and less formal meetings and discussions it was never possible to come up with a mission statement or give an answer what Kiberpipa was that everyone would agree with.

Even with hindsight it's hard to say what could have been done differently. It's doubtful that Kiberpipa would be this successful without its partnership with the student organization that ultimately led to its destruction. It provided an accessible, rent-free place and connections to government subsidies that removed the need for membership fees. With them the place would certainly attract a lot less people. Kiberpipa's community also showed a lot of flexibility, changing over the years its external face from mostly being a free cybercafé to a place to go to for lectures and workshops about various topics. Part of this probably comes from the fact that the community never learned how to transfer knowledge between generations, but still it's impressive enough that comments can be heard from old members that they never though the place would survive for 13 years.

Kovchek, Kiberpipa's old mobile video streaming server.

Although I mostly kept myself in the background and had my share of conflicts and grief there, Kiberpipa has been a big part of my life and I'm sad to see it end like this. Things may not be as bad as they look though. The latest generation of Kiberpipa's members are looking for ways of continuing the story in an independent fashion and although I'm not actively involved in that effort I hear that the outlook is good. I'm usually too pessimistic in such writings anyway. For better or worse I am quite certain though that Kiberpipa 2.0 will be quite different from the dark and smelly open source cellar we started 13 years ago.

Posted by Tomaž | Categories: Life | Comments »

Cookie law compliance

02.06.2013 19:06

On 15 June a new Slovenian law on electronic communications comes into effect. Among other things it implements the European cookie directive which makes Slovenia one of the last countries in the Union to comply with it.

Slovenian law makers decided on a stricter interpretation of the directive than most other countries, making illegal for instance storing any state on a visitor's browsers without her explicit consent. There are very few exceptions to this rule, for example where local state is the only way to implement some functionality (shopping carts for instance) or where this is expected (when you log in with a user name). But otherwise our Information commissioner is quite clear that various tracking cookies and such for anonymous users must go away unless a click-through warning is added to a web page. It remains to be seen to what extent this will be enforced though, especially since parts of the law also attempt to restrict what kind of processing you can do on plain web server access logs.

Since I started writing this blog I've been quite careful to respect the privacy of visitors on my web site. I never used cookies and for most of its existence these pages didn't include any third-party Javascript. I never used Google Analytics or other third-part analytics services and my own web server logs are only used for occasional local statistical processing when I'm curious about the number of visitors to particular articles.

I was therefore somewhat surprised when I was discussing this topic in our local Open data community and we ran some automated tests against my pages. It turns out the situation was not as rosy as I thought.

First problem was that against all odds cookies were getting set for my domain. I tracked it down to jsMath, which I use to typeset mathematical notation in some blog posts. jsMath uses a cookie to store settings you can change using a small toolbox that appears in the lower right corner of the website when a text with mathematical symbols is displayed (I'm quite sure nobody noticed it though).

That cookie isn't problematic however, since changing settings is an explicit action that is expected to save some state (the box also has an option for how long you wish the settings to be retained making that fact even clearer). However for some reason jsMath will always set a default cookie on the first visit, even if you don't touch any settings. That's not OK even though the cookie doesn't include any unique identifiers (and in fact is used solely on the client side, even though the browser will send it to my server on each HTTP request).

I'm not sure whether this is a bug in jsMath or if this is intentional. Anyway, the simple one-line patch below corrects this behavior and retains the setting-saving functionality if you happen to use it:

--- a/uncompressed/jsMath.js
+++ b/uncompressed/jsMath.js
@@ -1834,7 +1834,7 @@ jsMath.Controls = {
   cookie: {
     scale: 100,
     font: 'tex', autofont: 1, scaleImg: 0, alpha: 1,
-    warn: 1, fonts: '/', printwarn: 1, stayhires: 0,
+    warn: 0, fonts: '/', printwarn: 1, stayhires: 0,
     button: 1, progress: 1, asynch: 0, blank: 0,
     print: 0, keep: '0D', global: 'auto', hiddenGlobal: 1
   },

The second problem I had was that a few of my posts embed YouTube videos. That's a problem since YouTube player will drop two Flash Local Shared Objects on the visitor's computer as soon as it is loaded (even if you use the nocookie domain).

To my knowledge it is now impossible to embed a YouTube video on a web site and comply with the Slovenian law unless you provide a click-through warning. Since I find those obnoxious I chose to remove all embedded videos and replace them with static thumbnails that you can click-through to watch the video on the YouTube web page itself.

The other option would be to find some other video hosting service that would not set cookies (if it even exists) or host video files myself (which didn't end well a while ago). Both of these require more time than I'm willing to spend fixing this issue at the moment.

Posted by Tomaž | Categories: Code | Comments »