Skip to content

Instantly share code, notes, and snippets.

View hollance's full-sized avatar

Matthijs Hollemans hollance

View GitHub Profile
@hollance
hollance / CRUEL CANNON.PRG
Created March 5, 2024 20:29
Cruel Cannon, a hangman type game for the C64 written in BASIC, circa 1993
0 poke808,225:gosub 31000
1 poke53269,0
10 remifa=0thena=1:load"c.font3",8,1
20 remifa=1thena=2:load"lespirites",8,1
900 ww=68:dim n(ww):dim keer$(50)
1000 rem *** the game ***
1010 rem ** after a game over **
1015 poke 53265,peek(53265) and 239
1020 sc=0:gd=0:ft=0:ln=0:l$="":w$="":keer=1:keer$(0)="":keer$(1)=""
1030 gosub 20000:gosub 10000:jaja=0
@hollance
hollance / StateVariableFilter.h
Created August 26, 2023 16:26
Cytomic SVF implementation in C++
#pragma once
#include <cmath>
/**
State variable filter (SVF), designed by Andrew Simper of Cytomic.
http://cytomic.com/files/dsp/SvfLinearTrapOptimised2.pdf
The frequency response of this filter is the same as of BZT filters.
@hollance
hollance / alignment-heads.md
Last active December 5, 2023 13:25
Alignment heads for Whisper word-level timestamps with Hugging Face Transformers

To allow the Hugging Face version of Whisper to predict word-level timestamps, a new property alignment_heads must be added to the GenerationConfig object. This is a list of [layer, head] pairs that select the cross-attention heads that are highly correlated to word-level timing.

If your Whisper checkpoint does not have the alignment_heads property yet, it can be added in two possible ways.

Method 1. Change the model.generation_config property:

# load the model
model = WhisperForConditionalGeneration.from_pretrained("your_checkpoint")
@hollance
hollance / ProtectYourEars.h
Created June 26, 2022 18:45
For testing audio code with headphones on...
#pragma once
#include <JuceHeader.h>
/**
Silences the buffer if bad or loud values are detected in the output buffer.
Use this during debugging to avoid blowing out your eardrums on headphones.
If the output value is out of the range [-1, +1] it will be hard clipped.
*/
inline void protectYourEars(float *buffer, int sampleCount)
@hollance
hollance / synth.c
Created May 21, 2022 22:19
Render basic waveform using Core Audio on macOS
// Compile this with:
// $ gcc synth.c -o synth -framework AudioToolbox
// Based on the CH07_AUGraphSineWave example from the book
// "Learning Core Audio: A Hands-On Guide to Audio Programming
// for Mac and iOS" by Chris Adamson and Kevin Avila
#include <AudioToolbox/AudioToolbox.h>
typedef struct
@hollance
hollance / BiQuadFilter.h
Created December 8, 2021 19:56
bi-quad filter in C++
inline float denormalsToZero(float x) {
return (std::abs(x) < 1e-15f) ? 0.0f : x;
}
/**
mystran's Bi-quadratic filter
https://www.kvraudio.com/forum/viewtopic.php?p=4836443#p4836443
This is not a direct form topology! Essentially it is modified coupled form
@hollance
hollance / Button.cpp
Created December 24, 2020 14:45
Arduino push button debouncing
#include "Button.h"
Button::Button() : _pin(0), _oldState(0) {
}
void Button::attach(byte pin) {
_pin = pin;
pinMode(_pin, INPUT);
}
@hollance
hollance / workaround.markdown
Created October 9, 2020 09:59
Workaround for Xcode 12 problems with Core ML models

I ran into a problem with Xcode 12's Core ML compiler, and several people have emailed me about what appears to be the same issue.

The workaround is to use Xcode 11 to compile the Core ML model. This means you still need to have Xcode 11 installed (which is a good idea anyway).

What worked for me is the following...

From the Terminal, switch to the Xcode 11.7 installation (your path may be different):

sudo xcode-select -s /Applications/Xcode11.7.app/Contents/Developer/
@hollance
hollance / ARC.ipynb
Created September 8, 2020 13:25
ARC test
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
A few years after my stint in Japan, I ended up back in the United
States, hired by an AI software outfit to be their director of corporate
communications. Cool, I thought. That sounded important. I had no idea
what it meant. Only later did I discover I'd become their PR guy.
Bummer.
I was pretty naive back then, but I quickly figured out that public
relations was perceived by the press — the people I was supposed to be
talking to — as little more than thinly disguised hucksterism. I tried
playing the high-tech huckster role precisely once and came away from