Skip to content

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

Merged
merged 4 commits into from
Oct 3, 2017

Conversation

kattni
Copy link
Contributor

@kattni kattni commented Oct 2, 2017

No description provided.

Copy link
Member

@tannewt tannewt left a 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)

Copy link
Member

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)

Copy link
Member

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()
"""
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.start_tone(frequency)

Copy link
Member

@tannewt tannewt left a 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! Super clean

@tannewt tannewt merged commit 9c7dc77 into adafruit:master Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants