Skip to content

Instantly share code, notes, and snippets.

View Enkerli's full-sized avatar

Alexandre Enkerli Enkerli

View GitHub Profile
@Enkerli
Enkerli / tonespace_chords.rb
Created April 23, 2017 06:38
Sonic Pi script to emulate the tonespace MIDI harmonizer from mucoder.
use_real_time # Preventing latency
use_tuning :just, :c # Just Intonation, chords are diatonic in C major
with_fx :compressor, threshold: 0.1 do # Preventing clipping
with_fx :reverb do # Everything on the same reverb
with_fx :lpf, cutoff_slide: 0.02 do |filtre| # Everything on the same breath-controlled filter
baritone = synth :hoover, note: 0, release: 1000, amp: 0 # “Classic early 90’s rave synth”
tenor = synth :chipbass, note: 0, release: 1000, amp: 0 # “A 16 step triangle wave modelled after the 2A03 chip found in voice 3 of the NES games console.”
alto = synth :beep, note: 0, release: 1000, amp: 0 # Sine wave
soprano = synth :chiplead, note: 0, release: 1000, amp: 0 # “A slightly clipped square (pulse) wave with phases of 12.5%, 25% or 50% modelled after the 2A03 chip found in voices 1 and 2 of the NES games console.”
@Enkerli
Enkerli / spi_mbe.rb
Created April 21, 2017 17:01
Sonic Pi script to create four-part harmony from incoming notes using the “rotating chords” effect pioneered by Robby Kilgore in his work with Michael Brecker. Video here: https://vimeo.com/214204872
# Thirty years ago, Robby Kilgore invented a neat harmonization effect for Michael Brecker: http://robbykilgore.com/?p=19
# The basic idea is that incoming notes are doubled by rotating intervals. So you get diverse chords from the same melodic notes.
# This script is an attempt to reproduce the same effect.
use_real_time # Prevents latency
use_synth :fm # Other interesting synth sounds for this: [:hoover, :prophet, :blade, :fm]
middle=[-8, -5, -7, -1].ring # Rotating intervals for the middle note of each chord.
low=[-12, -17, 0].ring # Rotating intervals for the “bass” note of each chord.
@Enkerli
Enkerli / spi_osc_bridge.pde
Created November 25, 2016 07:45
Using TouchOSC to control Sonic Pi, with Processing as a bridge.
// Passing on OSC data to Sonic Pi
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myBroadcastLocation;
void setup() {
background(0);
frameRate(60);
@Enkerli
Enkerli / skywriter_osc_client.py
Created November 25, 2016 05:09
Controlling Sonic Pi using Pimoroni's Skywriter HAT. A Python script to send OSC messages with xyz coordinates, and a Sonic Pi script to do something with those coordinates. Also works with Alexandre rANGEL's scale-based Sonic Pi script. https://gist.github.com/AlexandreRangel/e82072203fcf4b89f12003b1f1a957fa
"""Based on Small example OSC client from Python-OSC, and Synth.py from Pimoroni's Skywriter examples.
This sends the Skywriter HAT's xyz coordinates as OSC messages to Sonic Pi.
"""
import argparse
import random
import time
import skywriter
import os
import signal
@Enkerli
Enkerli / spi-ctl-bpf.rb
Last active September 15, 2023 02:27
A Sonic Pi script (spi-ctl-bpf.rb) and a Processing one (spi_ctl_bpf.pde) to control a band pass filter using the mouse. Been having performance issues with the sound lagging behind. Setting `set_sched_ahead_time!` in Sonic Pi sounds like it helps, but not enough. Original code from Robin Newman: https://gist.github.com/rbnpi/ca5e80258c0c1296b1c…
set_sched_ahead_time! 0 # Setting that one to a negative value makes Sonic Pi complain, it sounds like.
with_fx :bpf do |s| # Setting up the fx to be controlled internally
synth :square, note: 32,release: 400 # Long release as the control will affect a single note
live_loop :ctl do # The loop is inside the fx as this is where the action will be.
ctl=sync "/ctl" # The OSC message which Processing sends, based on mouse coordinates.
rz=ctl[:args][0] # Assigning the first argument to resonance.
ct=ctl[:args][1] # Assigning the second argument to centre.
control s, res: rz, centre: ct # The actual control of the fx.
set_sched_ahead_time! -2 # Sounds like setting this again every time actually helps.
@Enkerli
Enkerli / gist:3f3b4bf5134e3d1cfed5c0258dcea94c
Created November 4, 2016 06:06
Colour version of exercise 13-5 in Daniel Shiffman’s Learning Processing book (2015: 249). Enjoying the effect: https://www.dropbox.com/s/k3n7y6m85y49rn7/cartesian-spiral.png?dl=0
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Exercise 13-5: Using Example 13-5, draw a spiral path. Start in the center and move
// outward. Note that this can be done by changing only one line of code and adding one line
// of code!
// A Polar coordinate, radius now starts at 0 to spiral outwards
float r = 1;
@Enkerli
Enkerli / distance_pulse.py
Created May 21, 2016 03:11
Simple #RasPi script to change a passive buzzer’s frequency based on an ultrasound distance sensor.
from gpiozero import *
from time import sleep
sensor = DistanceSensor(24, 23)
n = 0
bz = PWMOutputDevice(18, initial_value=0.4)
bz.pulse(fade_in_time=0.3)
while True:
print('Distance to nearest object is', sensor.distance, 'm')
@Enkerli
Enkerli / geyger.py
Created May 21, 2016 01:46
#RasPi script to link a passive buzzer to a distance sensor. The effect is similar to a geiger counter. Based on this code to play melodies on a passive buzzer: http://www.linuxcircle.com/2015/04/12/how-to-play-piezo-buzzer-tunes-on-raspberry-pi-gpio-with-pwm/
import RPi.GPIO as GPIO #import the GPIO library
import time #import the time library
from gpiozero import DistanceSensor
class Buzzer(object):
def __init__(self):
GPIO.setmode(GPIO.BCM)
self.buzzer_pin = 22 #set to GPIO pin 22
GPIO.setup(self.buzzer_pin, GPIO.IN)
GPIO.setup(self.buzzer_pin, GPIO.OUT)
@Enkerli
Enkerli / voice-granulator_touchosc_accel.pd
Last active May 16, 2016 02:10
Slight tweak of Voice Granulator by davidjgurney, adding accelerometer control through TouchOSC. http://www.davidjgurney.com/portfolio/wall-e-style-voice-granulator/
#N canvas 431 139 708 570 10;
#N canvas 553 258 450 300 soundload 0;
#X obj 100 157 openpanel;
#X obj 100 100 bng 45 250 50 0 empty empty Load 11 22 0 10 -261682
-33289 -33289;
#X msg 100 182 read -resize \$1 soundfile1;
#X obj 100 209 soundfiler;
#X floatatom 100 233 10 0 0 0 - - -;
#X obj 100 256 s filelength;
#X obj 254 238 samplerate~;
@Enkerli
Enkerli / pot-tone.html
Created May 7, 2016 22:27
Simple Arduino code: control pitch with a potentiometer. Material required: potentiometer, piezo buzzer, Arduino board, jumper cables.
<pre>
<font color="#00979c">void</font> <font color="#5e6d03">setup</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#000000">{</font>
&nbsp;<b><font color="#d35400">Serial</font></b><font color="#434f54">.</font><font color="#d35400">begin</font><font color="#000000">(</font><font color="#000000">9600</font><font color="#000000">)</font><font color="#000000">;</font>
<font color="#000000">}</font>
<font color="#00979c">void</font> <font color="#5e6d03">loop</font><font color="#000000">(</font><font color="#000000">)</font> <font color="#000000">{</font>
&nbsp;<font color="#00979c">int</font> <font color="#000000">readTime</font> <font color="#434f54">=</font> <font color="#000000">20</font><font color="#000000">;</font>
&nbsp;&nbsp;&nbsp;<font color="#434f54">// read the input on analog pin 0:</font>
&nbsp;<font color="#00979c">int</font> <font color="#000000">sensorValue</font> <font color="#434f54">=</font> <font color="#d35400">analogRead</font><font color="#000000">(</