Skip to content
Snippets Groups Projects
Commit 8ee0b002 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Move software sim stuff over to looper repo

parent 73744d33
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:6ad68c73-abea-4199-a610-f9c06edd405b tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
def draw(r, data):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
ax.plot(x, data)
pulse_delay = 100
pulse_duration = 100
total_duration = 2000
data = [0.0]*pulse_delay
data += [-1.0]*pulse_duration
data += [0.0]*pulse_delay
data += [1.0]*pulse_duration
data += [0.0]*(total_duration-pulse_delay-pulse_duration)
def process(data):
attack = pow(0.01, 1.0 / (20.1 * 48000 * 0.001))
decay = pow(0.01, 1.0 / (100.0 * 48000 * 0.001))
value = 0.0
output = []
for in_ in data:
abs_value = abs(in_)
if abs_value > value:
value = attack * (value - abs_value) + abs_value
else:
value = decay * (value - abs_value) + abs_value
output.append(value)
return output
env = process(data)
draw(env, data)
```
%% Output
%% Cell type:code id:50316437-021e-49b4-bda9-7663854444da tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
def draw(r):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
data = [(3.0 + math.log10(x/1000))/3.0 for x in range(1,1001)]
draw(data)
print(f'Min: {min(data)}')
print(f'Max: {max(data)}')
```
%% Output
Min: 0.0
Max: 1.0
%% Cell type:code id:d3bbb0dd-b8c3-4563-aec0-f39f1d0766b1 tags:
``` python
import math
import numpy as np
table = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
def lerp(a, b, f=0.5) -> float:
f = min(1.0, max(0.0, f))
if f == 0.0:
return a
elif f == 1.0:
return b
else:
return a * (1.0-f) + b * f
def get(table, f):
f = min(1.0, max(0.0, f))
pos = (len(table)-1) * f
pos_frac = pos%1.0
if pos_frac == 0.0:
val = table[int(round(pos))]
print(f"{f} direct access {int(pos)}: {val}")
return val
a = table[int(math.floor(pos))]
b = table[int(math.ceil(pos))]
val = lerp(a, b, pos_frac)
print(f"{f} interpolating [{a}] -> [{b}] with f {pos_frac}: {val}")
return val
for i in range(0, 33):
get(table, i/32.0)
```
%% Output
0.0 direct access 0: 0.0
0.03125 interpolating [0.0] -> [1.0] with f 0.125: 0.125
0.0625 interpolating [0.0] -> [1.0] with f 0.25: 0.25
0.09375 interpolating [0.0] -> [1.0] with f 0.375: 0.375
0.125 interpolating [0.0] -> [1.0] with f 0.5: 0.5
0.15625 interpolating [0.0] -> [1.0] with f 0.625: 0.625
0.1875 interpolating [0.0] -> [1.0] with f 0.75: 0.75
0.21875 interpolating [0.0] -> [1.0] with f 0.875: 0.875
0.25 direct access 1: 1.0
0.28125 interpolating [1.0] -> [2.0] with f 0.125: 1.125
0.3125 interpolating [1.0] -> [2.0] with f 0.25: 1.25
0.34375 interpolating [1.0] -> [2.0] with f 0.375: 1.375
0.375 interpolating [1.0] -> [2.0] with f 0.5: 1.5
0.40625 interpolating [1.0] -> [2.0] with f 0.625: 1.625
0.4375 interpolating [1.0] -> [2.0] with f 0.75: 1.75
0.46875 interpolating [1.0] -> [2.0] with f 0.875: 1.875
0.5 direct access 2: 2.0
0.53125 interpolating [2.0] -> [3.0] with f 0.125: 2.125
0.5625 interpolating [2.0] -> [3.0] with f 0.25: 2.25
0.59375 interpolating [2.0] -> [3.0] with f 0.375: 2.375
0.625 interpolating [2.0] -> [3.0] with f 0.5: 2.5
0.65625 interpolating [2.0] -> [3.0] with f 0.625: 2.625
0.6875 interpolating [2.0] -> [3.0] with f 0.75: 2.75
0.71875 interpolating [2.0] -> [3.0] with f 0.875: 2.875
0.75 direct access 3: 3.0
0.78125 interpolating [3.0] -> [4.0] with f 0.125: 3.125
0.8125 interpolating [3.0] -> [4.0] with f 0.25: 3.25
0.84375 interpolating [3.0] -> [4.0] with f 0.375: 3.375
0.875 interpolating [3.0] -> [4.0] with f 0.5: 3.5
0.90625 interpolating [3.0] -> [4.0] with f 0.625: 3.625
0.9375 interpolating [3.0] -> [4.0] with f 0.75: 3.75
0.96875 interpolating [3.0] -> [4.0] with f 0.875: 3.875
1.0 direct access 4: 4.0
%% Cell type:code id:cc0b4852-eccb-4bae-859a-bbbf92458ab2 tags:
``` python
from matplotlib import pyplot as plt
%matplotlib inline
import math
def draw(r):
l = len(r)
x = [x for x in range(l)]
fig = plt.figure(figsize=(8, 4))
ax = fig.add_axes([0, 0, 1, 1])
ax.axhline(y=0.5, color='black', linestyle='--')
ax.set_xticks(range(0, l, 64))
ax.set_yticks(range(-l*2, l*2+1, 128))
ax.grid()
ax.plot(x, r)
def deadband(x, deadband = 200):
span = 4096
half = span/2
half_span = half-deadband
scaler = half/half_span
if x < half:
x += deadband
x = (min(half, x)-half) * -scaler
x = int(x * -1) + half
else:
x -= deadband
x = (max(half, x)-half)*scaler
x = int(x)+half
return x
data = [deadband(x) for x in range(0,4096)]
draw(data)
print(f'Min: {min(data)}')
print(f'Max: {max(data)}')
```
%% Output
Min: 0.0
Max: 4094.0
%% Cell type:code id:2e2c2c7f-4bc6-4a1f-b6bd-bf5558b8f03f tags:
``` python
```
%% Output
<function __main__.draw(f)>
%% Cell type:code id:6112aebb-dc20-45e3-9ca6-280c76523469 tags:
``` python
```
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment