From Pin Eight
Jump to: navigation, search

Until September 2009, I had used the Allegro library to develop PC games. Around that time, I found that XCode 3.2, included with Mac OS X Snow Leopard, could not build the Allegro library because the Allegro library depended on the QuickDraw framework, which Apple had deprecated and removed by XCode 3.2. In addition, the version of Allegro in the universe repository of at least Ubuntu 9.04 and through 10.04 is incompatible with PulseAudio.

So I looked into SDL, but I found it lacking in features that I had remembered from Allegro. This appears to be on purpose, as SDL operates at a somewhat lower level than Allegro, but the available extension libraries weren't a perfect match either. I took a vacation from PC game development, which included developing NES software such as Concentration Room. But knowing that whining solves nothing, I began work on the Pin Eight SDL extension, or p8sdl. Ideally, p8sdl should run wherever SDL does, but the first platform on which p8sdl will be tested is Ubuntu.


SDL_mixer supports one music stream and any number of waves for sound effects. This has limitations compared to Allegro's mixer. All sound effects are resampled to the sound card's output rate on load; there is no real-time pitch control, therefore no way to play engine noise in a racing game. Only one music stream can be played at a time; all other music must be loaded and pre-rendered as waves by some other library.

I plan to fix that by writing my own mixer with a far more general architecture inspired by Allegro's AUDIOSTREAM. Each voice in the mixer consists of a synthesizer, resampling factor for pitch control, and volume. In each "frame" of audio, the mixer runs the synthesizer for x number of samples and mixes the synthesizer's output into a buffer. For example, a voice playing a loaded PCM wave runs a synth that's the equivalent of memcpy(). A voice playing a compressed wave decompresses to the buffer. Even the mixer isn't a singleton; though only one mixer can be hooked up to SDL_OpenAudio, it's possible to make another mixer and use it as a synth, whose the program can feed into an audio file, an in-memory sample, or another mixer. This makes tracked music players easier to write, as one can have a mixer all to itself and not have to share voices with sound effects. Sure, there are more copy operations in this architecture than in a synth built around native support for mixing loaded wave files. But compared to the 25 MHz PCs that Allegro for MS-DOS ran on, modern PCs with CPU frequencies in the GHz are fast enough (and audio slow enough) that the flexibility is worth the slight CPU cost.


SDL_ttf can render scalable fonts. But it has a problem: scalable fonts are a lot more work to make than bitmap fonts, especially at small display sizes. Until recently, users of Windows had to perform a difficult Cygwin install because FontForge, the leading Free program to edit scalable fonts, didn't have a native Windows version. (Sometime in 2008, someone in Japan made an unofficial port of FontForge to MinGW.) In addition, most available scalable fonts are not free to redistribute, creating copyright problems. Finally, parts of the TrueType technology used by SDL_ttf were patented until July 2010.[1]

I have started to work around that by writing my own bitmap font library. A converter written in Python translates monochrome glyph sheets designed for the Allegro library into font files for p8sdl's text renderer. Later, I plan to write a converter to make bitmap fonts out of TTFs so that I can "scrub" copyright in the outlines from a font. Such "scrubbing" works because though the control points and hints making up a scalable glyph shape are copyrighted, the glyph shapes themselves aren't copyrightable in most of the world, and very few fonts are subject to a design patent.