Created
November 22, 2024 15:59
-
-
Save interstar/5293c2eead2a737ce188908cf8edf759 to your computer and use it in GitHub Desktop.
Bytebeats in Edison 3.0 (much faster than previously because we're eval-ing a lambda)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enveditor import * | |
""" | |
Create bytebeats in Edison. | |
""" | |
def makeSample(length, srate, norm, formula): | |
# Sample rate selection | |
if srate == 0: | |
EditorSample.SampleRate = 8000 | |
elif srate == 1: | |
EditorSample.SampleRate = 11025 | |
elif srate == 2: | |
EditorSample.SampleRate = 22050 | |
else: | |
EditorSample.SampleRate = 44100 | |
# Setting sample length | |
if EditorSample.Length <= 0: | |
EditorSample.Length = round(EditorSample.MSToSamples(length * 1000)) | |
try : | |
formula_func = "lambda t : %s" % formula | |
formula_func = eval(formula_func) | |
x1 = Editor.SelectionStartS | |
x2 = Editor.SelectionEndS | |
# Byte-beat generation | |
for n in range(x1, x2 + 1): | |
for c in range(EditorSample.NumChans): | |
s = formula_func(n) | |
EditorSample.SetSampleAt(n, c, s) | |
# Normalization | |
if norm == 0: | |
EditorSample.NormalizeFromTo(x1, x2, 0.8) | |
except Exception as e : | |
Utils.ShowMessage("Exception\n%s \n%s" % (formula_func,e)) | |
# User Interface | |
form = ScriptDialog('ByteBeats', 'Generate Your ByteBeats Right Now!!!') | |
form.AddInputKnob('Length (s)', 1, 0, 100) | |
form.AddInputCombo('Sample Rate', '8000,11025,22050,44100', 3) | |
form.AddInputCombo('Normalize?', 'Yes,No', 1) | |
form.AddInputText('Formula', "(128 & t * (4 | 7 & t >> 13) >> (1 & -t >> 11)) + (127 & t * (t >> 11 & t >> 13) * (3 & -t >> 9)) % 255") | |
if form.Execute(): | |
makeSample(form.GetInputValue('Length (s)'), form.GetInputValue('Sample Rate'), form.GetInputValue('Normalize?'),form.GetInputValue('Formula')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment