Welcome

Using storage

You may have seen this video:

It's history is pretty nice: it's originally a music track from the game Touhou which was then re-made, improved, and had a clip made by various fans and groups. The end result, as you can see, is a catchy tune with nice and fluid shadow-play animations.

Because the video is black-and-white, it could be played on a variety of devices, and many a hacker had fun with it. The simplest variant is to show it in ASCII art , but more complex example feature the video being played on an original IBM PC/XT, a TI/84 calculator, an Atari 2600, or a laser scanner. People with less programming experience also had their fun with it, by example carving the clip in a real apple or by doing an awesome stop motion video by basically printing out every single frame of the movie.

So how do we get this on a Vectrex? I started by just ripping the video off of Youtube. Then I needed to dissect it, so I ran it through mplayer with some options that would give me every single frame as a png file and the audio track as a .wav file. Raster images wouldn't do me any good on a vector-based machine like the Vectrex, so I ran Potrace, the same tool Inkscape uses for vectorizing raster images, on every frame. With the right settings, this spits out a JSON file describing the vectors. I had to post-process this file before I could use it on the Vectrex: for example, the Vectrex uses relative vectors. I wrote a small script in PHP to do that. The Vectrex can also only display so many vectors before the image becomes flickery, so on high-vector frames, the script simplifies the image to make sure the Vectrex can show it flicker-free. For example, here's a frame which the script could just use directly (on the left) and another one where it had to optimize away a fair few vectors (the musicians on the right):

So now we had video. I also wanted audio, though. Unfortunately, the Vectrex isn't really made to reproduce digital samples: the sound chip it has is a 3-channel AY-3-8912 PSG which can make some nice bleeps and bloops, but getting digital audio out of it requires abuse I just can't spare the clock cycles for. Fortunately, the Vectrex has an other way to generate sound: the 8-bit DA-converter that normally drives the video circuit can be redirected to inject its output directly into the audio amplifier input.

This gives two problems. First of all, because we're using the same DAC to do both video and audio, we can only use it for a short while between vectors to actually output something. Because the output is 'silent' while the vectors are drawn, this means the sound level will be pretty low. Also, when the DAC can output sound is dependent on when a vector has finished drawing; this makes timing pretty critical.

The volume problem can be solved in a not-so-nice but fairly trivial way: just turn the volume knob on the Vectrex to the max and the audio will get through. The timing problem I solved another way. First, I made a ROM which can play the animation with the sound muted. I then load that up in a modified version of VecX, a vectrex emulator. My version is modified to amongst others be able to access the animation data, implement DAC sound (somewhat) and output debugging data. When the cartridge is done with a vector and can send a sound sample, it'll write the timing of that event to a file. Finally, I can use that file to find the exact sample that should be played at that time, re-parse the video and audio data and have a cartridge with sound.

The end result is pretty good, for a 33-year old console: although the sound is pretty noisy, the sound track is easily recognizable and the animations are nice and fluid:

« Prev 4 Next »


© 2006-2022 Sprite_tm - Contact