Autosave: 2025-01-01 15:57:56

This commit is contained in:
thomasabishop 2025-01-01 15:57:56 +00:00
parent 42238b2810
commit 0bd10ab9db
814 changed files with 341 additions and 79 deletions

View file

@ -1,9 +0,0 @@
---
tags: []
created: Friday, December 27, 2024
---
# Binary_encoding_of_sound

View file

@ -1,25 +0,0 @@
---
tags: [databases, SQL, SQLite]
created: Wednesday, November 13, 2024
---
# SQLite
## Enabling foreign key constraints
Foreign key constraints are not enabled by default - it is very permissive. You
must manually turn them on, as part of the connection process:
```py
connection = sqlite3.connect("my_database.db")
connection.execute("PRAGMA foreign_keys = ON")
```
## INSERT OR IGNORE INTO
If table has a `UNIQUE` constraint on a field, insert if it is unique otherwise
skip without throwing a constraint error.
```sql
INSERT OR IGNORE INTO table_name (value) VALUES (:value)
```

View file

@ -5,44 +5,57 @@ created: Friday, December 27, 2024
# Audio file formats
## CD
## CD quality
- CDs store audio in uncompressed PCM (Pulse Code Modulation) format
- They have a sampling rate of 44.1kHz
- In two channels for stereo
We can use CD's as the digital gold standard as the best digital quality
available (to consumers).
## WAV: Waveform Audio File Format
CDs store audio in uncompressed PCM (Pulse Code Modulation) format.
They have a sampling rate of 44.1kHz, which is done in two channels to enable
stereo.
## What lossy formats entail
A conversion to MP3 from, for example, a CD source is always a one-way process
and is not reversible. Once information is discarded in the compression process,
it cannot be retrieved.
This is obviously in contrast to lossless methods like FLAC where the original
CD audio can always be reconstructed.
It follows from the above that if you repeatedly encode a CD source to MP3, it
will deteriorate in quality since more data is being removed each time.
## Major audio formats
### WAV (Waveform Audio File Format)
- CD-quality encoding with no compression
- Bit-for-bit identical to the CD source
- Historically developed for Windows machines but can play on all operating
systems
## FLAC: Free Lossless Audio Codec
### FLAC (Free Lossless Audio Codec)
- Basically the same as WAV but in a (losslessly) compressed format
- The difference between a novel in a text file (WAV) and as a zipped file
## MP3: MPEG-1 Audio Layer MP3
### MP3 (MPEG-1 Audio Layer MP3)
- Lossy format.
- When a WAV file (or other lossless format) is converted to MP3 a Fast Fourier
Transform analysis is performed to determine the frequency of certain sounds.
Transform analysis is performed to determine the frequency of certain sounds
- This is used by the encoder to decide which parts of the sound are
imperceptible and thus which can be discarded to reduce the file size. This is
done through the application of psycho-acoustic models.
- The remaining data is then compressed
- Examples of the data reduction applied:
- Removing frequencies that humans cannot hear
- Removing quieter sounds that are masked by louder sounds
- Combining similar frequencies
- Reducing stero information where it is less noticable
- A conversion to MP3 from, for example, a CD source is always a one-way process
and is not reversible. Once information is discarded in the compression
process it cannot be retrieved. This is obviously in contrast to lossless
methods like FLAC where the original CD audio can always be reconstructed.
- It follows from the above that if you repeatedly encode a CD source to MP3, it
will deteriorate in quality since more data is being removed each time.
## OGG: Ogg Vorbis

View file

