Skip to content

Instantly share code, notes, and snippets.

@nauful
nauful / dsp_blit.cpp
Created May 7, 2024 14:06
DSP BLIT synthesis in C++
// This code generates a band limited impulse train, then uses the table
// to generate an antialiased square wave at two different frequencies.
// The computational cost of using BLIT is far less than a sinc resampler
// because points are only evaluated on sample changes instead of every
// sampled point.
const static lc_u32 AUDIO_RATE = 44100;
void agb_test_audio_blit() {
const int FRAME_AUDIO_SIZE = (AUDIO_RATE + 59) / 60;
@nauful
nauful / gist:4cce9552badbe648c60dac04af67e5fe
Created February 12, 2022 19:43
Implemented paper: "On the Implementation of Minimum Redundancy Prefix Codes, Moffat and Turpin 1997"
void test_huf(FileReader *reader) {
const int FAST_BITS = 7;
const int MAX_BITS = 11;
uint32 counts[0x100] = { 0 };
byte buf[1 << 12];
uint32 n = 0;
reader->Rewind();
while ((n = reader->Read(buf, sizeof(buf))) > 0) {
for (uint32 i = 0; i < n; i++) {
void opt_parse_path_alt(const byte* window, ParsePath* table, const MatchNode* match_table, State& state, int opt_current_p, int opt_start_at, int opt_next_at, int block_end) {
const int MAX_STATE_SIZE = 0x100;
const int MAX_STATE_MASK = MAX_STATE_SIZE - 1;
struct CarriedState {
byte match_hist;
BitNibble2 cmd[4];
RepState rep;
};
template<int scale_bits> void rescale_freq16(uint16(&freq)[0x100]) {
const int total_freq = 1 << scale_bits;
int total = 0;
for (int i = 0; i < 0x100; i++) {
total += freq[i];
}
uint64 div = (1ULL << 31) / total;
int N = fin.len;
const int CH_BITS = 25;
FSM fsm;
memset(&fsm, 0, sizeof(FSM));
memset(fsm.index, -1, sizeof(fsm.index));
init_fsm(fsm);
{
byte* t2 = new byte[1 << 24];
@nauful
nauful / DocumentInvertedIndexer.java
Last active May 20, 2019 15:26
Efficient and low-memory document indexer with inverted index + full-text search (ala Apache Lucene/ElasticSearch) extended to find partial word matches. Create meta-data nodes with ids and related arrays of prefixable text (i.e. document codes/tags), and nodes with ids and related arrays of body text (i.e. entire document bodies).
package com.iva.nlp.document;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
public class DocumentInvertedIndexer {
public static class Node {
private final int index;
@nauful
nauful / DocumentInvertedIndexer.java
Created May 20, 2019 15:22
Simple and fast document indexer with an inverted index (ala Apache Lucene/ElasticSearch) + full-text search. Create meta-data nodes with ids and related arrays of prefixable text (i.e. document codes/tags)
package com.iva.nlp.document;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
public class DocumentInvertedIndexer {
public static class Node {
private final int index;