Skip to content

Instantly share code, notes, and snippets.

View bit-hack's full-sized avatar

Aidan Dodds bit-hack

View GitHub Profile
@bit-hack
bit-hack / float_band_lim_wav.c
Created July 3, 2018 08:35
Floating Point Band limited waveform tables
static const float bl_sqr_1024[] = {
0.097529f, 0.289545f, 0.472608f, 0.641306f, 0.791023f, 0.918181f, 1.020420f, 1.096688f,
1.147256f, 1.173645f, 1.178479f, 1.165270f, 1.138160f, 1.101625f, 1.060181f, 1.018096f,
0.979137f, 0.946363f, 0.921979f, 0.907263f, 0.902558f, 0.907333f, 0.920304f, 0.939604f,
0.962981f, 0.988014f, 1.012329f, 1.033791f, 1.050671f, 1.061757f, 1.066433f, 1.064683f,
1.057065f, 1.044619f, 1.028753f, 1.011100f, 0.993361f, 0.977153f, 0.963869f, 0.954573f,
0.949915f, 0.950097f, 0.954878f, 0.963611f, 0.975324f, 0.988818f, 1.002784f, 1.015926f,
1.027076f, 1.035291f, 1.039934f, 1.040715f, 1.037706f, 1.031323f, 1.022269f, 1.011470f,
0.999976f, 0.988866f, 0.979147f, 0.971666f, 0.967040f, 0.965603f, 0.967391f, 0.972140f,
0.979327f, 0.988219f, 0.997949f, 1.007598f, 1.016279f, 1.023220f, 1.027828f, 1.029741f,
@bit-hack
bit-hack / band_lim_wav.py
Last active July 3, 2018 08:50
Band limited waveform sample generation
import math
import csv
import StringIO
import random
def sinc(x):
theta = 2.0 * x * math.pi * 4.0
try:
return min(1.0, math.sin(theta) / theta)
@bit-hack
bit-hack / vlq.h
Created June 22, 2018 22:06
variable length quantity
#pragma once
#include <stdint.h>
#include <array.h>
// read variable length quantity
uint32_t _vlq_read(const uint8_t *&out) {
uint32_t val = 0;
for (;;) {
const uint8_t c = *(out++);
val = (val << 7) | (c & 0x7f);
@bit-hack
bit-hack / prefix_codes.cpp
Last active June 22, 2018 14:49
256 variable length prefix codes
struct prefix_code_t {
uint8_t index; // length sorted index
uint8_t size; // number of bits in prefix code
uint32_t code; // bit encoded prefix code
};
static const prefix_code_t codes[] =
{ 0x0fd, 0x12, 0x0003ffff }, // 00000000000000111111111111111111
{ 0x0ff, 0x13, 0x0005ffff }, // 00000000000001011111111111111111
{ 0x0fe, 0x13, 0x0001ffff }, // 00000000000000011111111111111111
@bit-hack
bit-hack / asfc_table.cpp
Last active June 22, 2018 14:50
Addaptive shannon-fano coding table generation
#include <algorithm>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
static int _coin_toss() { return ((rand() % 100) < 80) ? 1 : 0; }
struct code_t {
@bit-hack
bit-hack / lz.cpp
Last active June 23, 2018 00:12
LZ encoder/decoder sketch
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <vector>
struct entry_t {
bool match;
@bit-hack
bit-hack / kmeans.md
Created June 17, 2018 23:41
A k-means palette generation mockup
static uint32_t num_itters = 32;
static uint32_t num_clusters = 16;

struct rgb_t {
    uint8_t r, g, b;
};

struct cluster_t {
@bit-hack
bit-hack / sort.cpp
Last active June 5, 2018 12:34
Small array sort test
#include <stdlib.h>
#include <assert.h>
#include <intrin.h>
#include <array>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#undef min
#undef max
@bit-hack
bit-hack / edge_function.cpp
Last active May 22, 2018 18:24
derive triangle interpolation edge functions
// triangle setup
//
struct tri_setup_t {
tri_setup_t(const std::array<float2, 3> & t)
: _t(t)
, _i(tri_calc(t))
{
}
@bit-hack
bit-hack / cl.cpp
Created May 16, 2018 08:45
opencl test
#include <CL/cl.h>
#include <array>
const char *source = R"(
kernel void mult(global float *data) {
const int id = get_global_id(0);
data[id] *= 2.f;
}
)";