Skip to content

Commit ce6849b

Browse files
committed
Audio
1 parent e0c3860 commit ce6849b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,15 +1624,15 @@ wf.close()
16241624
import simpleaudio, math, struct
16251625
from itertools import chain, repeat
16261626
F = 44100
1627-
S1 = '71♪,69,,71♪,66,,62♪,66,,59♪,,,'
1628-
S2 = '71♪,73,,74♪,73,,74,,71,,73♪,71,,73,,69,,71♪,69,,71,,67,,71♪,,,'
1627+
P1 = '71♪,69,,71♪,66,,62♪,66,,59♪,,,'
1628+
P2 = '71♪,73,,74♪,73,,74,,71,,73♪,71,,73,,69,,71♪,69,,71,,67,,71♪,,,'
16291629
get_pause = lambda seconds: repeat(0, int(seconds * F))
16301630
sin_f = lambda i, hz: math.sin(i * 2 * math.pi * hz / F)
16311631
get_wave = lambda hz, seconds: (sin_f(i, hz) for i in range(int(seconds * F)))
16321632
get_hz = lambda n: 8.176 * 2 ** (int(n) / 12)
16331633
parse_n = lambda note: (get_hz(note[:2]), 0.25 if len(note) > 2 else 0.125)
16341634
get_note = lambda note: get_wave(*parse_n(note)) if note else get_pause(0.125)
1635-
samples_f = chain.from_iterable(get_note(n) for n in f'{S1}{S1}{S2}'.split(','))
1635+
samples_f = chain.from_iterable(get_note(n) for n in f'{P1}{P1}{P2}'.split(','))
16361636
samples_b = b''.join(struct.pack('<h', int(a * 30000)) for a in samples_f)
16371637
simpleaudio.play_buffer(samples_b, 1, 2, F)
16381638
```

0 commit comments

Comments
 (0)