def __init__(self, pitch, pitch_per_second=12, decibels=1, decibels_per_second=1, samplerate=utilities.DEFAULT_SAMPLE_RATE): self.frequency = utilities.pitch_to_frequency(pitch) self.phase = 0 self.amplitude = utilities.decibels_to_amplitude_ratio(decibels) self.pitch_per_second = pitch_per_second self.decibels_per_second = decibels_per_second self.goal_frequency = self.frequency self.goal_amplitude = self.amplitude self.samplerate = samplerate
def set_pitch(self, pitch): '''Set the goal pitch that the sinewave will gradually shift towards.''' self.goal_frequency = utilities.pitch_to_frequency(pitch)
def test_pitch_to_frequency(): # 0 is middle C assert utilities.pitch_to_frequency(0) == utilities.MIDDLE_C_FREQUENCY # 9 is middle A (440) assert math.isclose(utilities.pitch_to_frequency(9), 440, rel_tol=0.1)