-
Notifications
You must be signed in to change notification settings - Fork 71
start_tone / stop_tone implemented. #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good. The changes I suggest are so that the sine buffer isn't generated until its needed.
shift = 2 ** 15 | ||
for i in range(length): | ||
yield int(TONE_VOLUME * math.sin(2*math.pi*(i / length)) + shift) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _generate_sample(self):
if self.sample != None:
return
length = 100
sine_wave = array.array("H", sine_sample(length))
self.sample = audioio.AudioOut(board.SPEAKER, sine_wave)
for i in range(length): | ||
sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15) | ||
|
||
sample = audioio.AudioOut(board.SPEAKER, sine_wave) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.generate_sample()
circuit.start_tone(294) | ||
else: | ||
circuit.stop_tone() | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._generate_sample()
# Play a tone of the specified frequency (hz). | ||
self.sample.frequency = int(len(self.sine_wave) * frequency) | ||
if not self.sample.playing: | ||
self.sample.play(loop=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.start_tone(frequency)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good! Thank you!
# Play a tone of the specified frequency (hz). | ||
self.start_tone(frequency) | ||
time.sleep(duration) | ||
self.stop_tone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! Super clean
No description provided.