Add 2020 source files for real
This commit is contained in:
1 parent
a3c1748648
commit
9d61fc0fb4
147 files changed
+32101
No files matched your search
@@ -0,0 +1,590 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# 2020 makefile
|
||||
#
|
||||
# This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis
|
||||
# is licensed under:
|
||||
#
|
||||
# Creative Commons Attribution-ShareAlike 3.0 Unported License.
|
||||
#
|
||||
# See: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
#############################
|
||||
# shell used by this Makefile
|
||||
#############################
|
||||
#
|
||||
SHELL= /bin/bash
|
||||
|
||||
#######################
|
||||
# common tool locations
|
||||
#######################
|
||||
#
|
||||
A2P= a2p
|
||||
AR= ar
|
||||
ASA= asa
|
||||
AT= at
|
||||
ATQ= atq
|
||||
ATRM= atrm
|
||||
AWK= awk
|
||||
BANNER= banner
|
||||
BASE64= base64
|
||||
BASENAME= basename
|
||||
BATCH= batch
|
||||
BC= bc
|
||||
BINHEX= binhex
|
||||
BISON= bison
|
||||
BUNZIP2= bunzip2
|
||||
BZCAT= bzcat
|
||||
BZCMP= bzcmp
|
||||
BZDIFF= bzdiff
|
||||
BZEGREP= bzegrep
|
||||
BZFGREP= bzfgrep
|
||||
BZGREP= bzgrep
|
||||
BZIP2= bzip2
|
||||
BZLESS= bzless
|
||||
BZMORE= bzmore
|
||||
C2PH= c2ph
|
||||
C89= c89
|
||||
C99= c99
|
||||
CAL= cal
|
||||
CALC= calc
|
||||
CAT= cat
|
||||
CD= cd
|
||||
CHFLAGS= chflags
|
||||
CHGRP= chgrp
|
||||
CHMOD= chmod
|
||||
CKSUM= cksum
|
||||
CLANG= clang
|
||||
CLANG_PLUSPLUS= clang++
|
||||
CLEAR= clear
|
||||
CMP= cmp
|
||||
COL= col
|
||||
COLLDEF= colldef
|
||||
COLRM= colrm
|
||||
COLUMN= column
|
||||
COMPRESS= compress
|
||||
CP= cp
|
||||
CPIO= cpio
|
||||
CPP= cpp
|
||||
CRC32= crc32
|
||||
CSH= csh
|
||||
CSPLIT= csplit
|
||||
CURL= curl
|
||||
CUT= cut
|
||||
C_PLUSPLUS= c++
|
||||
C_PLUSPLUS_FILT= c++filt
|
||||
DATE= date
|
||||
DC= dc
|
||||
DD= dd
|
||||
DF= df
|
||||
DIFF3= diff3
|
||||
DIFF= diff
|
||||
DIG= dig
|
||||
DIRNAME= dirname
|
||||
ECHO= echo
|
||||
ED= ed
|
||||
EGREP= egrep
|
||||
ENV= env
|
||||
EQN= eqn
|
||||
ETAGS= etags
|
||||
EXPECT= expect
|
||||
EXPR= expr
|
||||
FALSE= false
|
||||
FGREP= fgrep
|
||||
FILE= file
|
||||
FIND2PERL= find2perl
|
||||
FIND= find
|
||||
FLEX= flex
|
||||
FLEX_PLUSPLUS= flex++
|
||||
FMT= fmt
|
||||
FOLD= fold
|
||||
FS_USAGE= fs_usage
|
||||
FUNZIP= funzip
|
||||
FUSER= fuser
|
||||
GCC= gcc
|
||||
GDIFFMK= gdiffmk
|
||||
GENCAT= gencat
|
||||
GENSTRINGS= genstrings
|
||||
GETOPT= getopt
|
||||
GETOPTS= getopts
|
||||
GINDENT= gindent
|
||||
GNUMAKE= gnumake
|
||||
GREP= grep
|
||||
GROFF= groff
|
||||
GROFFER= groffer
|
||||
GROG= grog
|
||||
GROPS= grops
|
||||
GROTTY= grotty
|
||||
GUNZIP= gunzip
|
||||
GVIM= gvim
|
||||
GZCAT= gzcat
|
||||
GZEXE= gzexe
|
||||
GZIP_PROG= gzip
|
||||
G_PLUSPLUS= g++
|
||||
H2PH= h2ph
|
||||
H2XS= h2xs
|
||||
HASH= hash
|
||||
HEAD= head
|
||||
HOSTNAME_PROG= hostname
|
||||
ICONV= iconv
|
||||
ID= id
|
||||
INDENT= indent
|
||||
INFO= info
|
||||
JOT= jot
|
||||
KILL= kill
|
||||
KSH= ksh
|
||||
LAST= last
|
||||
LD= ld
|
||||
LESSECHO= lessecho
|
||||
LEX= len
|
||||
LINK= link
|
||||
LN= ln
|
||||
LS= ls
|
||||
M4= m4
|
||||
MAKE= make
|
||||
MAN= man
|
||||
MKDIR= mkdir
|
||||
MKFIFo= mkfifo
|
||||
MKTEMP= mktemp
|
||||
MV= mv
|
||||
NANO= nano
|
||||
NASM= nasm
|
||||
NEQN= neqn
|
||||
NICE= nice
|
||||
NL= nl
|
||||
NM= nm
|
||||
NOHUP= nohup
|
||||
NROFF= nroff
|
||||
NSLOOKUP= nslookup
|
||||
OD= od
|
||||
OPENSSL= openssl
|
||||
PASTE= paste
|
||||
PATCH= patch
|
||||
PATHCHK= pathchk
|
||||
PAX= pax
|
||||
PERL= perl
|
||||
PICO= pico
|
||||
PR= pr
|
||||
PRINTENV= printenv
|
||||
PS= ps
|
||||
PTAR= ptar
|
||||
PTARDIFF= ptardiff
|
||||
PTARGREP= ptargrep
|
||||
PWD= pwd
|
||||
PYDOC= pydoc
|
||||
PYTHON= python
|
||||
PYTHONW= pythonw
|
||||
READLINK= readlink
|
||||
RENICE= renice
|
||||
RESET= reset
|
||||
REV= rev
|
||||
RI= ri
|
||||
RM= rm
|
||||
RMDIR= rmdir
|
||||
RSYNC= rsync
|
||||
RUBY= ruby
|
||||
RVIM= rvim
|
||||
SAY= say
|
||||
SCP= scp
|
||||
SCREEN= screen
|
||||
SCRIPT= script
|
||||
SDIFF= sdiff
|
||||
SED= sed
|
||||
SEQ= seq
|
||||
SFTP= sftp
|
||||
SH= sh
|
||||
SHA1= sha1
|
||||
SHA= sha
|
||||
SHAR= shar
|
||||
SHASUM5_18= shasum5.18
|
||||
SHASUM= shasum
|
||||
SIZE= size
|
||||
SLEEP= sleep
|
||||
SORT= sort
|
||||
SSH= ssh
|
||||
STAT= stat
|
||||
STRIP= strip
|
||||
STTY= stty
|
||||
SUM= sum
|
||||
SYNC= sync
|
||||
TABS= tabs
|
||||
TAIL= tail
|
||||
TAR= tar
|
||||
TEE= tee
|
||||
TEST= test
|
||||
TFTP= tftp
|
||||
TIDY= tidy
|
||||
TIME= time
|
||||
TOP= top
|
||||
TOUCH= touch
|
||||
TPUT= tout
|
||||
TPUT= tput
|
||||
TR= tr
|
||||
TROFF= troff
|
||||
TRUE= true
|
||||
TSET= tset
|
||||
TSORT= tsort
|
||||
UL= ul
|
||||
UNAME= uname
|
||||
UNCOMPRESS= uncompress
|
||||
UNEXPAND= unexpand
|
||||
UNIFDEF= unifdef
|
||||
UNIFDEFALL= unifdefall
|
||||
UNIQ= uniq
|
||||
UNITS= units
|
||||
UNLINK= unlink
|
||||
UNZIP= unzip
|
||||
UNZIPSFX= unzipsfx
|
||||
UPTIME= uptime
|
||||
UUDECODE= uudecode
|
||||
UUENCODE= uuencode
|
||||
UUIDGEN= uuidgen
|
||||
VI= vi
|
||||
VIEW= view
|
||||
VIM= vim
|
||||
VIMDIFF= vimdiff
|
||||
W= w
|
||||
WAIT4PATH= wait4path
|
||||
WAIT= wait
|
||||
WC= wc
|
||||
WHAT= what
|
||||
WHATIS= whatis
|
||||
WHICH= which
|
||||
WHO= who
|
||||
WHOAMI= whoami
|
||||
WHOIS= whois
|
||||
WRTIE= write
|
||||
XAR= xar
|
||||
XARGS= xargs
|
||||
XATTR= xattr
|
||||
XXD= xxd
|
||||
YACC= yacc
|
||||
YES= yes
|
||||
ZCAT= zcat
|
||||
ZCMP= zcmp
|
||||
ZDIFF= zdiff
|
||||
ZEGREP= zegrep
|
||||
ZFGREP= zfgrep
|
||||
ZFORCE= zforce
|
||||
ZGREP= zgrep
|
||||
ZIP= zip
|
||||
ZIPCLOAK= zipcloak
|
||||
ZIPGREp= zipgrep
|
||||
ZIPINFo= zipinfo
|
||||
ZIPNOTE= zipnote
|
||||
ZIPSPLIT= zipsplit
|
||||
ZLESS= zless
|
||||
ZMORE= zmore
|
||||
ZNEW= znew
|
||||
ZPRINT= zprint
|
||||
ZSH= zsh
|
||||
|
||||
# Set X11_LIBDIR to the directory where the X11 library resides
|
||||
#
|
||||
#X11_LIBDIR= /usr/X11R6/lib
|
||||
#X11_LIBDIR= /usr/X11/lib
|
||||
X11_LIBDIR= /opt/X11/lib
|
||||
|
||||
# Set X11_INCLUDEDIR to the directory where the X11 include files reside
|
||||
#
|
||||
#X11_INCDIR= /usr/X11R6/include
|
||||
#X11_INCDIR= /usr/X11/include
|
||||
X11_INCDIR= /opt/X11/include
|
||||
|
||||
# CWARN - Silence warnings that ${CWARN} would normally complain about
|
||||
# CSILENCE -Compiler warnings
|
||||
#
|
||||
ifeq ($(CC),clang)
|
||||
|
||||
# clang CSILENCE and CWARN
|
||||
#
|
||||
#CSILENCE=
|
||||
#CSILENCE= -Wno-implicit-int
|
||||
CSILENCE= -Wno-disabled-macro-expansion -Wno-empty-body -Wno-float-conversion -Wno-float-equal \
|
||||
-Wno-missing-variable-declarations -Wno-shadow -Wno-shorten-64-to-32 -Wno-sign-conversion \
|
||||
-Wno-string-plus-char -Wno-string-plus-int -Wno-unknown-warning-option
|
||||
#
|
||||
#CWARN= $CSILENCE}
|
||||
#CWARN= -Wall $CSILENCE}
|
||||
#CWARN= -Wall -Wextra $CSILENCE}
|
||||
#CWARN= -Wall -Wextra -pedantic ${CSILENCE}
|
||||
#CWARN= -Wall -Wextra -Weverything $CSILENCE}
|
||||
CWARN= -Wall -Wextra -Weverything -pedantic ${CSILENCE}
|
||||
|
||||
else
|
||||
ifeq ($(CC),gcc)
|
||||
|
||||
# gcc CSILENCE and CWARN
|
||||
#
|
||||
#CSILENCE=
|
||||
#CSILENCE= -Wno-implicit-int
|
||||
CSILENCE= -Wno-empty-body -Wno-string-plus-char -Wno-string-plus-int -Wno-unknown-warning-option
|
||||
#
|
||||
#CWARN= $CSILENCE}
|
||||
#CWARN= -Wall $CSILENCE}
|
||||
#CWARN= -Wall -Wextra $CSILENCE}
|
||||
CWARN= -Wall -Wextra -pedantic ${CSILENCE}
|
||||
|
||||
else
|
||||
|
||||
# default CSILENCE and WARN
|
||||
#
|
||||
#CSILENCE=
|
||||
#CSILENCE= -Wno-implicit-int
|
||||
CSILENCE= -Wno-empty-body -Wno-string-plus-char -Wno-string-plus-int -Wno-unknown-warning-option
|
||||
#
|
||||
#CWARN= $CSILENCE}
|
||||
#CWARN= -Wall $CSILENCE}
|
||||
#CWARN= -Wall -Wextra $CSILENCE}
|
||||
CWARN= -Wall -Wextra -pedantic ${CSILENCE}
|
||||
#CWARN= -Wall -Wextra -Weverything $CSILENCE}
|
||||
#CWARN= -Wall -Wextra -Weverything -pedantic ${CSILENCE}
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
# compiler standard
|
||||
#
|
||||
#CSTD=
|
||||
#CSTD= -ansi
|
||||
#CSTD= -std=c11
|
||||
CSTD= -std=c99
|
||||
|
||||
# compiler bit architecture
|
||||
#
|
||||
# Some entries require 32-bitness:
|
||||
# ARCH= -m32
|
||||
#
|
||||
# Some entries require 64-bitness:
|
||||
# ARCH= -m64
|
||||
#
|
||||
# By default we assume nothing:
|
||||
#
|
||||
ARCH=
|
||||
|
||||
# defines that are needed to compile
|
||||
#
|
||||
CDEFINE=
|
||||
#CDEFINE= -DIOCCC
|
||||
|
||||
# include files that are needed to compile
|
||||
#
|
||||
CINCLUDE=
|
||||
#CINCLUDE= -include stdlib.h
|
||||
#CINCLUDE= -include stdio.h
|
||||
#CINCLUDE= -include stdlib.h -include stdio.h
|
||||
#CINCLUDE= -I ${X11_INCDIR}
|
||||
|
||||
# optimization
|
||||
#
|
||||
# Most compiles will safely use -O2. Some can use only -O1 or -O.
|
||||
# A few compilers have broken optimizers or this entry make break
|
||||
# under those buggy optimizers and thus you may not want anything.
|
||||
# Reasonable compilers will allow for -O3.
|
||||
#
|
||||
#OPT=
|
||||
#OPT= -O
|
||||
#OPT= -O1
|
||||
#OPT= -O2
|
||||
OPT= -O3
|
||||
|
||||
# default flags for ANSI C compilation
|
||||
#
|
||||
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
|
||||
|
||||
# Libraries needed to build
|
||||
#
|
||||
LIBS=
|
||||
#LIBS= -L ${X11_LIBDIR}
|
||||
|
||||
# ANSI compiler
|
||||
#
|
||||
# Set CC to the name of your ANSI compiler.
|
||||
#
|
||||
# Some entries seem to need gcc. If you have gcc, set
|
||||
# both CC and MAY_NEED_GCC to gcc.
|
||||
#
|
||||
# If you do not have gcc, set CC to the name of your ANSI compiler, and
|
||||
# set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just :
|
||||
# to disable such programs.
|
||||
#
|
||||
CC= cc
|
||||
#CC= clang
|
||||
MAY_NEED_GCC= gcc
|
||||
|
||||
|
||||
##############################
|
||||
# Special flags for this entry
|
||||
##############################
|
||||
#
|
||||
OBJ= prog.o
|
||||
DATA= dtmf.bin pi.wav
|
||||
TARGET= prog
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
|
||||
|
||||
#################
|
||||
# build the entry
|
||||
#################
|
||||
#
|
||||
all: ${TARGET} ${DATA}
|
||||
@${TRUE}
|
||||
|
||||
prog: prog.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LIBS}
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
alt: ${ALT_TARGET}
|
||||
@${TRUE}
|
||||
|
||||
# data files
|
||||
#
|
||||
data: ${DATA}
|
||||
@${TRUE}
|
||||
|
||||
|
||||
###############
|
||||
# utility rules
|
||||
###############
|
||||
#
|
||||
everything: all alt
|
||||
|
||||
clean:
|
||||
${RM} -f ${OBJ} ${ALT_OBJ}
|
||||
@-if [ -f indent.c ]; then \
|
||||
${ECHO} ${RM} -f indent.c; \
|
||||
${RM} -f indent.c; \
|
||||
fi
|
||||
|
||||
clobber: clean
|
||||
${RM} -f ${TARGET} ${ALT_TARGET}
|
||||
@-if [ -e sandwich ]; then \
|
||||
${RM} -f sandwich; \
|
||||
${ECHO} 'ate sandwich'; \
|
||||
fi
|
||||
|
||||
nuke: clobber
|
||||
@${TRUE}
|
||||
|
||||
dist_clean: nuke
|
||||
@${TRUE}
|
||||
|
||||
install:
|
||||
@${ECHO} "Surely you are performing, Dr. Science!"
|
||||
@${TRUE}
|
||||
|
||||
# backwards compatibility
|
||||
#
|
||||
build: all
|
||||
@${TRUE}
|
||||
|
||||
# you may be able to mis-understand the source by reading indent.c
|
||||
#
|
||||
indent.c: prog.c
|
||||
@if which "${GINDENT}" >/dev/null 2>&1; then \
|
||||
${ECHO} ${RM} -f $@; \
|
||||
${RM} -f $@; \
|
||||
${ECHO} "${GINDENT} < $< > $@"; \
|
||||
${GINDENT} < $< > $@; \
|
||||
elif which "${INDENT}" >/dev/null 2>&1; then \
|
||||
${ECHO} ${RM} -f $@; \
|
||||
${RM} -f $@; \
|
||||
${ECHO} "${INDENT} < $< > $@"; \
|
||||
${INDENT} < $< > $@; \
|
||||
else \
|
||||
${ECHO} "no intent prog found, ident $< yourself, sorry"; \
|
||||
${ECHO} "exit 1"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
|
||||
##################
|
||||
# 133t hacker rulz
|
||||
##################
|
||||
#
|
||||
love:
|
||||
@${ECHO} 'not war?'
|
||||
@${TRUE}
|
||||
|
||||
haste:
|
||||
$(MAKE) waste
|
||||
@${TRUE}
|
||||
|
||||
waste:
|
||||
@${ECHO} 'haste'
|
||||
@${TRUE}
|
||||
|
||||
make:
|
||||
@${ECHO} 'We encourage you to attend a maker faire'
|
||||
@${TRUE}
|
||||
|
||||
easter_egg:
|
||||
@${ECHO} you expected to often mis-understand this $${RANDOM} magic
|
||||
@${ECHO} chongo '<was here>' "/\\oo/\\"
|
||||
@${ECHO} Eggy and Kitty
|
||||
|
||||
fabricate fashion form frame manufacture produce: make
|
||||
@${TRUE}
|
||||
|
||||
sandwich:
|
||||
@if [ `id -u` -eq 0 ]; then \
|
||||
${ECHO} 'Okay.'; \
|
||||
${ECHO} $${RANDOM}`date +%s`$${RANDOM} | \
|
||||
${SHASUM} -a 512256 | \
|
||||
${SED} -e 's/ .*//' > $@; \
|
||||
else \
|
||||
${ECHO} 'Reall?!? Make it yourself.'; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
# Understand the history of the Homebrew Computer Club
|
||||
# as well as the West Coast Computer Faire and
|
||||
# you might be confused different. :-)
|
||||
#
|
||||
supernova: nuke
|
||||
@-if [ -r .code_anal ]; then \
|
||||
${RM} -f .code_anal_v6; \
|
||||
else \
|
||||
${ECHO} "planet deniers, like a few silly IAU members, are so cute when they try to defend their logic"; \
|
||||
fi
|
||||
@${ECHO} A $@ helps ${MAKE} the elements that help form planets
|
||||
@${TRUE}
|
||||
|
||||
deep_magic:
|
||||
@-if [ -r .code_anal ]; then \
|
||||
ccode_analysis --deep_magic 253d8c80830e2df66c018820004b3d4939821bbd7d781fc50d9e633797e44f65d1d62c707bb7e5a82c328a37bbf9ecb4c46fb56aa3f08641fcf45d10ba3c6081 --FNV1a_hash_512_bit "prog"; \
|
||||
else \
|
||||
${ECHO} "Wrong! Do it again!"; \
|
||||
sleep 1; \
|
||||
${ECHO} "Wrong! Do it again!"; \
|
||||
sleep 1; \
|
||||
${ECHO} "Wrong! Do it again!"; \
|
||||
fi
|
||||
@${TRUE}
|
||||
|
||||
magic: deep_magic
|
||||
@-if [ -r .code_anal ]; then \
|
||||
ccode_analysis --level 391581 --mode 216193 --state Riesel --FNV1a_hash_512_bit "prog"; \
|
||||
else \
|
||||
${ECHO} "If you don't eat yer meat, you can't have any pudding!"; \
|
||||
${ECHO} "How can you have any pudding if you don't eat yer meat?!"; \
|
||||
${ECHO} "p.s. Be cafeful with that axe, Eugene."; \
|
||||
fi
|
||||
@${TRUE}
|
||||
|
||||
# The IOCCC resident astronomer states
|
||||
#
|
||||
charon: supernova
|
||||
@${ECHO} $@ is a dwarf planet
|
||||
@${ECHO} dwarf is a type of planet
|
||||
@${ECHO} therefore we continue to tell the IAU that $@ is a planet
|
||||
|
||||
pluto: supernova
|
||||
${MAKE} charon
|
||||
@${ECHO} $@ is a dwarf planet
|
||||
@${ECHO} dwarf is a type of planet
|
||||
@${ECHO} therefore, $@ is a planet
|
||||
@${ECHO} having lots of planets is good feature because $< can help ${MAKE} a lot of them
|
||||
Binary file not shown.
@@ -0,0 +1,97 @@
|
||||
# Most phony
|
||||
|
||||
Edward Giles
|
||||
<https://id523a.com/>
|
||||
|
||||
|
||||
The code for this entry can be found in prog.c
|
||||
|
||||
## Judges' comments:
|
||||
### To use:
|
||||
|
||||
make
|
||||
./prog
|
||||
|
||||
### Try:
|
||||
|
||||
./prog < pi.wav
|
||||
|
||||
# [https://en.wikipedia.org/wiki/867-5309/Jenny]
|
||||
./prog 867-5309 > jenny.wav
|
||||
|
||||
# Use an audio player to play jenny.wav
|
||||
|
||||
### Selected Judges Remarks:
|
||||
|
||||
A cross platform utility for both encoding and decoding tones.
|
||||
|
||||
## Author's comments:
|
||||
### Introduction and Usage
|
||||
|
||||
This program encodes and decodes [dual-tone multiple frequency](https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling) signals used in telephone systems, more commonly known as Touch-Tones.
|
||||
|
||||
If the program is executed with no arguments, it will read a WAV file from standard input, decode the touch-tones in the file, and output the corresponding digits to standard output. This program only supports WAV files that have exactly 16 bits per sample, but it allows any sample rate and any number of audio channels.
|
||||
|
||||
$ ./prog < pi.wav
|
||||
31415926
|
||||
|
||||
If the program is executed with a command-line argument, it will generate the tones corresponding to the specified characters, writing them to standard output as a WAV file.
|
||||
|
||||
$ ./prog 867-5309 | aplay
|
||||
|
||||
### Interesting Features
|
||||
|
||||
* When compiled with `gcc -pedantic -Wall -Wextra` there are no compiler warnings.
|
||||
* This program can be successfully compiled and run on Windows, using both Microsoft's C compiler and [TCC](https://bellard.org/tcc/).
|
||||
* This program resamples the incoming audio, so that it can accept audio data at any sample rate.
|
||||
* The code that generates the output sine-waves is the same as the code that looks for sine-waves in the input. (see Algorithm Details for roughly how this works)
|
||||
* Despite handling lots of sine waves, the program only uses basic arithmetic operations. It does not depend on `libm`.
|
||||
* All type punning is done with `memcpy` so there are no strict-aliasing violations.
|
||||
* The size of the source code using the IOCCC size tool is 1963, the year the first push-button telephones were made available to customers.
|
||||
* The source code is roughly in the shape of a telephone handset.
|
||||
|
||||
### Assumptions
|
||||
|
||||
* Code is compiled using the C99 or C11 standard
|
||||
* `CHAR_BIT == 8`
|
||||
* Machine is little-endian
|
||||
* `int16_t`, `uint16_t`, and `uint32_t` exist
|
||||
* `int16_t` is 2's-complement
|
||||
* `double` is an IEEE 754 binary64 floating-point type
|
||||
* `sizeof(double) == 8`
|
||||
|
||||
### Obfuscations
|
||||
|
||||
* DSP code is inherently somewhat difficult to understand.
|
||||
* Lots of identifier reuse. Each identifier is used for about 2.2 different tasks, on average.
|
||||
For example, `aa` is both a variable and a macro for error handling,
|
||||
and `memcpy` is both a library function and a goto-label.
|
||||
* Most of the identifiers are only 1 or 2 characters long, and are unrelated to their actual function.
|
||||
* The `f` macro is used to unroll some of the loops.
|
||||
* Some numerical constants are replaced with character literals, so the actual value is unclear.
|
||||
* All of the strings used by the program have been combined into a single string literal.
|
||||
* Most of the values used for the actual signal-processing all reside in one array, named `l`. This array is usually accessed at index `z` plus a constant. Accesses of this type have been rewritten from, e.g. `l[z+17]` to `17[l+z]`. `[l+z]` ends up occurring quite often, so I created the macro `a` as a shorthand.
|
||||
|
||||
|
||||
### Algorithm Details
|
||||
|
||||
Each tone in a DTMF signal is a combination of two frequencies. The lower frequency determines which row the digit is in, and the higher frequency determines the column. There are 4 possible row frequencies and 4 possible column frequencies.
|
||||
|
||||
| | **1209 Hz** | **1336 Hz** | **1477 Hz** | **1633 Hz** |
|
||||
|------------|-------------|-------------|-------------|-------------|
|
||||
| **697 Hz** | 1 | 2 abc | 3 def | A |
|
||||
| **770 Hz** | 4 ghi | 5 jkl | 6 mno | B |
|
||||
| **852 Hz** | 7 pqrs | 8 tuv | 9 wxyz | C |
|
||||
| **941 Hz** | * | 0 | # | D |
|
||||
|
||||
This program determines which frequencies are present in the input by passing it through a set of 8 virtual resonators, each tuned to one of the frequencies used for DTMF. These can be implemented using only basic arithmetic, and they are able to 'select' a specific frequency from the input sound, blocking all other frequencies from reaching the output. The loudness of the sound output from each resonator can therefore be used as a measure of how much of a particular frequency was present in the input. The program then decides, over the course of one tone, which row frequency and which column frequency were most prominent.
|
||||
|
||||
Tones are generated using those same resonators by providing [an impulse](https://en.wikipedia.org/wiki/Kronecker_delta#Digital_signal_processing) as input. An impulse can be thought of as consisting of sine-waves at all frequencies, and when it is put through one of the resonators, the result is a single pure sine wave.
|
||||
|
||||
-----------------------------------------------------------------------------------------------------
|
||||
(c) Copyright 1984-2020, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
|
||||
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
|
||||
|
||||
[judges]: http://www.ioccc.org/judges.html
|
||||
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
-----------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,178 @@
|
||||
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional //EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="GENERATOR" content="mkd2html 2.2.2">
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=utf-8"> <link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="../hint.css" />
|
||||
<title></title>
|
||||
<title>Most phony</title>
|
||||
</head>
|
||||
<body>
|
||||
<CENTER>
|
||||
<IMG SRC="/png/ioccc.png" ALT="IOCCC" height=78 width=267>
|
||||
<P><FONT size="6"><I>The International Obfuscated C Code Contest</I></FONT></P>
|
||||
<div id="bar">
|
||||
<ul>
|
||||
<li><a href="../index.html">About the 27th IOCCC</a></li>
|
||||
<li><a href="../whowon.html">27th IOCCC Winners</a></li>
|
||||
<li><a href="/index.html">IOCCC home</a></li>
|
||||
<li><a href="/winners.html">List of All Winners</a></li>
|
||||
<li><a href="/judges.html">The Judges</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<P><FONT size="6"><B>A 27<sup>th</sup> IOCCC Winner</B></FONT></P>
|
||||
</CENTER>
|
||||
|
||||
|
||||
<h1>Most phony</h1>
|
||||
|
||||
<p>Edward Giles<br/>
|
||||
<a href="https://id523a.com/">https://id523a.com/</a></p>
|
||||
|
||||
<p>The code for this entry can be found in <a href="prog.c">prog.c</a></p>
|
||||
|
||||
<h2>Judges' comments:</h2>
|
||||
|
||||
<h3>To use:</h3>
|
||||
|
||||
<pre><code>make
|
||||
./prog
|
||||
</code></pre>
|
||||
|
||||
<h3>Try:</h3>
|
||||
|
||||
<pre><code>./prog < pi.wav
|
||||
|
||||
# [https://en.wikipedia.org/wiki/867-5309/Jenny]
|
||||
./prog 867-5309 > jenny.wav
|
||||
|
||||
# Use an audio player to play jenny.wav
|
||||
</code></pre>
|
||||
|
||||
<h3>Selected Judges Remarks:</h3>
|
||||
|
||||
<p>A cross platform utility for both encoding and decoding tones.</p>
|
||||
|
||||
<h2>Author’s comments:</h2>
|
||||
|
||||
<h3>Introduction and Usage</h3>
|
||||
|
||||
<p>This program encodes and decodes <a href="https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling">dual-tone multiple frequency</a> signals used in telephone systems, more commonly known as Touch-Tones.</p>
|
||||
|
||||
<p>If the program is executed with no arguments, it will read a WAV file from standard input, decode the touch-tones in the file, and output the corresponding digits to standard output. This program only supports WAV files that have exactly 16 bits per sample, but it allows any sample rate and any number of audio channels.</p>
|
||||
|
||||
<pre><code>$ ./prog < pi.wav
|
||||
31415926
|
||||
</code></pre>
|
||||
|
||||
<p>If the program is executed with a command-line argument, it will generate the tones corresponding to the specified characters, writing them to standard output as a WAV file.</p>
|
||||
|
||||
<pre><code>$ ./prog 867-5309 | aplay
|
||||
</code></pre>
|
||||
|
||||
<h3>Interesting Features</h3>
|
||||
|
||||
<ul>
|
||||
<li>When compiled with <code>gcc -pedantic -Wall -Wextra</code> there are no compiler warnings.</li>
|
||||
<li>This program can be successfully compiled and run on Windows, using both Microsoft’s C compiler and <a href="https://bellard.org/tcc/">TCC</a>.</li>
|
||||
<li>This program resamples the incoming audio, so that it can accept audio data at any sample rate.</li>
|
||||
<li>The code that generates the output sine-waves is the same as the code that looks for sine-waves in the input. (see Algorithm Details for roughly how this works)</li>
|
||||
<li>Despite handling lots of sine waves, the program only uses basic arithmetic operations. It does not depend on <code>libm</code>.</li>
|
||||
<li>All type punning is done with <code>memcpy</code> so there are no strict-aliasing violations.</li>
|
||||
<li>The size of the source code using the IOCCC size tool is 1963, the year the first push-button telephones were made available to customers.</li>
|
||||
<li>The source code is roughly in the shape of a telephone handset.</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h3>Assumptions</h3>
|
||||
|
||||
<ul>
|
||||
<li>Code is compiled using the C99 or C11 standard</li>
|
||||
<li><code>CHAR_BIT == 8</code></li>
|
||||
<li>Machine is little-endian</li>
|
||||
<li><code>int16_t</code>, <code>uint16_t</code>, and <code>uint32_t</code> exist</li>
|
||||
<li><code>int16_t</code> is 2’s-complement</li>
|
||||
<li><code>double</code> is an IEEE 754 binary64 floating-point type</li>
|
||||
<li><code>sizeof(double) == 8</code></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h3>Obfuscations</h3>
|
||||
|
||||
<ul>
|
||||
<li>DSP code is inherently somewhat difficult to understand.</li>
|
||||
<li>Lots of identifier reuse. Each identifier is used for about 2.2 different tasks, on average.
|
||||
For example, <code>aa</code> is both a variable and a macro for error handling,
|
||||
and <code>memcpy</code> is both a library function and a goto-label.</li>
|
||||
<li>Most of the identifiers are only 1 or 2 characters long, and are unrelated to their actual function.</li>
|
||||
<li>The <code>f</code> macro is used to unroll some of the loops.</li>
|
||||
<li>Some numerical constants are replaced with character literals, so the actual value is unclear.</li>
|
||||
<li>All of the strings used by the program have been combined into a single string literal.</li>
|
||||
<li>Most of the values used for the actual signal-processing all reside in one array, named <code>l</code>. This array is usually accessed at index <code>z</code> plus a constant. Accesses of this type have been rewritten from, e.g. <code>l[z+17]</code> to <code>17[l+z]</code>. <code>[l+z]</code> ends up occurring quite often, so I created the macro <code>a</code> as a shorthand.</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h3>Algorithm Details</h3>
|
||||
|
||||
<p>Each tone in a DTMF signal is a combination of two frequencies. The lower frequency determines which row the digit is in, and the higher frequency determines the column. There are 4 possible row frequencies and 4 possible column frequencies.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th> <strong>1209 Hz</strong> </th>
|
||||
<th> <strong>1336 Hz</strong> </th>
|
||||
<th> <strong>1477 Hz</strong> </th>
|
||||
<th> <strong>1633 Hz</strong> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td> <strong>697 Hz</strong> </td>
|
||||
<td> 1 </td>
|
||||
<td> 2 abc </td>
|
||||
<td> 3 def </td>
|
||||
<td> A </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> <strong>770 Hz</strong> </td>
|
||||
<td> 4 ghi </td>
|
||||
<td> 5 jkl </td>
|
||||
<td> 6 mno </td>
|
||||
<td> B </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> <strong>852 Hz</strong> </td>
|
||||
<td> 7 pqrs </td>
|
||||
<td> 8 tuv </td>
|
||||
<td> 9 wxyz </td>
|
||||
<td> C </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> <strong>941 Hz</strong> </td>
|
||||
<td> * </td>
|
||||
<td> 0 </td>
|
||||
<td> # </td>
|
||||
<td> D </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<p>This program determines which frequencies are present in the input by passing it through a set of 8 virtual resonators, each tuned to one of the frequencies used for DTMF. These can be implemented using only basic arithmetic, and they are able to ‘select’ a specific frequency from the input sound, blocking all other frequencies from reaching the output. The loudness of the sound output from each resonator can therefore be used as a measure of how much of a particular frequency was present in the input. The program then decides, over the course of one tone, which row frequency and which column frequency were most prominent.</p>
|
||||
|
||||
<p>Tones are generated using those same resonators by providing <a href="https://en.wikipedia.org/wiki/Kronecker_delta#Digital_signal_processing">an impulse</a> as input. An impulse can be thought of as consisting of sine-waves at all frequencies, and when it is put through one of the resonators, the result is a single pure sine wave.</p>
|
||||
<BR>
|
||||
<HR>
|
||||
<TABLE><TR>
|
||||
<TD><a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="/png/by-sa-3.0-88x31.png" /></a></TD>
|
||||
<TD><P>© Copyright 1984-2020,
|
||||
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
|
||||
- All rights reserved<BR>
|
||||
This work is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
|
||||
<TD> <!--<a href="https://validator.w3.org/check?uri=referer"><img src="https://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
|
||||
</TR></TABLE>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
@@ -0,0 +1,70 @@
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#define X ;_setmode(_fileno(h),_O_BINARY)
|
||||
#else
|
||||
#define X
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define a [l+z]
|
||||
#define m(aa) z=aa;z=z;;
|
||||
#define g(g,a)memset(g,0,a);
|
||||
#define e2(a,g)!fread(a,g,1,h)
|
||||
#define aa(a)fprintf(stderr,"%s\n",a);return 1;
|
||||
#define n(n) b=n-i;b=b<0?1+b:1-b;d[n+2]+=b>0?b*c*aa:0;
|
||||
#define t(t) z=t;b=(1-6[d])*d[2]+2*17 a*0 a-1 a*d[6];1 a=0 a;0 a=b*6[d];
|
||||
#define f(f,aa) x=0; f(2)aa f(10)aa f(6)aa f(12)aa f(4)aa f(8)aa f(14)aa f(0)aa
|
||||
#define j if(w){b=-1;char j=0;f(m,if(32 a>b){b=32 a;j=k[z];}if(33 a>b){b=33 a;j=k[z+1];})putchar(j);}
|
||||
|
||||
const char*t=
|
||||
|
||||
"Dual-tone multi-frequency signaling"
|
||||
"(DTMF) is a telecommunication signaling"
|
||||
"system using the voice-frequency band"
|
||||
|
||||
"Invalid WAV input\0Read "
|
||||
"error\0Cannot read dtmf.bin\0rb\0"+111;
|
||||
int main(int m,char**f){double aa,c,d[8]={[
|
||||
6]=--m?1:0.994,[7]=1e-4},g,i=0,l['0']={0},b,
|
||||
e2=0,x;char k[':'+'s'];FILE*h;if(!(h=fopen(t+
|
||||
')',t+'2'))){memcpy: aa(t+'A'-'$')}uint32_t p=
|
||||
e2(k+'U',',')||e2(l+16,'C'+'=')||e2(k,'Q'),w=0
|
||||
,o[2],z,n;fclose(h);if(p)goto memcpy;setvbuf(h
|
||||
=m?stdout:stdin,0,_IOFBF,65536)X;uint16_t e,v;
|
||||
int16_t r;if(m){m(6400*strlen(*++f))mem\
|
||||
cpy(k+'+'+'R',&z,4);z+='$';me\
|
||||
mcpy(k+'Y',&z,4);fwrite(k+'U',
|
||||
',',1,h);while(**f){char*c=st\
|
||||
rchr(k,*(*f)++);g(l,'F'+':')if
|
||||
(c){w=c-k;double*n=l+w%4*2;*n
|
||||
=n[16];n=l+8+(w/4)%4*2;*n=n[
|
||||
16];}for(w=3200;w;--w){f(t,x
|
||||
+=b*e2*49e2;)r=x;fwrite(&r,2
|
||||
,1,h);e2+=(w>1300?1:-1)*3e-2
|
||||
;e2=(e2>1?1:(e2>0?e2:0));}}}
|
||||
else{ if(e2(k+'+'+'V',',')){
|
||||
fread:aa(t+18)}if( memcmp(k+
|
||||
'+'+'^',k+']',14)){ int_16t:
|
||||
aa(t)}memcpy(&n,k+'+'+'n',4)
|
||||
;c=16e3/n;n=c; if(n!=c)++n;c
|
||||
/=n;memcpy( &v,k+43+'x',2);v
|
||||
/=8; memcpy(&e,k+'+'+'v',2);
|
||||
if(!e||!v||v>4)goto int_16t;
|
||||
e-=v;while(!e2(k+'Q',v)){m(e
|
||||
)while(z-- && getc(h)>=0);if
|
||||
(v>1){memcpy(&r,k+v+'O',2);g=r/512\
|
||||
.0/'@';} else g=(unsigned char)k['Q']/128.0-1;
|
||||
for(p=n;p;--p){aa=(e2-g)*p/n+g;n(0)n(1)n(2)i+=
|
||||
c;if(i>=1){g(d,16)g(o,8) f(t,b=0 a-d[6]*17 a*1
|
||||
a;aa=d[6]*1 a*16 a;aa=b*b+aa*aa;x+=aa;if(aa>=d
|
||||
[z/8]){o[z/8]=z/2;d[z/8]=aa;})if( (r=w?x>d[7]*
|
||||
0.45:x>d[7]*0.6)){if(!w)g(l+32,128)if(x>d[7])
|
||||
d[7]=x; /* x= (-b+sqrt(b*b-4*a*c))/(2*a); */
|
||||
++ l[16+o[1]*4+*o];}else j w=r;memmove(d+2,d+3
|
||||
,24);--i;}}e2=g;}if(ferror(h))goto fread
|
||||
;j puts("0123456789"+10);}return 0;}
|
||||
Reference in new issue
Block a user