Skip to content

Instantly share code, notes, and snippets.

@pichenettes
pichenettes / bad_reputation.txt
Created June 24, 2019 15:45
Quick DIY translation of Brassens' "mauvaise réputation"
View bad_reputation.txt
In my humble village,
I have a bad reputation.
Whether I try to argue or remain silent,
I pass for a good-for-nothing.
Yet I'm not hurting anyone,
By following my own unpretentious path.
(Chorus)
But the good people don't like it,
When we follow a path different from theirs!
@pichenettes
pichenettes / pulse_additive.py
Created September 18, 2016 20:30
Pulse waveform additive synthesis
View pulse_additive.py
import numpy
import pylab
ratio = 0.333
t = numpy.arange(1000.0) / 1000.0
s = 0
for n in xrange(1, 1000):
harmonic = numpy.cos(2 * numpy.pi * t * n)
@pichenettes
pichenettes / voice_controller.cc
Created March 2, 2015 20:23
Anushri code modification for Volca clock sync
View voice_controller.cc
void VoiceController::Clock(bool midi_generated) {
voice_.set_lfo_pll_target_phase(lfo_sync_counter_);
if (!clock_counter_) {
if (!clock_out_counter_) {
clock_pulse_ = 8;
}
clock_out_counter_ = (clock_out_counter_ + 1) & 1; // Divide by 2.
ClockArpeggiator();
ClockSequencer();
ClockDrumMachine();
@pichenettes
pichenettes / coefficient.py
Created November 3, 2014 23:17
Mapping an uint16_t to a value between 32 and 32768 with an exponential scale; with only 64 bytes of constant data
View coefficient.py
import numpy
import pylab
# coeff = numpy.exp(numpy.arange(65536) * numpy.log(1000) / 65536.0) * 32.768
# coarse_table = numpy.round(coeff[::4096])
# fine_table = numpy.round(coeff[:4096+256:256] / 32.768 * 32768)
coarse_table = [ 33, 50, 78, 120, 184, 284, 437, 673, 1036, 1596, 2457, 3784, 5827, 8973, 13818, 21279 ]
fine_table = [ 32768, 33664, 34585, 35531, 36503, 37501, 38527, 39580, 40663, 41775, 42918, 44092, 45298, 46536, 47809, 49117, 50460 ]
@pichenettes
pichenettes / combinatorial_encoding.py
Last active December 11, 2015 05:09
Combinatorial encoding/decoding
View combinatorial_encoding.py
import math
def bin_string(n, size):
l = ['0'] * size
for i in xrange(size):
l[size - 1 - i] = '01'[n % 2]
n /= 2
return ''.join(l)
@pichenettes
pichenettes / bitshift.py
Created November 16, 2012 19:18
Bit shifting fractal function of death
View bitshift.py
import numpy
import pylab
def f(n, bit):
if bit == 0:
return n
else:
if n & (1 << bit):
return f(n % (1 << bit), bit - 1) + (n & (1 << (bit - 1)))
else:
@pichenettes
pichenettes / mr_cooley_tukey.py
Created June 23, 2012 11:12
Cooley-Tukey FFT step using Map Reduce (single MR step)
View mr_cooley_tukey.py
import numpy
global r, n
def run_mr(data, mapper, reducer):
"""Runs a map reduce locally."""
shuffled = {}
for k, v in data:
for out_k, out_v in mapper(k, v):
shuffled.setdefault(out_k, []).append(out_v)
@pichenettes
pichenettes / mr_cooley_tukey.py
Created June 23, 2012 10:12
Cooley-Tukey FFT step using Map Reduce
View mr_cooley_tukey.py
import numpy
global r, n
def run_mr(data, mapper, reducer):
"""Runs a map reduce locally."""
shuffled = {}
for k, v in data:
for out_k, out_v in mapper(k, v):
shuffled.setdefault(out_k, []).append(out_v)
@pichenettes
pichenettes / wave_doodle.py
Created February 22, 2012 11:54
Hertz Google Doodle, correctly done
View wave_doodle.py
import numpy
import pylab
points = [
(3, 3.0),
(3, 3.0),
(3, 3.0),
(2, 2.0),
(2, 2.0),
(2, 2.0),
@pichenettes
pichenettes / gist:1788715
Created February 10, 2012 10:47
Least square regression of complex amplitudes onto a synthetic signal subspace for an EDS+50 Hz hum model
View gist:1788715
import numpy
import pylab
delta = 0.01
omega = 0.05
omega_noise = 0.2
A = 5
A_noise = 0.2
phi = 0.8
N = 1000