#!/usr/bin/env python3 # # sinegen3.py # Released under the GPLv3 license. # # Initial release: August 4, 2009, G. Forrest Cook # revision: Feb 24, 2022, cleaned up and verified for Python 3 # revision: Feb 21, 2024, removed obsolete pylab import, now use plt. and np. # # Generate and display exponentially weighted sine wave patterns for # a Vibrato/Tremolo LFO circuit. # The waveform is scaled to a range of 0-255 to support an # 8 bit digital to analog converter (DAC). # # This requires the Ubuntu Matplotlib package (python3-matplotlib) # Note that the commented lines were used to produce differently weighted # sine waves using a slightly different method, the final values chosen worked # best with the Lil' Tiger amp's pitch-shifting vibrato circuit, see: # http://www.solorb.com/elect/musiccirc/ArduinoLFO2/ # import matplotlib.pyplot as plt import numpy as np val = 0.0 count = 0 # minval and maxval start with out of range values. minval = 255 maxval = 0 wavetable = [] # Bottom Heavy "Big Bottom" wave for ind in range(0, 256): val = (75 * pow(2.1, (1.0 - np.cos(2*np.pi*ind/256.0)))) - 75 # Calculate maxval and minval values. if val > maxval: maxval = val if val < minval: minval = val wavetable.append(val) # print either right-side-up or inverted wave data: print("%d, " % val, end=""), # print("%d, " % (255.9-val), end=""), count = count+1 print("\nMin:%d, Max:%d, count:%d" % (minval, maxval, count)) #print(wavetable) # array of floats plt.grid(True) plt.plot(wavetable) plt.show() quit() # # v2 = 0.0 # v3 = 0.0 # # for ind in range (steps): # v1 = (370 * pow (1.3, (1.0 - cos(2*pi*ind/256.0)))) - 370 # v1 = (204 * pow (1.5, (1.0 - cos(2*pi*ind/256.0)))) - 204 # v1 = (135 * pow (1.7, (1.0 - cos(2*pi*ind/256.0)))) - 135 # v1 = (40 * exp ((1.0 - cos(2*pi*ind/256.0)))) -40 # # v1 = 127.9 * (1.0 - cos(2*pi*ind/256.0)) # v1 = 84 * (1.0 - cos(2*pi*ind/256.0)) # v2 = 43 * (1.0 - cos(2*pi*ind/768.0)) # # v1 = 71.5 * (1.0 - cos(2*pi*ind/256.0)) # v2 = 39 * (1.0 - cos(2*pi*ind/768.0)) # v3 = 17 * (1.0 - cos(2*pi*ind/1280.0)) # # Top Heavy inverted wave # val = 255 - v1