@ -0,0 +1,50 @@
---
tags: [sound, binary, analogue]
created: Friday, December 27, 2024
---
# Binary encoding of sound
Sound is a change in air pressure.
To record sound, we convert the change in air pressure into an electrical signal
by means of a microphone. Effectively, the same natural waveform is converted
from one medium (the vibration of air molecules) into another medium (electrical
charge in a field) whilst retaining the same morphology. See
[Recording and processing sound]().
The resulting electrical signal is analogue: it has a continuous and variable
frequency and amplitude and thus can have any value at any given moment.
To encode this information digitally we need to make the continuous analogue
single discrete, so that it can represented with a finite set of symbols (bits).
This process is known as **quantization** and consists in sampling the analogue
waveform. This means taking a measurement of it at different points in time -
each second.
CDs sample the audio source at a rate of 44.1 kHz: 44, 100 measurements of the
signal per second.
The measurements are then stored in a digital format: bits. The amount of bits
used to record the measurement is the **bit-depth**. Each measurement is rounded
to the nearest available digital value. CDs have a depth of 16 bits. Thus each
measurement can be one of $16^2 = 65,536$ possible values.
With sampling at a given bit-depth established, the **bitrate** can be derived.
This is the sampling rate (number of measurements per second) divided by the
number of bits per sample (bit-depth), multiplied by the number of channels.
Thus for stereo CDs this is:
$$
(44100 / 16 ) \middot 2 = 1411200
$$
Or 1.4 Mb/s
> Even with a high bitrate (as with CDs) the process still necessarily involves
> a loss of information when converting sound from analogue to digital. However,
> given a high enough value for the sampling rate and bit-depth, the differences
> are imperceptible to the human ear.

View file

@ -0,0 +1,59 @@
---
tags: [databases, SQL, SQLite]
created: Wednesday, November 13, 2024
---
# SQLite
## Enabling foreign key constraints
Foreign key constraints are not enabled by default - it is very permissive. You
must manually turn them on, as part of the connection process:
```py
connection = sqlite3.connect("my_database.db")
connection.execute("PRAGMA foreign_keys = ON")
```
## INSERT OR IGNORE INTO
If table has a `UNIQUE` constraint on a field, insert if it is unique otherwise
skip without throwing a constraint error.
```sql
INSERT OR IGNORE INTO table_name (value) VALUES (:value)
```
## exec and fetchall
For `CREATE`, `INSERT`, `UPDATE`, `DELETE` operations it is sufficient to simply
use `execute` to carry out the operations:
```py
cursor = connection.cursor()
cursor.execute(sql)
```
For `SELECT` operations, you must add a return statement that uses `fetchall`:
```py
sql = "SELECT * FROM table"
cursor = connection.cursor()
cursor.execute(sql)
return cursor.fetchall()
```
## SELECT response data type
A `SELECT` operation returns a [list](Lists_in_Python.md) of
[tuples](Tuples_in_Python.md) where each entry in the tuple is a returned field.
For example:
```py
entries_sql = "SELECT title, size FROM entries"
entries_response = cursor.execute(entries_sql)
print(cursor.fetchall())
# [('Lorem ipsum', 127), ('Dolar sit', 4231)]
```

View file

