Various fixes in 2013/endoh3: formatting, others

Add note about twitter no longer being used or endorsed by the IOCCC but
noting that despite this the award title should remain the same.

Unrot13 the spoiler as per the request of Landon months ago. Doing this
also allowed for proper syntax highlighting (via the feature of GitHub's
languages of code blocks) as rot13 of C/c is P/p.

Format fix README.md file.
This commit is contained in:
Cody Boone Ferguson committed 2023-10-15 03:09:50 -07:00
1 parent 18a6aecb53
commit ec2c1b577e
1 file changed
+83 -52
+83 -52
View File
@@ -32,13 +32,24 @@ There are also some other musical samples, twinkle.abc and menuet.abc.
## Judges' remarks: ## Judges' remarks:
This endoh3ram can tweet out a tune and is small enough to tweet. This program can toot out a tune that is small enough to posted to most social
media platforms that have small message length limits.
This endoh3ram can toot out a tune that is small enough.
### A modern day (2023) note about the award 'Most tweetable 1-liner' and twitter:
The IOCCC no longer endorses the use of what was once twitter, or whatever it
might be called today. We recommend that you pick a responsible social media
platform to post the program's output on. Nevertheless the award of this entry
will remain the same for historical purposes.
## Author's remarks: ## Author's remarks:
### Remarks ### Remarks
This is a sound synthesizer for a subset of [ABC music notation](http://en.wikipedia.org/wiki/ABC_notation). This is a sound synthesizer for a subset of [ABC music
notation](http://en.wikipedia.org/wiki/ABC_notation).
Try: Try:
@@ -54,14 +65,14 @@ as `padsp` or `aoss`:
echo "CDEFGABc" | ./endoh3 | padsp tee /dev/dsp > /dev/null echo "CDEFGABc" | ./endoh3 | padsp tee /dev/dsp > /dev/null
``` ```
If you are using Mac OS X, try [sox](http://sox.sourceforge.net/): If you are using Mac OS X, try [sox](http://sox.sourceforge.net/) like so:
```sh ```sh
echo "CDEFGABc" | ./endoh3 | sox -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio echo "CDEFGABc" | ./endoh3 | sox -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio
``` ```
If they do not work, use the attached script to convert the output If that does not work, use the attached script to convert the output into a wave
into a wave file format: file format:
```sh ```sh
echo "CDEFGABc" | ./endoh3 | ruby wavify.rb > cde.wav echo "CDEFGABc" | ./endoh3 | ruby wavify.rb > cde.wav
@@ -69,19 +80,28 @@ echo "CDEFGABc" | ./endoh3 | ruby wavify.rb > cde.wav
and play `cde.wav`. and play `cde.wav`.
You can enjoy some music scores that I attached:
You can also enjoy some music scores that I attached. With `/dev/dsp` you can
do so like:
```sh ```sh
cat twinkle.abc | ./endoh3 > /dev/dsp cat twinkle.abc | ./endoh3 > /dev/dsp
cat menuet.abc | ./endoh3 > /dev/dsp cat menuet.abc | ./endoh3 > /dev/dsp
``` ```
but you should be able to modify it a way to meet your system requirements as
described above.
### Obfuscation ### Obfuscation
The following sequence of questions may be helpful to understand the endoh3ram. The following sequence of questions may be helpful to understand the `endoh3ram`
program:
- How does it convert ABC notes into the frequency? - How does it convert ABC notes into the frequency?
- What is `89/84.`? I found it by using Stern-Brocot tree. - What is `89/84.`? I found it by using the [Stern-Brocot
tree](https://en.wikipedia.org/wiki/Stern-Brocot_tree).
- How does it generate a wave? Hint: it generates a saw wave. - How does it generate a wave? Hint: it generates a saw wave.
### Limitation ### Limitation
@@ -98,7 +118,7 @@ The following features are supported:
- `A3` (a dotted quarter note) - `A3` (a dotted quarter note)
- `A4` (a half note) - `A4` (a half note)
The following features are *not* supported: The following features are *NOT* supported:
- Sharp and flat: `^C` `_C` - Sharp and flat: `^C` `_C`
- But it is possible to emit the half tones. Do you see how? - But it is possible to emit the half tones. Do you see how?
@@ -110,10 +130,12 @@ The following features are *not* supported:
### Known Bugs ### Known Bugs
You can *not* write a note length immediately followed by a note `E`, You can *NOT* write a note length immediately followed by a note `E`,
such as `C2E2`. such as `C2E2`.
Can you know why?
You can work it around by inserting a whitespace: `C2 E2`. Can you figure out why?
A workaround is inserting a whitespace: `C2 E2`.
### Portability ### Portability
@@ -130,61 +152,70 @@ I did write a score of the Happy Birthday song too.
(It does not matter because the song is out-of-copyright in my country.) (It does not matter because the song is out-of-copyright in my country.)
But I do not attach it to protect you from W\*\*\*\*r. But I do not attach it to protect you from W\*\*\*\*r.
For the same reason, do not play a score that contains only `z1092`. For the same reason, do not post a score that contains only `z1092`.
You know, it is ["the famous song"](http://en.wikipedia.org/wiki/4%E2%80%B233%E2%80%B3). You know, it is ["the famous song"](http://en.wikipedia.org/wiki/4%E2%80%B233%E2%80%B3).
### Spoiler (rot13) ### Spoiler
Urer vf n zntvpny rkcerffvba juvpu V sbhaq ol oehgr-sbepr: Here is a magical expression which I found by brute-force:
```c ```c
(p % 32 + 5) * 9 / 5 % 13 + a / 32 * 12 - 22 (c % 32 + 5) * 9 / 5 % 13 + n / 32 * 12 - 22
``` ```
Vagrerfgvatyl, vg pbairegf na NFPVV ahzore bs NOP abgrf Interestingly, it converts an ASCII number of ABC notes
gb gur pbeerfcbaqvat gbar ahzore. to the corresponding tone number.
'P' (NFPVV 67) => 3 ```
'Q' (NFPVV 68) => 5 'C' (ASCII 67) => 3
'R' (NFPVV 69) => 7 'D' (ASCII 68) => 5
'S' (NFPVV 70) => 9 'E' (ASCII 69) => 7
'T' (NFPVV 71) => 10 'F' (ASCII 70) => 9
'N' (NFPVV 65) => 12 'G' (ASCII 71) => 10
'O' (NFPVV 66) => 14 'A' (ASCII 65) => 12
'p' (NFPVV 99) => 15 'B' (ASCII 66) => 14
'q' (NFPVV 100) => 17 'c' (ASCII 99) => 15
'r' (NFPVV 101) => 19 'd' (ASCII 100) => 17
's' (NFPVV 102) => 20 'e' (ASCII 101) => 19
't' (NFPVV 103) => 22 'f' (ASCII 102) => 20
'n' (NFPVV 97) => 24 'g' (ASCII 103) => 22
'o' (NFPVV 98) => 26 'a' (ASCII 97) => 24
'b' (ASCII 98) => 26
```
Ol gur jnl, lbh pna jevgr n unys-gbar ol gur sbyybjvat punenpgref. By the way, you can write a half-tone by the following characters.
'X' => 4 (= P#) ```
'Y' => 6 (= Q#) 'K' => 4 (= C#)
'H' => 8 (= S#) 'L' => 6 (= D#)
'I' => 11 (= T#) 'U' => 8 (= F#)
'C' => 13 (= N#) 'V' => 11 (= G#)
'P' => 13 (= A#)
```
Abgr gung gur gbar ahzoref fvzcyl rahzrengr gur frzv-gbar fgrcf. Note that the tone numbers simply enumerate the semi-tone steps. So we can
Fb jr pna pnyphyngr gur serdhrapl rnfvyl: `cbj(2, a / 12.0)`. calculate the frequency easily: `pow(2, n / 12.0)`. Then, how can we calculate
Gura, ubj pna jr pnyphyngr `cbj` jvgubhg `zngu.u`? `pow` without `math.h`? `pow(2, 1.0 / 12.0)` is approximated by `89/84.`. (I
`cbj(2, 1.0 / 12.0)` vf nccebkvzngrq ol `89/84.`. found this approximation by using the [Stern-Brocot
(V sbhaq guvf nccebkvzngvba ol hfvat [Fgrea-Oebpbg gerr](uggc://ra.jvxvcrqvn.bet/jvxv/Fgrea%R2%80%93Oebpbg_gerr).) tree](http://en.wikipedia.org/wiki/Stern%E2%80%93Brocot_tree).) We can gain the
Jr pna tnva gur serdhrapl ol zhygvcylvat gur inyhr `a` gvzrf. frequency by multiplying the value by `n` times.
Svanyyl, gur sbyybjvat pbqr trarengrf n fnj jnir: Finally, the following code generates a saw wave:
sbe(p = 0; p < yra; p++) chgpune(n = a * Q); ```c
for(c = 0; c < len; c++) putchar(a = n * D);
```
jurer `Q` vf n serdhrapl naq `n` vf n inevnoyr jubfr glcr vf pune. where `D` is a frequency and `a` is a variable whose type is char. By assigning
Ol nffvtavat sybng gb pune inevnoyr, gur vzcyvpvg glcr pbairegvba vf cresbezrq sebz sybng gb pune (zbqhyb 256). float to char variable, the implicit type conversion is performed from float to
(Fgevpgyl fcrnxvat, guvf orunivbe vf haqrsvarq nppbeqvat gb 6.3.1.4 va P99; char (modulo 256).
lbh pna ercynpr vg jvgu `(ybat)(a*Q)` vs lbh ner crqnagvp.)
(Strictly speaking, this behavior is undefined according to 6.3.1.4 in C99; you
can replace it with `(long)(n*D)` if you are pedantic.)
All that was left was to combine and condense the components. The key is
squashing them into just one for-loop.
Nyy gung jnf yrsg jnf gb pbzovar naq pbaqrafr gur pbzcbaragf.
Gur xrl vf fdhnfuvat gurz vagb whfg bar sbe-ybbc.
## Copyright and CC BY-SA 4.0 License: ## Copyright and CC BY-SA 4.0 License: