A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://todbot.github.io/CircuitPython_Synthio_Tutorial/4_oscillators_wavetables/wavetable.py below:

# 4_oscillators_waveforms/wavetable.py # simple wavetable class for synthio # part of todbot circuitpython synthio tutorial # 10 Feb 2025 - @todbot / Tod Kurt # import ulab.numpy as np import synthio import adafruit_wave class Wavetable: """ A 'waveform' for synthio.Note uses a WAV containing a wavetable and provides a scannable wave position.""" def __init__(self, filepath, wave_len=256): self.w = adafruit_wave.open(filepath) self.wave_len = wave_len # how many samples in each wave if self.w.getsampwidth() != 2 or self.w.getnchannels() != 1: raise ValueError("unsupported WAV format") # empty buffer we'll copy into self.waveform = np.zeros(wave_len, dtype=np.int16) self.num_waves = self.w.getnframes() // self.wave_len self.num_samples = self.w.getnframes() self.sample_rate = self.w.getframerate() self.wave_pos = 0 @property def wave_pos(self): return self._wave_pos @wave_pos.setter def wave_pos(self, pos): """Pick where in wavetable to be, morphing between waves""" pos = min(max(pos, 0), self.num_waves-1) # constrain samp_pos = int(pos) * self.wave_len # get sample position self.w.setpos(samp_pos) waveA = np.frombuffer(self.w.readframes(self.wave_len), dtype=np.int16) self.w.setpos(samp_pos + self.wave_len) # one wave up waveB = np.frombuffer(self.w.readframes(self.wave_len), dtype=np.int16) pos_frac = pos - int(pos) # fractional position between wave A & B # mix waveforms A & B self.waveform[:] = Wavetable.lerp(waveA, waveB, pos_frac) self._wave_pos = pos # mix between values a and b, works with numpy arrays too, t ranges 0-1 def lerp(a, b, t): return (1-t)*a + t*b

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4