-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsound_generator.py
49 lines (41 loc) · 1.02 KB
/
sound_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import sys
import main
import math
import threading
from flask import Flask,request
loopThread = None
loop = False
app = Flask(__name__)
class SoundLoop(threading.Thread):
def __init__(self, frequency, pulse):
super(SoundLoop, self).__init__()
self._stop = threading.Event()
self.frequency = frequency
self.pulse = pulse
def run(self):
global loop
print(self.pulse)
while loop:
main.play_frequency(self.frequency, 2*math.pi, self.pulse)
@app.route('/sendPost', methods=["GET", "POST"])
def send_post():
frequency = float(request.args['frequency'])
duration = float(request.args['duration'])
pulse = request.args['altFreq']
global loopThread
global loop
if duration == 0:
loop = True
loopThread = SoundLoop(frequency, pulse == 'true')
loopThread.start()
else:
loop = False
main.play_frequency(frequency, duration, pulse == 'true')
return ""
if __name__ == '__main__':
try:
main.set_up_pygame()
app.run('steplica.student.rit.edu',port=5000, debug=True)
finally:
main.quit_pygame()