Skip to content

Instantly share code, notes, and snippets.

Avatar

Saf safiire

View GitHub Profile
@safiire
safiire / phase_accumulator.dsp
Last active Dec 22, 2015
A Phase Accumulator / Sine wave generator in Faust
View phase_accumulator.dsp
import("math.lib");
Tau = 6.283185307179586;
Pi = 3.141592653589793;
Fs = SR;
oscillator(f, amplitude) = phase_accumulator(w) : sinf * amplitude with {
w = f / Fs * Tau;
sinf = ffunction(float sinf(float), <math.h>, "");
};
@safiire
safiire / pi_infinite_series
Last active Aug 29, 2015
Compute π with an infinite series
View pi_infinite_series
def f(n)
(2 * n + 1)**-1
end
def g(n)
((-1)**n).to_f
end
def pi
@safiire
safiire / dual_number_derivative.rb
Last active Oct 2, 2016
Simulataneously calculate a function and it's derivitive using Dual Numbers
View dual_number_derivative.rb
require 'matrix'
## Note: In ruby the notation x**n means x raised to the nth power
##
## In linear algebra, Dual numbers are in the form:
## a + bε
##
## Where ε is what is called nilpotent, you can think of
## ε as an infinitesimal (sort of kinda), like how they used to do Calculus in the
## olden days.
@safiire
safiire / rc_filter_simulation.rb
Created Feb 10, 2014
RC Lowpass Filter Simulation in both Ruby and Rust for comparison.
View rc_filter_simulation.rb
#!/usr/bin/env ruby
# encoding: UTF-8
require 'complex'
Tau = 2 * Math::PI
TableWidth = 20
#######################################################################
## This is a script I was using to simulate an analog Resistor
## Capacitor in series filter, to see if I had the math right.
@safiire
safiire / the_greatest_english_paragraph_of_all.txt
Created Feb 12, 2014
This is likley the greatest English paragraph, of all.
View the_greatest_english_paragraph_of_all.txt
For although light oftenest behaves as a wave, it can be looked on as a mote, the *lightbit*.
We have already said by the way that a mote of stuff can behave not only as a chunk, but as a wave.
Down among the unclefts, things do not happen in steady flowings, but in leaps between bestandings that are forbidden.
The knowledge-hunt of this is called *lump beholding*.
@safiire
safiire / lowpass.cpp
Created Jul 8, 2014
One Zero Low Pass Filter
View lowpass.cpp
#include <iostream>
#include <complex>
#define PI 3.141592653589793
#define SAMPLE_RATE 64
using namespace std;
// This lowpass is a weighted moving average
// If you change the + to - it will become a highpass filter
View make_wavetable.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "common.h"
// Enums
enum {SAW, SQUARE, SINE};
@safiire
safiire / c++11_example.cpp
Last active May 25, 2016
Messing around with C++11
View c++11_example.cpp
// C++11 is pretty neat so far.
//
// clang++ yay.cpp -o yay -std=c++11 -stdlib=libc++
#include <iostream>
#include <memory>
#include <vector>
#include <functional>
using namespace std;
@safiire
safiire / intersect.rb
Created Aug 28, 2014
Line Intersection with Matrices
View intersect.rb
require 'matrix'
####
## Random program that uses matrices to find intersection between 2 lines
## the linear algebra way.
## I am not sure why I made this, but it's probably because I like matrices
class Line
attr_reader :slope, :offset
@safiire
safiire / blog_sound_demo.asm
Created Mar 30, 2015
NES sound demo from my blog post.
View blog_sound_demo.asm
;;;;
; Create an iNES header
.ines {"prog": 1, "char": 0, "mapper": 0, "mirror": 0}
;;;;
; Include all the symbols in the nes library
.inc <nes.sym>
You can’t perform that action at this time.