Skip to content

Commit 925425c

Browse files
committed
Synthesizer
1 parent 8af4027 commit 925425c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,8 +2334,8 @@ get_pause = lambda seconds: repeat(0, int(seconds * F))
23342334
sin_f = lambda i, hz: math.sin(i * 2 * math.pi * hz / F)
23352335
get_wave = lambda hz, seconds: (sin_f(i, hz) for i in range(int(seconds * F)))
23362336
get_hz = lambda key: 8.176 * 2 ** (int(key) / 12)
2337-
parse_n = lambda note: (get_hz(note[:2]), 0.25 if '' in note else 0.125)
2338-
get_frames = lambda note: get_wave(*parse_n(note)) if note else get_pause(0.125)
2337+
parse_note = lambda note: (get_hz(note[:2]), 0.25 if '' in note else 0.125)
2338+
get_frames = lambda note: get_wave(*parse_note(note)) if note else get_pause(0.125)
23392339
frames_f = chain.from_iterable(get_frames(n) for n in f'{P1}{P1}{P2}'.split(','))
23402340
frames_b = b''.join(struct.pack('<h', int(f * 30000)) for f in frames_f)
23412341
simpleaudio.play_buffer(frames_b, 1, 2, F)

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,8 +1955,8 @@ <h3 id="synthesizer">Synthesizer</h3>
19551955
sin_f = <span class="hljs-keyword">lambda</span> i, hz: math.sin(i * <span class="hljs-number">2</span> * math.pi * hz / F)
19561956
get_wave = <span class="hljs-keyword">lambda</span> hz, seconds: (sin_f(i, hz) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(int(seconds * F)))
19571957
get_hz = <span class="hljs-keyword">lambda</span> key: <span class="hljs-number">8.176</span> * <span class="hljs-number">2</span> ** (int(key) / <span class="hljs-number">12</span>)
1958-
parse_n = <span class="hljs-keyword">lambda</span> note: (get_hz(note[:<span class="hljs-number">2</span>]), <span class="hljs-number">0.25</span> <span class="hljs-keyword">if</span> <span class="hljs-string">'♪'</span> <span class="hljs-keyword">in</span> note <span class="hljs-keyword">else</span> <span class="hljs-number">0.125</span>)
1959-
get_frames = <span class="hljs-keyword">lambda</span> note: get_wave(*parse_n(note)) <span class="hljs-keyword">if</span> note <span class="hljs-keyword">else</span> get_pause(<span class="hljs-number">0.125</span>)
1958+
parse_note = <span class="hljs-keyword">lambda</span> note: (get_hz(note[:<span class="hljs-number">2</span>]), <span class="hljs-number">0.25</span> <span class="hljs-keyword">if</span> <span class="hljs-string">'♪'</span> <span class="hljs-keyword">in</span> note <span class="hljs-keyword">else</span> <span class="hljs-number">0.125</span>)
1959+
get_frames = <span class="hljs-keyword">lambda</span> note: get_wave(*parse_note(note)) <span class="hljs-keyword">if</span> note <span class="hljs-keyword">else</span> get_pause(<span class="hljs-number">0.125</span>)
19601960
frames_f = chain.from_iterable(get_frames(n) <span class="hljs-keyword">for</span> n <span class="hljs-keyword">in</span> <span class="hljs-string">f'<span class="hljs-subst">{P1}</span><span class="hljs-subst">{P1}</span><span class="hljs-subst">{P2}</span>'</span>.split(<span class="hljs-string">','</span>))
19611961
frames_b = <span class="hljs-string">b''</span>.join(struct.pack(<span class="hljs-string">'&lt;h'</span>, int(f * <span class="hljs-number">30000</span>)) <span class="hljs-keyword">for</span> f <span class="hljs-keyword">in</span> frames_f)
19621962
simpleaudio.play_buffer(frames_b, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, F)

0 commit comments

Comments
 (0)