Code

Jon Olick

Contained in this page is a bunch of useful code. This page is still a WIP as I pick through stuff to upload to the site.

MPEG Writer

License: public domain
Features: Single File, 256 lines of C code, No memory allocation

GIF Writer

License: public domain
Features: Single File, Extremely small (398 LoC), No memory allocation

Simple Windows 2D Drawing Shim

License: public domain

Kodak Image Set 2x Super Resolution

License: public domain

Scale Invariant Feature Transform (SIFT)

License: public domain

JPEG Writer

License: public domain
Features: Single File, Extremely small (336 LoC), No memory allocation

MPEG-1 Audio Layer 1 (MP1) Decoder

License: public domain
Features: Single File, Extremely small (397 LoC), No memory allocation

Image Resizing

License: public domain

PCM/ADPCM WAV File Writing

License: public domain

QR Code Generator

License: public domain

TGA file Writer

WAV file writer

Bilinear texture sampling

HBAO Shader

DCT/IDCT 8x8

Portable fsync()

​Quality Experiments with Audio at various Bit Depths

These experiments are part of a twitter discussion on the quality of audio at various bitrates and its suitability as a super fast near lossless audio codec (a replacement for Flac) when combined with Zip or Lzma. The only artifacts from quantization is the volume of tape hiss and the dynamic range of the audio itself. Therefore if you can make the tape hiss inaudible, its pretty much equivalent to lossless.

Try our your ears at this blind test between 8-bit and 16-bit audio

here

. 8-bit hiss is

audible

with quiet audio, but at 12-bits it becomes nearly inaudible at normal volume levels.

Check out this download for some experiments. Contained in the Zip is the same audio at 1 to 16 bits per sample. The quantization method is naive and can certainly be better, but results are pretty good at bit depths >= 5.

Javascript NES emulator

VA

​static const char *va(const char *fmt, ...) {
static thread_local char tmp[0x10000];
static thread_local int at = 0;
char *ret = tmp+at;
va_list args;
va_start(args, fmt);
at += 1 + vsnprintf(ret, sizeof(tmp)-at-1, fmt, args);
va_end(args);
if(at > sizeof(tmp) - 0x400) {
at = 0;
}
return ret;
}

using C++ Lambdas as C callbacks