Skip to content

Instantly share code, notes, and snippets.

View pranavrc's full-sized avatar

Pranav Ravichandran pranavrc

View GitHub Profile
@pranavrc
pranavrc / sound.py
Created January 16, 2012 06:23
Function that generates sound of parameter frequency
from struct import pack
from math import sin, pi
import time
from populate import _listen_
def _play_(name, freq, dur, vol, mode='ab'):
""" Generate sound with frequency freq, duration dur, and volume vol """
_dump_ = open(name, mode)
_dump_.write('.snd' + pack('>5L', 24, 8*dur, 2, 8000, 1))
_factor_ = 2 * pi * freq/8000
@pranavrc
pranavrc / sound.py
Created January 16, 2012 06:25
Generating sound and appending it to a .au file
import populate
import sound
import random
populate._listen_(27.5, 5000, 1.059463094, 21)
_beats_ = 4
_intervalLength_ = random.choice(range(1,5))*1000
_interval_ = 0
_noteLength_ = random.choice([500,1000,2000,3000,4000,5000])
_barLength_ = _beats_ * (_intervalLength_ + _noteLength_)
@pranavrc
pranavrc / scalestodos.txt
Created January 16, 2012 16:50
TODOs for Scales
TODOs:
Incorporate Karplus-Strong for plucked-string sound.
Try different algorithms.
Reduce randomizations.
Make it choose between different styles (rock, pop, reggae, swing etc), based on different time signatures.
Add a database of scales and corresponding notes.
Think of more TODOs.
@pranavrc
pranavrc / populate.py
Created January 16, 2012 06:26
Assigning frequency values to note symbols
_freq_={}
_midi_={}
def _listen_(_firstNoteInRange_, _lastNoteInRange_, _noteInterval_, _midiCounter_):
""" Fills dictionaries with note symbols and corresponding frequency values """
notes = ['A0', 'A#0', 'B0', 'C1', 'C#1', 'D1', 'D#1', 'E1', 'F1', 'F#1', 'G1', 'G#1', 'A1', 'A#1', 'B1', 'C2', 'C#2', 'D2', 'D#2', 'E2', 'F2', 'F#2', 'G2', 'G#2', 'A2', 'A#2', 'B2', 'C3', 'C#3', 'D3', 'D#3', 'E3', 'F3', 'F#3', 'G3', 'G#3', 'A3', 'A#3', 'B3', 'C4', 'C#4', 'D4', 'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4', 'A4', 'A#4', 'B4', 'C5', 'C#5', 'D5', 'D#5', 'E5', 'F5', 'F#5', 'G5', 'G#5', 'A5', 'A#5', 'B5', 'C6', 'C#6', 'D6', 'D#6', 'E6', 'F6', 'F#6', 'G6', 'G#6', 'A6', 'A#6', 'B6', 'C7', 'C#7', 'D7', 'D#7', 'E7', 'F7', 'F#7', 'G7', 'G#7', 'A7', 'A#7', 'B7', 'C8', 'C#8', 'D8', 'D#8']
_bwdf_ = 0
while _firstNoteInRange_ <= _lastNoteInRange_:
_freq_[notes[_bwdf_]] = _firstNoteInRange_
@pranavrc
pranavrc / QuickHist_from_bash.md
Last active December 16, 2015 23:49
Example bash script using the QuickHist API.

QuickHist API from the terminal