-
Notifications
You must be signed in to change notification settings - Fork 68
Render Engine and BPM
David Braun edited this page Jun 30, 2022
·
1 revision
import dawdreamer as daw
SAMPLE_RATE = 44100
BUFFER_SIZE = 128 # Parameters will undergo automation at this buffer/block size.
def make_sine(freq: float, duration: float, sr=SAMPLE_RATE):
"""Return sine wave based on freq in Hz and duration in seconds"""
N = int(duration * sr) # Number of samples
return np.sin(np.pi*2.*freq*np.arange(N)/sr)
# Make an engine. We typically only need one.
engine = daw.RenderEngine(SAMPLE_RATE, BUFFER_SIZE)
# By the default, the BPM is 120, but we can change it.
engine.set_bpm(130.)
# The BPM can also be set as a numpy array that is interpreted
# with a fixed PPQN (Pulses Per Quarter Note).
# If we choose ppqn=960 and the numpy array abruptly changes values every 960 samples,
# the tempo will abruptly change "on the beat".
bpm_automation = make_sine(1./2., DURATION, sr=PPQN)
bpm_automation = 120.+30*(bpm_automation > 0).astype(np.float32)
engine.set_bpm(bpm_automation, ppqn=PPQN)