Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hackEns
TouchlessTracking
Commits
8fd18513
Commit
8fd18513
authored
Oct 29, 2013
by
Phyks
Browse files
chorizo.py : simple note generator
parent
d5019900
Changes
3
Hide whitespace changes
Inline
Side-by-side
3d_view.py
View file @
8fd18513
#!/usr/bin/env python
#!/usr/bin/env python3
# TODO
import
pyglet
import
pyglet.gl
as
gl
...
...
chorizo.py
View file @
8fd18513
#!/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.
# 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
# =============================================================================
# TODO
import
wave
import
math
import
pyaudio
import
sys
NomFichier
=
"temp"
Monson
=
wave
.
open
(
NomFichier
,
'w'
)
channels
=
1
# Mono
sample_size
=
1
# Size of a sample -> 8 bits
sampling_freq
=
44100
# Sampling frequency
freq
=
440
# Note frequency
length
=
5
# Length of the note in seconds
level
=
150
# Between 0 (max < 0) and 255 (max > 0), 0 is 127
sample_number
=
int
(
length
*
sampling_freq
)
parameters
=
(
channels
,
sample_size
,
sampling_freq
,
sample_number
,
'NONE'
,
'not compressed'
)
Monson
.
setparams
(
parameters
)
# File header
for
i
in
range
(
0
,
sample_number
):
value
=
int
(
128.0
+
level
*
math
.
sin
(
2.0
*
math
.
pi
*
freq
*
i
/
sampling_freq
))
wave
.
struct
.
pack
(
'h'
,
value
)
# Params
# ======
nChannels
=
1
# Mono
sample_size
=
2
# Size of a sample -> 1 = 8 bits
framerate
=
44100
# Sampling frequency
length
=
2
# Length in seconds
frequency
=
440
level
=
1
# =====
Monson
.
close
()
if
level
<
0.0
or
level
>
1.0
:
sys
.
exit
(
1
)
wf
=
open
(
NomFichier
,
'rb'
)
filename
=
"temp"
w
=
wave
.
open
(
filename
,
'w'
)
p
=
pyaudio
.
PyAudio
()
# Computed params
nFrames
=
int
(
length
*
framerate
)
max_amplitude
=
int
(
2
**
(
sample_size
*
8
-
1
)
-
1
)
amplitude
=
max_amplitude
*
level
stream
=
p
.
open
(
format
=
p
.
get_format_from_width
(
wf
.
getsampwidth
()),
channels
=
wf
.
getnchannels
(),
rate
=
wf
.
getframerate
(),
output
=
True
)
w
.
setparams
((
nChannels
,
sample_size
,
framerate
,
nFrames
,
'NONE'
,
'not compressed'
))
data
=
wf
.
readframes
(
CHUNK
)
sine_wave
=
[]
for
i
in
range
(
min
(
framerate
,
nFrames
)):
sine_wave
.
append
(
int
(
max_amplitude
+
amplitude
*
math
.
sin
(
2
*
math
.
pi
*
frequency
*
i
/
framerate
)))
while
data
!=
''
:
stream
.
write
(
data
)
data
=
wf
.
readframes
(
CHUNK
)
for
i
in
range
(
nFrames
):
sine_wave
=
int
(
amplitude
*
math
.
sin
(
2
*
math
.
pi
*
frequency
*
i
/
framerate
))
data
=
wave
.
struct
.
pack
(
'h'
,
sine_wave
)
# ^ h is for "short" so each value can go from -2**15 to 2**15
w
.
writeframesraw
(
data
)
stream
.
stop_stream
()
stream
.
close
()
p
.
terminate
()
w
.
close
()
color.py
View file @
8fd18513
#!/bin/env python
#!/bin/env python
3
# ============================================================================
# This script maps the 3D position of your hand, as detected by the electrodes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment