Archive for July, 2004

A new blog

Thursday, July 29th, 2004

A new initiative at Microsoft means that everyone (at least in my division, not sure about others) has to spend at least 4 hours a month interacting with customers and partners. It's a good idea in principle but unfortunately I have never actually had occasion to seriously use the tools I write - I've never written any software targetting the .NET Compact Framework other than trivial programs to test my own work. Therefore I'm really not the person to answer the sort of questions my customers ask.

Fortunately I found a loophole - I have to interact with customers, but they don't necessarily have to be my customers. I've started a work blog here which talks about C++ and general programming techniques. I'll continue to post here just as frequently (posting here less frequently would be extremely difficult) and will continue to talk about the same things, as the sort of things I talk about here would probably not be appropriate for my work blog.

No spaghetti

Sunday, July 25th, 2004

We went to one of our favourite strip-mall Italian restaurants on Friday night, and would you believe it? They had run out of spaghetti. Imagine that - an Italian restaurant that had run out of spaghetti. Well we didn't have to. The very concept still boggles my mind.

This is pretty funny, and fairly accurately represents some of my views on the whole Microsoft dividend thing last week.

More geekism

Sunday, July 11th, 2004

I finally got my 8253 timer project finished. One minor hurdle that I didn't anticipate is that MESS's abstraction of the host computer's soundcard and its emulated CPU aren't synchronized. The soundcard is supposed to request samples from the emulated CPU at 44.1KHz, but according to the emulated CPU it seems to be doing it slightly faster than that (or the emulated CPU is running slightly slow by the soundcard's standard) so my buffer keeps underrunning.

The way to fix this is to tell the CPU to generate samples at a slightly higher rate (according to its clock) so that the soundcard and the CPU stay in sync. The trouble is, I don't know exactly how much faster the soundcard is than the CPU. Besides which, it seems to fluctuate and the ratio may even be completely different on a different machine.

The next thing I tried was dynamically adjusting the sample rate 60 times a second to the value which was calculated for the previous time-period. The problem with this was that the variations in the sample rate could sometimes be quite large, and the resulting "flutter" of the emulated computer's soundtrack sounded absolutely awful. Also, the buffer might now be slightly less full than optimal (leaving little room for further error) or slightly more full than optimal (causing the soundtrack to "lag" behind the graphics a bit). Clearly the most elegant way to solve this would be to smooth out these variations in such a way that the average sample rate over long time would be correct.

Next, I set up a running total of the "drift" time, and adjusted the sample rate in proportion to this. Of course, this caused the sample rate to oscillate around the correct value - I needed some damping to remove "energy" from the system. A couple of pages of calculations later I had modelled the system with a second order differential equation and solved for the critical damping value. After some tweaking of the buffer length and time-constant values it now works wonderfully - no buffer underruns, no noticable flutter and the graphics and sound are fairly well synchronized.

The only problem now is the aliasing - the 8253 timer in the PC can generate frequencies of up to almost 600KHz, and because of the rather unscientific way I'm downsampling that high-frequency waveform down to 44,100Hz (roughly) all the harmonics too high for the soundcard to play are aliased down to frequencies between 0 and 22,050KHz (roughly) so when you attempt to play a square wave, you get a whole pile of harmonics you weren't expecting and it sounds rather less than perfect. Since the sampling rate drifts up and down, playing a constant high-pitched tone makes all sorts of swooping noises. I wonder if it would be feasable to use a proper finite impulse response filter to downsample while removing all the frequencies that are too high-pitched to play...

For those rare few of you for who are not interested in all this geek stuff, here are some rather spectacular mazes.

Aliens from outer space

Saturday, July 10th, 2004

Yesterday, I discovered that there is incontrovertible proof that aliens from outer space landed in the U.S. and that this was known by various authorities, right up to President Bill Clinton.

This is not a hoax - everything you are about to read is absolutely true.

The aliens touched down at runway 15 of the Kennedy Space Center in Florida, at 10:54:34am EDT on July 7th, 1995, and came from the (then) largest spacecraft ever observed in orbit around Earth.

The names of the aliens were Vladimir Dezhurov and Gennadiy Strekalov. They were cosmonauts aboard the Russian Mir space station. When the space shuttle Atlantis docked with Mir during mission STS-71 (forming the then largest spacecraft ever in orbit) these two cosmonauts were transferred to Atlantis and brought back to Earth.

U.S. entry visas for Dezurov and Strekalov were forgotten before the launch of the spacecraft that took them to Mia. The U.S. State Department had to ask for a waiver for "aliens from outer space". The INS agreed not to arrest the cosmonauts for illegal entry into the United States.