Hi!
I’m sonifying environmental data and have two objects that play notes and they should be playing in sync, but are drifting. I’m starting with a small test where they each play on every beat. The beatPlayer is basically a metronome. The child clocks should be synced, right? So why aren’t the beats lining up?
I call them here:
s.fork(beatPlayer.playBeats)
s.fork(kiloYearDataPlayer.playData)
And the classes are:
class BeatPlayer:
def __init__(self, beatLength, inst, pitch, nbeats, vol, playNthbeat = 1):
self.instrument = inst
self.beatLength = beatLength
self.nbeats = nbeats
self.vol = vol
self.playNthbeat = playNthbeat
self.pitch = pitch # static pitch, could modify this later
def playBeats(self):
pitchArray = np.full(self.nbeats, None)
pitchArray[::self.playNthbeat] = self.pitch
for thisBeat in range(self.nbeats):
self.instrument.play_note(pitchArray[thisBeat],self.vol, self.beatLength)
class DataPlayer:
def __init__(self, dur, inst, data, CO2max, CO2min, refScale, vol = 0.7, tieNotes = False):
self.instrument = inst
self.vol = vol
if tieNotes == True:
pitchlist = pitch_list(CO2min, CO2max, data, refScale)
[self.pitches, self.durs] = tieSamePitches(pitchlist, dur)
else:
self.pitches = pitch_list(CO2min, CO2max, data, refScale)
if type(dur) == np.ndarray:
self.durs = dur
else:
self.durs = len(data)*[dur]
def playData(self, vol):
for pitch, dur in zip(self.pitches, self.durs):
self.instrument.play_note(pitch, self.vol, dur)