Update experiment with tty audio

This commit is contained in:
Justine Tunney 2022-07-15 23:07:32 -07:00
parent aa34340f3d
commit 6c724c0f1a
7 changed files with 286 additions and 30 deletions

41
libc/fmt/decodenf32.c Normal file
View file

@ -0,0 +1,41 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/fmt/nf32.h"
#include "libc/str/str.h"
/**
* Decodes u32 from ANSI Nf sequence.
*/
uint32_t DecodeNf32(const char *s, char **e) {
int diglet;
uint32_t x;
for (x = 0; (diglet = kNfcimal[*s & 255]) != -1; s++) {
if (__builtin_mul_overflow(x, 10, &x) ||
__builtin_add_overflow(x, diglet, &x)) {
errno = ERANGE;
x = -1;
break;
}
}
if (e) {
*e = (char *)s;
}
return x;
}

41
libc/fmt/encodenf32.c Normal file
View file

@ -0,0 +1,41 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/nf32.h"
/**
* Encodes u32 as ANSI Nf sequence content.
*/
char *EncodeNf32(char p[hasatleast 12], uint32_t x) {
char t;
size_t i, a, b;
i = 0;
do {
p[i++] = " ,.-+*#%&$"[x % 10];
x = x / 10;
} while (x > 0);
p[i] = '\0';
if (i) {
for (a = 0, b = i - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
}
return p + i;
}

75
libc/fmt/knfcimal.S Normal file
View file

@ -0,0 +1,75 @@
#include "libc/macros.internal.h"
// generated by:
// o/tool/build/xlat.com -s kNfcimal -inx -1 -I ' ,.-+*#%&$'
//
// present absent
//
// 0x00
// § 0x10
// #§%& *+,-. ! () / 0x20
// 0123456789:;<=>⁇ 0x30
// @ABCDEFGHIJKLMNO 0x40
// PQRSTUVWXYZ[]^_ 0x50
// `abcdefghijklmno 0x60
// pqrstuvwxyz{|}~ 0x70
// ÇüéâäàåçêëèïîìÄÅ 0x80
// ÉæÆôöòûùÿÖÜ¢£¥ƒ 0x90
// áíóúñѪº¿¬½¼¡«» 0xa0
// 0xb0
// 0xc0
// 0xd0
// αßΓπΣσμτΦΘΩδφε 0xe0
// ±÷°×²λ 0xf0
//
// const char kNfcimal[256] = {
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x00
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x10
// 0,-1,-1, 6, 9, 7, 8,-1,-1,-1, 5, 4, 1, 3, 2,-1, // 0x20
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x30
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x40
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x50
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x60
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x70
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x80
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0x90
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xa0
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xb0
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xc0
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xd0
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xe0
// -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0xf0
// };
.initbss 300,_init_kNfcimal
kNfcimal:
.zero 256
.endobj kNfcimal,globl
.previous
.initro 300,_init_kNfcimal
kNfcimal.rom:
.byte 32,255 # 00-1f -
.byte 1,0 # 20-20 -
.byte 2,255 # 21-22 !-
.byte 1,6 # 23-23 #-#
.byte 1,9 # 24-24 §-§
.byte 1,7 # 25-25 %-%
.byte 1,8 # 26-26 &-&
.byte 3,255 # 27-29 -)
.byte 1,5 # 2a-2a *-*
.byte 1,4 # 2b-2b +-+
.byte 1,1 # 2c-2c ,-,
.byte 1,3 # 2d-2d ---
.byte 1,2 # 2e-2e .-.
.byte 209,255 # 2f-ff /-λ
.byte 0,0 # terminator
.byte 0,0 # padding
.endobj kNfcimal.rom,globl
.init.start 300,_init_kNfcimal
call rldecode
lodsw
.init.end 300,_init_kNfcimal
// 39 bytes total (15% original size)

13
libc/fmt/nf32.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef COSMOPOLITAN_LIBC_FMT_NF32_H_
#define COSMOPOLITAN_LIBC_FMT_NF32_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern const char kNfcimal[256];
uint32_t DecodeNf32(const char *, char **);
char *EncodeNf32(char[hasatleast 12], uint32_t);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_NF32_H_ */