Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
-
|
4 |
-
from
|
5 |
-
import simpleaudio as sa
|
6 |
import time
|
7 |
|
8 |
# Constants
|
@@ -17,6 +16,8 @@ BLUES_PROGRESSIONS = [
|
|
17 |
['I', 'IV', 'I', 'V', 'IV', 'IV', 'I', 'V', 'IV', 'IV', 'I', 'V'],
|
18 |
]
|
19 |
|
|
|
|
|
20 |
def note_to_freq(note):
|
21 |
octave = int(note[-1])
|
22 |
key_index = KEYS.index(note[:-1])
|
@@ -34,26 +35,22 @@ def get_chord_notes(root, chord_type):
|
|
34 |
intervals = [0, 4, 7]
|
35 |
return [KEYS[(root_index + interval) % len(KEYS)] for interval in intervals]
|
36 |
|
37 |
-
def create_tone(freq,
|
38 |
-
|
|
|
39 |
|
40 |
def play_arpeggio(root, chord_type, tempo):
|
41 |
chord_notes = get_chord_notes(root, chord_type)
|
42 |
-
|
43 |
|
44 |
-
arpeggio =
|
45 |
for note in chord_notes:
|
46 |
freq = note_to_freq(f"{note}4")
|
47 |
-
tone = create_tone(freq,
|
48 |
-
arpeggio =
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
num_channels=arpeggio.channels,
|
53 |
-
bytes_per_sample=arpeggio.sample_width,
|
54 |
-
sample_rate=arpeggio.frame_rate
|
55 |
-
)
|
56 |
-
play_obj.wait_done()
|
57 |
|
58 |
def main():
|
59 |
st.title("12-Bar Blues Arpeggio Game")
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
+
import sounddevice as sd
|
4 |
+
from scipy import signal
|
|
|
5 |
import time
|
6 |
|
7 |
# Constants
|
|
|
16 |
['I', 'IV', 'I', 'V', 'IV', 'IV', 'I', 'V', 'IV', 'IV', 'I', 'V'],
|
17 |
]
|
18 |
|
19 |
+
SAMPLE_RATE = 44100
|
20 |
+
|
21 |
def note_to_freq(note):
|
22 |
octave = int(note[-1])
|
23 |
key_index = KEYS.index(note[:-1])
|
|
|
35 |
intervals = [0, 4, 7]
|
36 |
return [KEYS[(root_index + interval) % len(KEYS)] for interval in intervals]
|
37 |
|
38 |
+
def create_tone(freq, duration):
|
39 |
+
t = np.linspace(0, duration, int(SAMPLE_RATE * duration), False)
|
40 |
+
return 0.3 * signal.chirp(t, freq, duration, freq, method='linear')
|
41 |
|
42 |
def play_arpeggio(root, chord_type, tempo):
|
43 |
chord_notes = get_chord_notes(root, chord_type)
|
44 |
+
duration = 60 / tempo / 4 # 16th notes
|
45 |
|
46 |
+
arpeggio = np.array([])
|
47 |
for note in chord_notes:
|
48 |
freq = note_to_freq(f"{note}4")
|
49 |
+
tone = create_tone(freq, duration)
|
50 |
+
arpeggio = np.concatenate((arpeggio, tone))
|
51 |
|
52 |
+
sd.play(arpeggio, SAMPLE_RATE)
|
53 |
+
sd.wait()
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
def main():
|
56 |
st.title("12-Bar Blues Arpeggio Game")
|