@ -63,6 +63,35 @@ We could then use it thus:
def parse_articles() -> list[ArticleInfo]:
```
### Explicit type construction
Sometimes, simply asserting that custom type will be returned by a function is
not sufficient to pass the type checks. In these cases you need to explicitly
construct the type within the function.
For example this generates an error as Python sees the `tags` type as
`[Dictionary]`, even though it matches the type:
```python
class IGraphNode(TypedDict):
id: str
type: str
```
```py
tags = [{"id": f"#{tag[0]}", "type": "tag"} for tag in tags]
```
So you have to explicitly generate the type like this:
```python
tags = [IGraphNode(id=f"#{tag[0]}", type="tag") for tag in tags]
```
Then you will be able to type the return of the function as
`-> list[IGraphNode]`
## Optional types
`Optional` can be used to indicate that a variable can be `None` or the

View file

@ -1,5 +1,4 @@
---
id: mjia
tags: [python, JSON]
created: Tuesday, June 25, 2024
---
@ -20,8 +19,13 @@ Will error if the input string is not properly formatted JSON. This will be
Take a JSON-formatted dictionary and convert it into a string. The reverse of
`json.loads()` and equivalent to `JSON.stringify()` in JavaScript.
## JSON errors
## `json.dump()`
The `.loads()` and `.parse()` methods will throw an error if the input string is
Not to be confused with the above. Output a Python dictionary as JSON, for
instance to create a `.json` file:
## Related notes
```py
data = { "key": "value"}
with open("some/directory/output.json", "w") as f:
json.dump(data, f, indent=4)
```

View file

@ -0,0 +1,5 @@
This is your new *vault*.
Make a note of something, [[create a link]], or try [the Importer](https://help.obsidian.md/Plugins/Importer)!
When you're ready, delete this note and make the vault your own.

View file

@ -0,0 +1,5 @@
This is your new *vault*.
Make a note of something, [[create a link]], or try [the Importer](https://help.obsidian.md/Plugins/Importer)!
When you're ready, delete this note and make the vault your own.

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

@ -13,14 +13,17 @@ computer science.
![not-by-ai-badge](static/not-by-ai-alternative--light.svg)
**Build ID:** 3cd71ed3-2c64-460c-92b8-94889befa1fe
**Build ID:** 8f51653f-9574-4f79-81a8-1f2ecc0ba592
**Published:** Fri 27 Dec 2024 14:21:54
**Published:** Wed 01 Jan 2025 15:57:54
### Recent edits
- [[Audio_file_formats]]
- [[Binary_encoding_of_sound]]
- [[Audio_file_formats]]
- [[Type_hinting]]
- [[Working_with_JSON_in_Python]]
- [[SQLite]]
- [[a4601796_trapdoor_functions]]
- [[bbdcb54f_public_key_cryptography]]
- [[Dynamic_and_static_websites]]
@ -28,9 +31,6 @@ computer science.
- [[Architecture_of_the_World_Wide_Web]]
- [[Network_packet_analysis_tools]]
- [[What_can_the_ISP_see]]
- [[HTTPS]]
- [[Bauman_quote]]
- [[fbbfbc32-political-accommodation-inveigelment-surveillance-capitalism]]
### All notes (511)

View file

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View file

Before

Width:  |  Height:  |  Size: 145 KiB

After

Width:  |  Height:  |  Size: 145 KiB

View file

Before

Width:  |  Height:  |  Size: 289 KiB

After

Width:  |  Height:  |  Size: 289 KiB

View file

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

Before

Width:  |  Height:  |  Size: 6.9 MiB

After

Width:  |  Height:  |  Size: 6.9 MiB

View file

Before

Width:  |  Height:  |  Size: 224 KiB

After

Width:  |  Height:  |  Size: 224 KiB

View file

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View file

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View file

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 204 KiB

After

Width:  |  Height:  |  Size: 204 KiB

View file

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View file

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 91 KiB

View file

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 133 KiB

View file

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View file

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4 KiB

View file

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View file

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

View file

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 148 KiB

View file

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View file

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 121 KiB

View file

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View file

Before

Width:  |  Height:  |  Size: 470 KiB

After

Width:  |  Height:  |  Size: 470 KiB

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View file

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View file

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View file

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View file

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View file

Before

Width:  |  Height:  |  Size: 848 KiB

After

Width:  |  Height:  |  Size: 848 KiB

View file

Before

Width:  |  Height:  |  Size: 194 KiB

After

Width:  |  Height:  |  Size: 194 KiB

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 130 KiB

View file

Before

Width:  |  Height:  |  Size: 171 KiB

After

Width:  |  Height:  |  Size: 171 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

View file

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View file

Before

Width:  |  Height:  |  Size: 157 KiB

After

Width:  |  Height:  |  Size: 157 KiB

View file

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View file

Before

Width:  |  Height:  |  Size: 153 KiB

After

Width:  |  Height:  |  Size: 153 KiB

View file

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View file

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

View file

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 118 KiB

View file

Before

Width:  |  Height:  |  Size: 414 KiB

After

Width:  |  Height:  |  Size: 414 KiB

View file

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View file

Before

Width:  |  Height:  |  Size: 174 KiB

After

Width:  |  Height:  |  Size: 174 KiB

View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

Before

Width:  |  Height:  |  Size: 167 KiB

After

Width:  |  Height:  |  Size: 167 KiB

View file

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 150 KiB

View file

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View file

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 140 KiB

View file

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 190 KiB

View file

Before

Width:  |  Height:  |  Size: 374 KiB

After

Width:  |  Height:  |  Size: 374 KiB

View file

Before

Width:  |  Height:  |  Size: 9 KiB

After

Width:  |  Height:  |  Size: 9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View file

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

View file

Before

Width:  |  Height:  |  Size: 448 KiB

After

Width:  |  Height:  |  Size: 448 KiB

View file

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 122 KiB

View file

Before

Width:  |  Height:  |  Size: 668 KiB

After

Width:  |  Height:  |  Size: 668 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View file

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

View file

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View file

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View file

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View file

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View file

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View file

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View file

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View file

Before

Width:  |  Height:  |  Size: 146 KiB

After

Width:  |  Height:  |  Size: 146 KiB

View file

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View file

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 63 KiB

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View file

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

View file

@ -5,44 +5,57 @@ created: Friday, December 27, 2024
# Audio file formats
## CD
## CD quality
- CDs store audio in uncompressed PCM (Pulse Code Modulation) format
- They have a sampling rate of 44.1kHz
- In two channels for stereo
We can use CD's as the digital gold standard as the best digital quality
available (to consumers).
## WAV: Waveform Audio File Format
CDs store audio in uncompressed PCM (Pulse Code Modulation) format.
They have a sampling rate of 44.1kHz, which is done in two channels to enable
stereo.
## What lossy formats entail
A conversion to MP3 from, for example, a CD source is always a one-way process
and is not reversible. Once information is discarded in the compression process,
it cannot be retrieved.
This is obviously in contrast to lossless methods like FLAC where the original
CD audio can always be reconstructed.
It follows from the above that if you repeatedly encode a CD source to MP3, it
will deteriorate in quality since more data is being removed each time.
## Major audio formats
### WAV (Waveform Audio File Format)
- CD-quality encoding with no compression
- Bit-for-bit identical to the CD source
- Historically developed for Windows machines but can play on all operating
systems
## FLAC: Free Lossless Audio Codec
### FLAC (Free Lossless Audio Codec)
- Basically the same as WAV but in a (losslessly) compressed format
- The difference between a novel in a text file (WAV) and as a zipped file
## MP3: MPEG-1 Audio Layer MP3
### MP3 (MPEG-1 Audio Layer MP3)
- Lossy format.
- When a WAV file (or other lossless format) is converted to MP3 a Fast Fourier
Transform analysis is performed to determine the frequency of certain sounds.
Transform analysis is performed to determine the frequency of certain sounds
- This is used by the encoder to decide which parts of the sound are
imperceptible and thus which can be discarded to reduce the file size. This is
done through the application of psycho-acoustic models.
- The remaining data is then compressed
- Examples of the data reduction applied:
- Removing frequencies that humans cannot hear
- Removing quieter sounds that are masked by louder sounds
- Combining similar frequencies
- Reducing stero information where it is less noticable
- A conversion to MP3 from, for example, a CD source is always a one-way process
and is not reversible. Once information is discarded in the compression
process it cannot be retrieved. This is obviously in contrast to lossless
methods like FLAC where the original CD audio can always be reconstructed.
- It follows from the above that if you repeatedly encode a CD source to MP3, it
will deteriorate in quality since more data is being removed each time.
## OGG: Ogg Vorbis

View file

@ -1,9 +1,50 @@
---
tags: []
created: Friday, December 27, 2024
tags: [sound, binary, analogue]
created: Friday, December 27, 2024
---
# Binary_encoding_of_sound
# Binary encoding of sound
Sound is a change in air pressure.
To record sound, we convert the change in air pressure into an electrical signal
by means of a microphone. Effectively, the same natural waveform is converted
from one medium (the vibration of air molecules) into another medium (electrical
charge in a field) whilst retaining the same morphology. See
[Recording and processing sound]().
The resulting electrical signal is analogue: it has a continuous and variable
frequency and amplitude and thus can have any value at any given moment.
To encode this information digitally we need to make the continuous analogue
single discrete, so that it can represented with a finite set of symbols (bits).
This process is known as **quantization** and consists in sampling the analogue
waveform. This means taking a measurement of it at different points in time -
each second.
CDs sample the audio source at a rate of 44.1 kHz: 44, 100 measurements of the
signal per second.
The measurements are then stored in a digital format: bits. The amount of bits
used to record the measurement is the **bit-depth**. Each measurement is rounded
to the nearest available digital value. CDs have a depth of 16 bits. Thus each
measurement can be one of $16^2 = 65,536$ possible values.
With sampling at a given bit-depth established, the **bitrate** can be derived.
This is the sampling rate (number of measurements per second) divided by the
number of bits per sample (bit-depth), multiplied by the number of channels.
Thus for stereo CDs this is:
$$
(44100 / 16 ) \middot 2 = 1411200
$$
Or 1.4 Mb/s
> Even with a high bitrate (as with CDs) the process still necessarily involves
> a loss of information when converting sound from analogue to digital. However,
> given a high enough value for the sampling rate and bit-depth, the differences
> are imperceptible to the human ear.

View file

@ -23,3 +23,37 @@ skip without throwing a constraint error.
```sql
INSERT OR IGNORE INTO table_name (value) VALUES (:value)
```
## exec and fetchall
For `CREATE`, `INSERT`, `UPDATE`, `DELETE` operations it is sufficient to simply
use `execute` to carry out the operations:
```py
cursor = connection.cursor()
cursor.execute(sql)
```
For `SELECT` operations, you must add a return statement that uses `fetchall`:
```py
sql = "SELECT * FROM table"
cursor = connection.cursor()
cursor.execute(sql)
return cursor.fetchall()
```
## SELECT response data type
A `SELECT` operation returns a [list](Lists_in_Python.md) of
[tuples](Tuples_in_Python.md) where each entry in the tuple is a returned field.
For example:
```py
entries_sql = "SELECT title, size FROM entries"
entries_response = cursor.execute(entries_sql)
print(cursor.fetchall())
# [('Lorem ipsum', 127), ('Dolar sit', 4231)]
```

View file

@ -63,6 +63,35 @@ We could then use it thus:
def parse_articles() -> list[ArticleInfo]:
```
### Explicit type construction
Sometimes, simply asserting that custom type will be returned by a function is
not sufficient to pass the type checks. In these cases you need to explicitly
construct the type within the function.
For example this generates an error as Python sees the `tags` type as
`[Dictionary]`, even though it matches the type:
```python
class IGraphNode(TypedDict):
id: str
type: str
```
```py
tags = [{"id": f"#{tag[0]}", "type": "tag"} for tag in tags]
```
So you have to explicitly generate the type like this:
```python
tags = [IGraphNode(id=f"#{tag[0]}", type="tag") for tag in tags]
```
Then you will be able to type the return of the function as
`-> list[IGraphNode]`
## Optional types
`Optional` can be used to indicate that a variable can be `None` or the

View file

@ -1,5 +1,4 @@
---
id: mjia
tags: [python, JSON]
created: Tuesday, June 25, 2024
---
@ -20,8 +19,13 @@ Will error if the input string is not properly formatted JSON. This will be
Take a JSON-formatted dictionary and convert it into a string. The reverse of
`json.loads()` and equivalent to `JSON.stringify()` in JavaScript.
## JSON errors
## `json.dump()`
The `.loads()` and `.parse()` methods will throw an error if the input string is
Not to be confused with the above. Output a Python dictionary as JSON, for
instance to create a `.json` file:
## Related notes
```py
data = { "key": "value"}
with open("some/directory/output.json", "w") as f:
json.dump(data, f, indent=4)
```

5
zk/dfsdfdf/Welcome.md Normal file
View file

@ -0,0 +1,5 @@
This is your new *vault*.
Make a note of something, [[create a link]], or try [the Importer](https://help.obsidian.md/Plugins/Importer)!
When you're ready, delete this note and make the vault your own.

View file

@ -0,0 +1,5 @@
This is your new *vault*.
Make a note of something, [[create a link]], or try [the Importer](https://help.obsidian.md/Plugins/Importer)!
When you're ready, delete this note and make the vault your own.