From dee1786b46bc5e0486b1d045c3893f6b3d215865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 16 Jan 2023 20:56:47 +0100 Subject: [PATCH] CSV, Synthesizer --- README.md | 8 ++++---- index.html | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 19a814a..b1ae931 100644 --- a/README.md +++ b/README.md @@ -1829,7 +1829,7 @@ import csv * **File must be opened with a `'newline=""'` argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!** ### Parameters -* **`'dialect'` - Master parameter that sets the default values. String or a Dialect object.** +* **`'dialect'` - Master parameter that sets the default values. String or a 'csv.Dialect' object.** * **`'delimiter'` - A one-character string used to separate fields.** * **`'quotechar'` - Character for quoting fields that contain special characters.** * **`'doublequote'` - Whether quotechars inside fields are/get doubled or escaped.** @@ -2943,7 +2943,7 @@ Synthesizer #### Plays Popcorn by Gershon Kingsley: ```python # $ pip3 install simpleaudio -import itertools as it, math, struct, simpleaudio +import array, itertools as it, math, simpleaudio F = 44100 P1 = '71♩,69♪,,71♩,66♪,,62♩,66♪,,59♩,,' @@ -2955,8 +2955,8 @@ get_hz = lambda key: 8.176 * 2 ** (int(key) / 12) parse_note = lambda note: (get_hz(note[:2]), 1/4 if '♩' in note else 1/8) get_samples = lambda note: get_wave(*parse_note(note)) if note else get_pause(1/8) samples_f = it.chain.from_iterable(get_samples(n) for n in f'{P1},{P1},{P2}'.split(',')) -samples_b = b''.join(struct.pack(''bc', 'newline=""' argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!

Parameters

    -
  • 'dialect' - Master parameter that sets the default values. String or a Dialect object.
  • +
  • 'dialect' - Master parameter that sets the default values. String or a 'csv.Dialect' object.
  • 'delimiter' - A one-character string used to separate fields.
  • 'quotechar' - Character for quoting fields that contain special characters.
  • 'doublequote' - Whether quotechars inside fields are/get doubled or escaped.
  • @@ -2401,7 +2401,7 @@ engine.runAndWait()

#Synthesizer

Plays Popcorn by Gershon Kingsley:

# $ pip3 install simpleaudio
-import itertools as it, math, struct, simpleaudio
+import array, itertools as it, math, simpleaudio
 
 F  = 44100
 P1 = '71♩,69♪,,71♩,66♪,,62♩,66♪,,59♩,,'
@@ -2413,8 +2413,8 @@ get_hz      = lambda key: lambda note: (get_hz(note[:2]), 1/4 if '♩' in note else 1/8)
 get_samples = lambda note: get_wave(*parse_note(note)) if note else get_pause(1/8)
 samples_f   = it.chain.from_iterable(get_samples(n) for n in f'{P1},{P1},{P2}'.split(','))
-samples_b   = b''.join(struct.pack('<h', int(f * 30000)) for f in samples_f)
-simpleaudio.play_buffer(samples_b, 1, 2, F)
+samples_i   = array.array('h', (int(f * 30000) for f in samples_f))
+simpleaudio.play_buffer(samples_i, 1, 2, F)