Envelope Generator

We simulate an envelope generator
eg
envelope
mki-x-esEDU
module
diode
Published

June 16, 2023

1 Intro

Figure 1: VCF Eurorack module (left) and VCV Model (right)

In this post we’ll be continuing to reproduce the designs of the mki x es.edu eurorack EG. The detailed build instructions (source: https://www.ericasynths.lv/shop/diy-kits-1/edu-diy-eg/) contain lots of great information and it’s recommended to read that document first.

%load_ext autoreload
%autoreload 2

import os
import sys

module_path = os.path.abspath(os.path.join("../../.."))

if module_path not in sys.path:
    sys.path.append(module_path)
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
from pathlib import Path

import matplotlib.pylab as plt
import numpy as np
from sympy import *
from sympy.codegen.ast import Assignment

from spiceworld.mki_eg import (
    _code_to_hpp_and_recompile_eg_module,
    generate_envelope_active_ar,
    generate_envelope_passive_ar,
    generate_example_data,
)
from spiceworld.solve_MNA import generate_processor, run_MNA
from spiceworld.utilities import ModuleLoader, format_and_compile_as_module
_ = generate_envelope_passive_ar(plot=True)

_ = generate_envelope_active_ar(plot=True)

def test_spike():
    netlist = """
        V0 1 0 Vin
        C1 1 2 1e-7        
        R1 2 0 10000        
        D1 3 2 Rs=10
        J 3 0
    """

    class_name = "Spike3" + str(np.random.randint(1, 100000))
    rules, (A, x, b) = run_MNA(netlist, class_name, method="LUsolve", simplify_sol=True)

    code_string = generate_processor(rules)

    with ModuleLoader(code_string, class_name) as m:
        tmax, dt = 0.2, 1.0 / 44100.0
        ts = np.arange(0, tmax, dt)
        ins, outs = [], []
        for t in ts:
            vin = 5 * (0.05 < t < 0.1)
            out = m.process(vin, dt)
            ins.append(vin)
            outs.append(out)

        plt.figure(figsize=(12, 5))
        plt.plot(ts, ins)
        plt.plot(ts, outs)
        plt.show()


test_spike()