Skip to content

Instantly share code, notes, and snippets.

@pocc
Last active April 7, 2019 21:25
Show Gist options
  • Save pocc/eafb6768eb50aba5f87798d49f4389fa to your computer and use it in GitHub Desktop.
Save pocc/eafb6768eb50aba5f87798d49f4389fa to your computer and use it in GitHub Desktop.
Play a full octave using pysine
# Play all notes between 440-880hz, inclusive
from pysine import sine
def get_freq(key):
# For a given piano key, return the frequency
# Taken from https://en.wikipedia.org/wiki/Piano_key_frequencies
return 2**((key-49)/12) * 440
for key in range(49, 62):
freq = get_freq(key)
print("Playing at", round(freq), "Hz")
sine(frequency=freq, duration=0.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment