For more information about the examples, such as how the Python and Mojo files interact with each other, see the Examples Overview
BuchlaWaveFolder¶
this example shows how to use the variable wavetable oscillator. it shows how the oscillator can be made using linear, quadratic, or sinc interpolation and can also be set to use oversampling. with sinc interpolation, use an oversampling index of 0 (no oversampling), 1 (2x). with linear or quadratic interpolation, use an oversampling index of 0 (no oversampling), 1 (2x), 2 (4x), 3 (8x), or 4 (16x).
Python Code¶
from mmm_src.MMMAudio import MMMAudio
# instantiate and load the graph
mmm_audio = MMMAudio(128, graph_name="BuchlaWaveFolder", package_name="examples")
mmm_audio.start_audio()
mmm_audio.stop_audio()
mmm_audio.plot(4000)
xq
Mojo Code¶
from mmm_src.MMMWorld import MMMWorld
from mmm_utils.functions import *
from mmm_src.MMMTraits import *
from mmm_dsp.Osc import Osc
from mmm_dsp.Filters import Lag
from mmm_utils.Messenger import Messenger
from mmm_dsp.Env import ASREnv
from mmm_dsp.Distortion import buchla_wavefolder
struct BuchlaWaveFolder(Representable, Movable, Copyable):
var world: UnsafePointer[MMMWorld]
var osc: Osc[2]
var lag: Lag
var m: Messenger
fn __init__(out self, world: UnsafePointer[MMMWorld]):
self.world = world
# for efficiency we set the interpolation and oversampling in the constructor
self.osc = Osc[2](self.world)
self.lag = Lag(self.world, 0.1)
self.m = Messenger(self.world)
fn __repr__(self) -> String:
return String("Default")
fn next(mut self) -> SIMD[DType.float64, 2]:
amp = self.lag.next(self.world[].mouse_x * 39.0) + 1
sample = self.osc.next_interp(40)
sample = buchla_wavefolder(sample, amp)
return sample