Skip to content

Instantly share code, notes, and snippets.

View ariutti's full-sized avatar

Nicola Ariutti ariutti

View GitHub Profile
@ariutti
ariutti / crc_calculator.py
Last active March 17, 2020 10:39
A python snippet to calculate CRC from a list of bytes
#!/usr/bin/env python3
# this code is to get the CRC8 from a series of bytes we give
import crc8
# global variable
hash
# byte we want to calculate the CRC on to
@ariutti
ariutti / prettyPrint_incoming_bytes.py
Created March 16, 2020 13:23
A little python script to format incoming bytes from other programs in a more human readable fashion
#!/usr/bin/env python3
#useful link: https://stackoverflow.com/questions/55596557/os-read0-vs-sys-stdin-buffer-read-in-python
# use the program piping it some other byte-outputting software.
# Es.
# mosquitto_sub -h 192.168.1.4 -t \# | ./prettyPrint_incoming_bytes.py
import os
HOWMANYBYTES = 32
@ariutti
ariutti / time.py
Created March 10, 2020 16:23
A snippet to get seconds since epoch / seconds/ minutes / hours in the day
#!/usr/bin/env python3
import time
while 1:
secondsSinceEpoch = int( time.time() )
# how many seconds in a day? 24 * 60 * 60
secondsSinceDayStart = secondsSinceEpoch % 86400
#calculate seconds in a minute
@ariutti
ariutti / Nested_Routine_test.scd
Created February 10, 2020 17:23
a test on routines
// Do a rountine will continue having effetcs
// on the future if we stop it?
// Here we define a routine which will be launched by the main one
// It will wait 5 secs before playing a tone
(
~r2 = Routine({
var delay = 0.125;
var initialTime, elapsedTime;
@ariutti
ariutti / basic_granulator.scd
Last active December 30, 2022 02:24
A basic granular synthetizer in Supercollider ready to be controlled by MIDI CCs
// load stone samples ///////////////////////////////////////////////////////////////////
~sample = Buffer.read(s, "/home/nicola/Musica/sfx/CC0/stone_on_stone_dragging/_exports/dragged_stone_02.wav");
// test
{PlayBuf.ar(1, ~sample, doneAction:2)}.play;
(
// GRAIN PLAYER
// a synth to play buffers in a granular fashion
SynthDef(\texture_generator, {
@ariutti
ariutti / BufRd_and_Phasor.scd
Last active August 19, 2018 11:27
read a file w/ BufRd an Phasor
b = Buffer.read(s, "path/to/your/file.wav");
// even if you explicitly set the BufRd loop argument to 0
// The sound will loop anyway because of the fact Phasor is a periodic function
(
SynthDef(\test, {
|buf, trig=1, rate=1|
var sig, ph;
ph = Phasor.ar(trig, rate*BufRateScale.ir(buf), 0, BufFrames.ir(buf));
sig = BufRd.ar(2, buf, ph, interpolation:2);
@ariutti
ariutti / twos_complement.py
Created August 2, 2018 09:07
Two's complement and inverse in Python
# a test to convert binary numbers
# In order to obtain the two complement (TC) of a number N:
# 1. You must first negate all bits (255 - N);
# 2. You must then add one to the obtained number
# This is the formula
# TC = 255 - N + 1
# So in order to obtain back the number N
# having the TC number we shuold invert that formula.
@ariutti
ariutti / farfisa.scd
Created June 10, 2018 08:53
Farfisa organ like sound
// Trying to procedurally synthetise a violin,
// I eventually came out with the "Farfisa organ like sound
(
SynthDef(\violin, {
| midinote = 60 |
var sig = VarSaw.ar(
midinote.midicps,
width:LFNoise2.kr(1).range(0.2, 0.8)*SinOsc.kr(5, Rand(0.0, 1.0)).range(0.7,0.8))*0.25;
Out.ar(0, sig);
@ariutti
ariutti / abs-oscilloscope.pd
Created April 21, 2018 15:49
an oscilloscope to be use to test signal inside PD
#N canvas 171 94 395 130 10;
#X obj 219 69 metro 125;
#X obj 169 93 tabwrite~ \$0-A;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-A 2051 float 2;
#X coords 0 1 2050 -1 140 100 2 0 0;
#X restore 10 10 graph;
#X obj 219 48 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X obj 169 10 inlet~;
@ariutti
ariutti / simple_delays.scd
Last active April 21, 2018 15:09
Delay experiments
// This synth def is not so efficient due to the fact
// we are creating 3 different delay line instead of making
// three different read from a single one (as can be done
// with [delwrite~] and [delread~] objects in PD).
(
SynthDef(\test, {
var sig, dly1, dly2, dly3;
sig = SinOsc.ar(LFTri.kr(0.25,mul:1000, add:2000)) * 0.1;
dly1 = DelayN.ar(sig, 3, 0.3) * 0.5;
dly2 = DelayN.ar(sig, 3, 0.6) * 0.25;