Started code for Noel2013

This commit is contained in:
hackEns 2013-12-12 12:37:40 +01:00
parent 272c51d9a8
commit c59cbd10e7
2 changed files with 109 additions and 0 deletions

98
Noel2013/noel.py Executable file
View File

@ -0,0 +1,98 @@
#!/usr/bin/env python3
# ============================================================================
# This script allows you to play music using a chorizo (or whatever food you
# like) keyboard ! See README for more info and links.
# Specially designed for our demo for Christmas 2013. Designed to fully handle
# 5 notes and play jingle bells.
# As all the other scripts in this repository, I release it under a very
# permissive license. To make a long story short : do whatever you want with
# this script (but try to have fun :), I don't mind. It would be cool to quote
# the origin of the script if you reuse it, but you don't have to. I'd like to
# be noticed of what you did cool with it (if you think it's worth). :)
# Ah, I almost forgot : If by chance we ever meet and you think this script is
# worth, you can buy me a soda :)
#
# Phyks
# =============================================================================
from sound4python import sound
from multiprocessing import Process
import math
class _Getch:
"""Gets a single character from standard input. Does not echo to the
screen."""
def __call__(self):
import sys
import tty
import termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
getch = _Getch()
def play_wave(frequency=440, nb_secs=1.):
sine_wave = []
for i in range(math.ceil(nb_secs*framerate)+1):
sine_wave.append(int(16384*math.sin(2*math.pi*frequency*i/framerate)))
sound(sine_wave)
framerate = 16000
processes = []
frequency = 440
# Handle serial opening
# *** TODO ***
# Handle calibration
# *** TODO ***
# Main loop
# *** TODO *** : Add fetch from the serial also
print("Running... Press q to quit.")
running = True
while running:
char = getch()
if char == "q":
print("Exiting...")
running = False
continue
elif char == "a":
frequency = 440
elif char == "b":
frequency = 493.88
elif char == "c":
frequency = 523.25
elif char == "d":
frequency = 587.33
elif char == "e":
frequency = 659.26
elif char == "f":
frequency = 698.46
elif char == "g":
frequency = 783.99
else:
continue
print("Playing "+char.upper())
processes.append(Process(target=play_wave,
args=(frequency,
math.floor(0.2 * frequency + 1) / frequency)))
processes[-1].start()
for i in processes:
i.join()

View File

@ -35,6 +35,17 @@ __(working on)__
A script to play music using chorizo pads as a musical keyboard. See [our website](http://hackens.org/Projets/TouchlessTracking) (french, but vids are available, more coming soon) for infos and demos. A script to play music using chorizo pads as a musical keyboard. See [our website](http://hackens.org/Projets/TouchlessTracking) (french, but vids are available, more coming soon) for infos and demos.
Launch `test_player.py` and use your keyboard to play music for now (A, B, C, D, E, F and G keys).
# Noel2013
__(working on)__
Our code for a demo at Christmas party 2013. We wanted to play Jingle Bells using a chorizo player, 5 notes to fetch from the array and map to real sound.
Use the same basis as `test_player.py` so it is also usable with a keyboard for fallback if whatever bad happen :)
### 3d view ### 3d view
__(working on)__ __(working on)__