fix Makefile and README.md for 2001/coupard
This commit is contained in:
1 parent
38d4092abe
commit
e64580a245
2 files changed
+365
-262
No files matched your search
+260
-169
@@ -1,18 +1,9 @@
|
|||||||
#!/usr/bin/env make
|
#!/usr/bin/env make
|
||||||
#
|
#
|
||||||
# IOCCC 2001 entry Makefile
|
# IOCCC 2001 winning entry - coupard
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# An Historical Makefile NOTE:
|
|
||||||
#
|
|
||||||
# The orig.Makefile, if it exits, is the original Makefile before this IOCCC
|
|
||||||
# year directory was reworked so that entries are in separate directories.
|
|
||||||
# This also applies to any orig.ansi.mk and orig.common.mk files.
|
|
||||||
#
|
|
||||||
# Several Makefiles were modified / formed in 2022, and as such it may have
|
|
||||||
# elements that are not historically compatible with way entries were built.
|
|
||||||
#
|
|
||||||
# Regarding individual entries:
|
# Regarding individual entries:
|
||||||
#
|
#
|
||||||
# IOCCC winning entry code may not work on your system. Even with standards,
|
# IOCCC winning entry code may not work on your system. Even with standards,
|
||||||
@@ -45,192 +36,292 @@
|
|||||||
# See: http://creativecommons.org/licenses/by-sa/3.0/
|
# See: http://creativecommons.org/licenses/by-sa/3.0/
|
||||||
|
|
||||||
|
|
||||||
SHELL= /bin/sh
|
#############################
|
||||||
CAT= cat
|
# shell used by this Makefile
|
||||||
RM= rm
|
#############################
|
||||||
SED= sed
|
|
||||||
TRUE= true
|
|
||||||
#CINCLUDE= -I ${HOMEBREW_PREFIX}/include/SDL2
|
|
||||||
|
|
||||||
# optimization
|
|
||||||
#
|
#
|
||||||
# Most compiles will safely use -O2. Some can use only -O.
|
SHELL= bash
|
||||||
# A few compilers have broken optimizers and thus you may
|
|
||||||
# not want anything.
|
#######################
|
||||||
|
# common tool locations
|
||||||
|
#######################
|
||||||
|
#
|
||||||
|
include ../../var.mk
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Common C compiler warnings to silence
|
||||||
|
#
|
||||||
|
#CSILENCE=
|
||||||
|
CSILENCE= -Wno-empty-body -Wno-pointer-sign -Wno-return-type
|
||||||
|
|
||||||
|
# Common C compiler warning flags
|
||||||
|
#
|
||||||
|
#CWARN= ${CSILENCE}
|
||||||
|
#CWARN= -Wall ${CSILENCE}
|
||||||
|
CWARN= -Wall -Wextra ${CSILENCE}
|
||||||
|
#CWARN= -Wall -Wextra -pedantic ${CSILENCE}
|
||||||
|
|
||||||
|
# Compiler standard
|
||||||
|
#
|
||||||
|
#CSTD=
|
||||||
|
#CSTD= -ansi
|
||||||
|
CSTD= -std=gnu99
|
||||||
|
|
||||||
|
# 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} -I ${X11_INCDIR}/X11
|
||||||
|
#CINCLUDE= `${SDL2_CONFIG} --cflags`
|
||||||
|
|
||||||
|
# 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=
|
||||||
#OPT= -O
|
#OPT= -O
|
||||||
OPT= -O2
|
#OPT= -O1
|
||||||
|
#OPT= -O2
|
||||||
|
OPT= -O3
|
||||||
|
|
||||||
# flags for ANSI compiles
|
# Default flags for ANSI C compilation
|
||||||
#
|
#
|
||||||
# NOTE: Some ANSI compilers make use of -Xa to turn on ANSI mode,
|
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
|
||||||
# others such as gcc may want -ansi, others (Compaq Tru64 Unix)
|
|
||||||
# want -std1, and others may want nothing at all.
|
|
||||||
# Adjust the CFLAGS line as needed.
|
|
||||||
#
|
|
||||||
# NOTE: Some compilers cannot optimize, or optimize some entries
|
|
||||||
# incorrectly. You might want to turn on -O to see if your
|
|
||||||
# compiler can handle them.
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#CFLAGS= -Xa ${OPT}
|
|
||||||
#CFLAGS= -std1 $(OPT)
|
|
||||||
CFLAGS= -ansi ${OPT}
|
|
||||||
|
|
||||||
# NOTE: On some systems, the library path does not include the location
|
# Libraries needed to build
|
||||||
# of the X11 libraries. You might need to use a -L/path/to/X11/lib/dir
|
|
||||||
# in order to compile with these libs.
|
|
||||||
#
|
#
|
||||||
X11CCFLAGS= -I/usr/X11R6/include -I/usr/X11R6/include/X11 -I/usr/include/X11
|
LIBS=
|
||||||
#X11CCFLAGS=
|
#LIBS= -lm
|
||||||
X11LDFLAGS= -L/usr/X11R6/lib -Wl,-R/usr/X11R6/lib
|
#LIBS= -L ${X11_LIBDIR} -lX11
|
||||||
#X11LDFLAGS=
|
#LIBS= `${SDL2_CONFIG} --libs`
|
||||||
|
|
||||||
# ANSI compiler
|
# C compiler to use
|
||||||
#
|
|
||||||
# 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= cc
|
||||||
MAY_NEED_GCC= gcc
|
#CC=clang
|
||||||
|
#CC=gcc
|
||||||
|
|
||||||
# winners that compile under ANSI C
|
# Compiler add-ons or replacements for clang only
|
||||||
#
|
#
|
||||||
WINNERS= anonymous bellard bellard.otccex cheong coupard \
|
ifeq ($(CC),clang)
|
||||||
ctk dgbeards herrmann1 herrmann2 jason kev ollinger rosten \
|
|
||||||
schweikh westley williams
|
|
||||||
ALT_NAMES= westley.orig
|
|
||||||
DATA_FILES= anonymous_files bellard_files herrmann1_files herrmann2_files
|
|
||||||
|
|
||||||
|
|
||||||
all: ${WINNERS}
|
|
||||||
|
|
||||||
# Most likely to amaze
|
|
||||||
#
|
#
|
||||||
anonymous: anonymous.c
|
CSILENCE+= -Wno-implicit-int-conversion -Wno-missing-prototypes \
|
||||||
magic='${MAY_NEED_GCC} -O1'; \
|
-Wno-missing-variable-declarations -Wno-pedantic \
|
||||||
X='-DA(X)=#X'; \
|
-Wno-poison-system-directories -Wno-sign-conversion -Wno-strict-prototypes
|
||||||
warning='-pedantic -Dprocessor'; \
|
|
||||||
$$magic $$warning -Dmagic= $$X "-DX=A($$magic \"$$X\")" \
|
|
||||||
-o anonymous anonymous.c
|
|
||||||
|
|
||||||
anonymous_files: anonymous.ten.c
|
|
||||||
|
|
||||||
# Best abuse of the rules
|
|
||||||
#
|
#
|
||||||
bellard: bellard.c
|
CWARN+= -Weverything
|
||||||
${CC} -rdynamic ${CFLAGS} bellard.c -o bellard -ldl
|
|
||||||
|
|
||||||
bellard_files: bellard.otccex.c
|
|
||||||
|
|
||||||
# Best short program
|
|
||||||
#
|
#
|
||||||
cheong: cheong.c
|
endif
|
||||||
${CC} ${CFLAGS} cheong.c -o cheong
|
|
||||||
|
|
||||||
# Most obfuscated sound
|
# Specific add-ons or replacements for gcc only
|
||||||
#
|
#
|
||||||
coupard: coupard.c
|
ifeq ($(CC),gcc)
|
||||||
${CC} ${CFLAGS} -o coupard coupard.c
|
|
||||||
|
|
||||||
# Worst Driver
|
|
||||||
#
|
#
|
||||||
ctk: ctk.c
|
#CSILENCE+=
|
||||||
${CC} ${CFLAGS} -o ctk ctk.c
|
|
||||||
|
|
||||||
# Worst AI
|
|
||||||
#
|
#
|
||||||
dgbeards: dgbeards.c
|
#CWARN+=
|
||||||
${CC} ${CFLAGS} -DE=break -DF=char -DK=case -DP=int -DR=return \
|
|
||||||
-DI=0xFFFF dgbeards.c -o dgbeards
|
|
||||||
|
|
||||||
# Best abuse of the C preprocessor
|
|
||||||
#
|
#
|
||||||
herrmann1: herrmann1.c herrmann1.sh
|
endif
|
||||||
@echo "NOTE: $@ must be built/run using the script $@.sh"
|
|
||||||
${SHELL} ./herrmann1.sh
|
|
||||||
|
|
||||||
herrmann1_files: herrmann1.gcd herrmann1.sh herrmann1.times2
|
|
||||||
|
|
||||||
# Most eye-crossing
|
##############################
|
||||||
|
# Special flags for this entry
|
||||||
|
##############################
|
||||||
#
|
#
|
||||||
# This entry requires the GCC -include feature.
|
ENTRY= coupard
|
||||||
|
PROG= ${ENTRY}
|
||||||
#
|
#
|
||||||
herrmann2: herrmann2.c
|
OBJ= ${PROG}.o
|
||||||
${MAY_NEED_GCC} ${CFLAGS} herrmann2.c -o herrmann2 \
|
DATA=
|
||||||
-include /usr/include/stdlib.h -include /usr/include/stdio.h \
|
TARGET= ${PROG}
|
||||||
-include /usr/include/time.h -include /usr/include/unistd.h
|
|
||||||
|
|
||||||
herrmann2_files: herrmann2.cup herrmann2.ioccc
|
|
||||||
|
|
||||||
# Best Of Show
|
|
||||||
#
|
#
|
||||||
jason: jason.c
|
ALT_OBJ=
|
||||||
${CC} ${CFLAGS} -o jason jason.c
|
ALT_TARGET=
|
||||||
|
|
||||||
# Best Curses Game
|
|
||||||
|
#################
|
||||||
|
# build the entry
|
||||||
|
#################
|
||||||
#
|
#
|
||||||
kev: kev.c
|
all: data ${TARGET}
|
||||||
${CC} ${CFLAGS} -DPORT=5455 -DSPEED=50 -o kev kev.c \
|
|
||||||
-lcurses -ltermcap \
|
|
||||||
-Dl_="socket(il.sin_family=AF_INET,SOCK_STREAM,0)"
|
|
||||||
|
|
||||||
# Best primal ASCII graphics
|
|
||||||
#
|
|
||||||
ollinger: ollinger.c
|
|
||||||
${CC} ${CFLAGS} ollinger.c -o ollinger
|
|
||||||
|
|
||||||
# Best abuse of the user
|
|
||||||
#
|
|
||||||
rosten: rosten.c
|
|
||||||
${CC} ${CFLAGS} rosten.c ${X11CCFLAGS} ${X11LDFLAGS} -pedantic -lX11 \
|
|
||||||
-o rosten
|
|
||||||
|
|
||||||
# Best one-liner
|
|
||||||
#
|
|
||||||
schweikh: schweikh.c
|
|
||||||
${CC} ${CFLAGS} schweikh.c -o schweikh
|
|
||||||
|
|
||||||
# Best position-independant code
|
|
||||||
#
|
|
||||||
westley: westley.c
|
|
||||||
${CC} ${CFLAGS} westley.c -o westley
|
|
||||||
|
|
||||||
westley.orig: westley.orig.c
|
|
||||||
${CC} ${CFLAGS} westley.orig.c -o westley.orig
|
|
||||||
|
|
||||||
# Best position-independant code
|
|
||||||
#
|
|
||||||
williams: williams.c
|
|
||||||
${CC} williams.c ${X11CCFLAGS} ${X11LDFLAGS} -lX11 -o williams
|
|
||||||
|
|
||||||
everything: ${WINNERS} ${ALT_NAMES} ${DATA_FILES}
|
|
||||||
|
|
||||||
love:
|
|
||||||
@echo 'not war?'
|
|
||||||
|
|
||||||
haste:
|
|
||||||
${MAKE} waste
|
|
||||||
|
|
||||||
waste:
|
|
||||||
@echo 'waste'
|
|
||||||
|
|
||||||
clean:
|
|
||||||
${RM} -f *.o a.out core ${WINNERS}
|
|
||||||
|
|
||||||
clobber: clean
|
|
||||||
${RM} -f ${WINNERS}
|
|
||||||
${RM} -f ${ALT_NAMES}
|
|
||||||
|
|
||||||
nuke: clobber
|
|
||||||
@${TRUE}
|
@${TRUE}
|
||||||
|
|
||||||
install: all
|
.PHONY: all alt data everything clean clobber install \
|
||||||
${CAT} ${WINNERS} ${ALT_NAMES} > /dev/null
|
love haste waste maker easter_egg sandwich \
|
||||||
|
supernova deep_magic magic charon pluto
|
||||||
|
|
||||||
|
${PROG}: ${PROG}.c
|
||||||
|
${CC} ${CFLAGS} $< -o $@ ${LIBS}
|
||||||
|
|
||||||
|
# alternative executable
|
||||||
|
#
|
||||||
|
alt: data ${ALT_TARGET}
|
||||||
|
@${TRUE}
|
||||||
|
|
||||||
|
# data files
|
||||||
|
#
|
||||||
|
data: ${DATA}
|
||||||
|
@${TRUE}
|
||||||
|
|
||||||
|
# both all and alt
|
||||||
|
#
|
||||||
|
everything: all alt
|
||||||
|
|
||||||
|
|
||||||
|
###############
|
||||||
|
# utility rules
|
||||||
|
###############
|
||||||
|
#
|
||||||
|
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
|
||||||
|
|
||||||
|
install:
|
||||||
|
@echo "Dr. Spock says that is not logical!"
|
||||||
|
@${TRUE}
|
||||||
|
|
||||||
|
# you may be able to misunderstand 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 tool 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}
|
||||||
|
|
||||||
|
maker:
|
||||||
|
@echo 'Participate in a maker faire'
|
||||||
|
@${TRUE}
|
||||||
|
|
||||||
|
easter_egg:
|
||||||
|
@echo "you expected to often misunderstand this $${RANDOM} magic"
|
||||||
|
@echo "chongo '<was here>' /\\oo/\\"
|
||||||
|
@echo "Eggy"
|
||||||
|
|
||||||
|
sandwich: easter_egg
|
||||||
|
@if [ `id -u` -eq 0 ]; then \
|
||||||
|
echo 'Okay.'; \
|
||||||
|
echo "$${RANDOM}`date +%s`$${RANDOM}" > $@; \
|
||||||
|
else \
|
||||||
|
echo 'What? 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: sandwich
|
||||||
|
@-if [ -r .code_anal ]; then \
|
||||||
|
${RM} -f .code_anal_v6; \
|
||||||
|
else \
|
||||||
|
echo "planet deniers, like some members of the IAU, are so cute when they try to defend their logic"; \
|
||||||
|
fi
|
||||||
|
@echo "A $@ helps ${MAKE} the elements that help form planets"
|
||||||
|
@${TRUE}
|
||||||
|
|
||||||
|
deep_magic: supernova
|
||||||
|
@-if [ -r .code_anal ]; then \
|
||||||
|
ccode_analysis --deep_magic 7889066cdbdf09b0408021754586e895be641cc9be29e7eafd3ca65359541f17 \
|
||||||
|
--FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \
|
||||||
|
else \
|
||||||
|
echo "Wrong! Do it again!"; \
|
||||||
|
sleep 2; \
|
||||||
|
echo "Wrong! Do it again!"; \
|
||||||
|
sleep 2; \
|
||||||
|
echo "Wrong! Do it again!"; \
|
||||||
|
fi
|
||||||
|
@${TRUE}
|
||||||
|
|
||||||
|
magic: deep_magic
|
||||||
|
@-if [ -r .code_anal ]; then \
|
||||||
|
ccode_analysis --level 20003 --mode 5717175 --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \
|
||||||
|
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?!"; \
|
||||||
|
fi
|
||||||
|
@${TRUE}
|
||||||
|
|
||||||
|
# The IOCCC resident astronomer states
|
||||||
|
#
|
||||||
|
charon: magic
|
||||||
|
@echo "$@ is a dwarf planet"
|
||||||
|
@echo "dwarf is a type of planet"
|
||||||
|
@echo "therefore IAU, $@ is a planet"
|
||||||
|
|
||||||
|
pluto: charon
|
||||||
|
${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 supernovae can help ${MAKE} a lot of them"
|
||||||
+105
-93
@@ -1,4 +1,4 @@
|
|||||||
Most obfuscated sound:
|
# Most obfuscated sound:
|
||||||
|
|
||||||
Pierre-Philippe Coupard
|
Pierre-Philippe Coupard
|
||||||
Lineo, Inc.
|
Lineo, Inc.
|
||||||
@@ -7,130 +7,142 @@ Most obfuscated sound:
|
|||||||
Lindon, UT 84042
|
Lindon, UT 84042
|
||||||
USA
|
USA
|
||||||
|
|
||||||
|
# To build:
|
||||||
|
|
||||||
Judges' Comments:
|
```sh
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
To build:
|
### To run:
|
||||||
|
|
||||||
make coupard
|
```sh
|
||||||
|
./coupard
|
||||||
|
```
|
||||||
|
|
||||||
Try:
|
### Try:
|
||||||
|
|
||||||
./coupard > /dev/audio
|
```sh
|
||||||
-or-
|
./coupard > /dev/audio
|
||||||
./coupard > /dev/sound/dsp
|
-or-
|
||||||
|
./coupard > /dev/sound/dsp
|
||||||
|
```
|
||||||
|
|
||||||
You may need to run this a few times to understand exactly what is
|
## Judges' comments:
|
||||||
being said. You might even need to look somewhere on your desktop,
|
|
||||||
your arm or the wall for confirmation.
|
|
||||||
|
|
||||||
|
You may need to run this a few times to understand exactly what is
|
||||||
|
being said. You might even need to look somewhere on your desktop,
|
||||||
|
your arm or the wall for confirmation.
|
||||||
|
|
||||||
Selected Author's Comments:
|
## Author's comments:
|
||||||
|
|
||||||
Past years' IOCCC entries do many marvellous things in small packages,
|
Past years' IOCCC entries do many marvellous things in small packages,
|
||||||
such as console utilities, games, math, languages or even X
|
such as console utilities, games, math, languages or even X
|
||||||
applications. But they all have one thing in common (despite being hard
|
applications. But they all have one thing in common (despite being hard
|
||||||
to read obviously) : when they interact with the user, they only
|
to read obviously) : when they interact with the user, they only
|
||||||
*display* things, i.e. they display either text or drawings.
|
*display* things, i.e. they display either text or drawings.
|
||||||
|
|
||||||
So, for a change, this program titillates the sense of hearing instead
|
So, for a change, this program titillates the sense of hearing instead
|
||||||
of sight : this program is a self-contained speech synthesizer that
|
of sight : this program is a self-contained speech synthesizer that
|
||||||
tells the current time through the computer's sound card - in just under
|
tells the current time through the computer's sound card - in just under
|
||||||
2 Kb of source code !
|
2 Kb of source code !
|
||||||
|
|
||||||
In the 2001 IOCCC rules and guidelines documents, there is no mention of
|
In the 2001 IOCCC rules and guidelines documents, there is no mention of
|
||||||
what is or isn't acceptable regarding audio I/Os, but it is mentioned
|
what is or isn't acceptable regarding audio I/Os, but it is mentioned
|
||||||
that hardware-specific and/or non-portable programs are not welcome. So,
|
that hardware-specific and/or non-portable programs are not welcome. So,
|
||||||
in order to do audio and satisfy those requirements, the format required
|
in order to do audio and satisfy those requirements, the format required
|
||||||
by /dev/audio has been chosen : /dev/audio is a rather ancient
|
by /dev/audio has been chosen : /dev/audio is a rather ancient
|
||||||
fixed-format audio interface that is supported by the majority of Unices
|
fixed-format audio interface that is supported by the majority of Unices
|
||||||
that can do sound, as a lowest-denominator sound I/Os interface.
|
that can do sound, as a lowest-denominator sound I/Os interface.
|
||||||
|
|
||||||
Program usage :
|
### Program usage:
|
||||||
|
|
||||||
* To listen to what the program says directly, invoke
|
* To listen to what the program says directly, invoke
|
||||||
|
|
||||||
./coupard > /dev/audio
|
```sh
|
||||||
|
./coupard > /dev/audio
|
||||||
|
```
|
||||||
|
|
||||||
the program then speaks out something like
|
the program then speaks out something like
|
||||||
|
|
||||||
"The time is HH hours MM minutes SS seconds"
|
"The time is HH hours MM minutes SS seconds"
|
||||||
|
|
||||||
in military time (24 hours). Of course, you need to have permissions
|
in military time (24 hours). Of course, you need to have permissions
|
||||||
to write to /dev/audio, have your sound card enabled, the volume up,
|
to write to /dev/audio, have your sound card enabled, the volume up,
|
||||||
the speakers connected ... :-)
|
the speakers connected ... :-)
|
||||||
|
|
||||||
* If you want to convert the audio output of the program into another
|
* If you want to convert the audio output of the program into another
|
||||||
audio format, you can pipe it to sox for example (sox is the
|
audio format, you can pipe it to sox for example (sox is the
|
||||||
Swiss army knife of Unix audio tools) : the command
|
Swiss army knife of Unix audio tools) : the command
|
||||||
|
|
||||||
./coupard | sox -c1 -r8000 -tub - -c2 -r44100 -twav test.wav
|
```sh
|
||||||
|
./coupard | sox -c1 -r8000 -tub - -c2 -r44100 -twav test.wav
|
||||||
|
```
|
||||||
|
|
||||||
converts the output of the program into a 44.1KHz stereo .WAV
|
converts the output of the program into a 44.1KHz stereo .WAV
|
||||||
file and saves it into "test.wav".
|
file and saves it into "test.wav".
|
||||||
|
|
||||||
The output format of the program is 8KHz, unsigned 8-bit samples.
|
The output format of the program is 8KHz, unsigned 8-bit samples.
|
||||||
|
|
||||||
NOTE : the program's return code is meaningless
|
NOTE : the program's return code is meaningless
|
||||||
|
|
||||||
Audio quality :
|
### Audio quality:
|
||||||
|
|
||||||
The quality of the sound produced by the program is cross between a
|
The quality of the sound produced by the program is cross between a
|
||||||
yogurt-pot-and-string telephone and a bad gramophone, i.e. the S/N
|
yogurt-pot-and-string telephone and a bad gramophone, i.e. the S/N
|
||||||
ratio is very low and the signal's top frequency is very low as well.
|
ratio is very low and the signal's top frequency is very low as well.
|
||||||
This is because the audio is stored internally at a sampling rate of
|
This is because the audio is stored internally at a sampling rate of
|
||||||
4KHz (the Nyquist frequency is only 2KHz) with only 4-bit samples
|
4KHz (the Nyquist frequency is only 2KHz) with only 4-bit samples
|
||||||
(adding 24db of quantization noise to an already poor signal).
|
(adding 24db of quantization noise to an already poor signal).
|
||||||
|
|
||||||
In short, you might have to listen twice to understand what the
|
In short, you might have to listen twice to understand what the
|
||||||
program is saying. 2048 bytes including the sound generation program
|
program is saying. 2048 bytes including the sound generation program
|
||||||
doesn't leave much room for audio quality ;-)
|
doesn't leave much room for audio quality ;-)
|
||||||
|
|
||||||
Speech generation :
|
### Speech generation:
|
||||||
|
|
||||||
Only 9 phonemes are used to generate the speech. Beside the limited
|
Only 9 phonemes are used to generate the speech. Beside the limited
|
||||||
number of words the program has to generate (66 words), the low sound
|
number of words the program has to generate (66 words), the low sound
|
||||||
quality is actually exploited to take liberties with certain
|
quality is actually exploited to take liberties with certain
|
||||||
consonants (for example, "s" and "f" sound very much the same at 4KHz,
|
consonants (for example, "s" and "f" sound very much the same at 4KHz,
|
||||||
so they can be merged into one phoneme). Because the psychoacoustic
|
so they can be merged into one phoneme). Because the psychoacoustic
|
||||||
context around those phonemes is just sufficient, the words can be
|
context around those phonemes is just sufficient, the words can be
|
||||||
interpreted correctly most of the time despite the fact that they are
|
interpreted correctly most of the time despite the fact that they are
|
||||||
pronounced quite wrongly.
|
pronounced quite wrongly.
|
||||||
|
|
||||||
Internally, a table is used to generate most of the words, and
|
Internally, a table is used to generate most of the words, and
|
||||||
composite words such as "thirty-five" are made up by the C code
|
composite words such as "thirty-five" are made up by the C code
|
||||||
externally.
|
externally.
|
||||||
|
|
||||||
Data compression :
|
### Data compression:
|
||||||
|
|
||||||
Even at 4KHz / 4 bits, the weight of all the phoneme samples and the
|
Even at 4KHz / 4 bits, the weight of all the phoneme samples and the
|
||||||
word-to-phonemes table put together is over 1600 bytes, which is well
|
word-to-phonemes table put together is over 1600 bytes, which is well
|
||||||
over 2048 bytes when encoded in a C string made of printable
|
over 2048 bytes when encoded in a C string made of printable
|
||||||
characters. Therefore, a compression method was needed that's both
|
characters. Therefore, a compression method was needed that's both
|
||||||
efficient and with a decompressor that is implementable in the
|
efficient and with a decompressor that is implementable in the
|
||||||
shortest amount of code possible. GSM compression is very good, but
|
shortest amount of code possible. GSM compression is very good, but
|
||||||
needs large psychoacoustic tables to regenerate the original
|
needs large psychoacoustic tables to regenerate the original
|
||||||
signal. Raw FFT spectral compression is efficient too, but the
|
signal. Raw FFT spectral compression is efficient too, but the
|
||||||
decompression code can't be made small enough.
|
decompression code can't be made small enough.
|
||||||
|
|
||||||
The best compression compromise was found using a simple Huffman
|
The best compression compromise was found using a simple Huffman
|
||||||
compressor, and encoding the compressed data by blocks of 13 bits in
|
compressor, and encoding the compressed data by blocks of 13 bits in
|
||||||
pairs of printable ASCII characters : the raw data is compressed to
|
pairs of printable ASCII characters : the raw data is compressed to
|
||||||
8465 bits, and the resulting C string is therefore about 1300
|
8465 bits, and the resulting C string is therefore about 1300
|
||||||
characters, which leaves just enough room for the decompressor with a
|
characters, which leaves just enough room for the decompressor with a
|
||||||
hard-coded Huffman tree, and the code that plays the phonemes in the
|
hard-coded Huffman tree, and the code that plays the phonemes in the
|
||||||
right order.
|
right order.
|
||||||
|
|
||||||
Note on compiler warnings and lint :
|
### Note on compiler warnings and lint:
|
||||||
|
|
||||||
The program should build with gcc's -Wall -Werror and -ansi flags. If
|
The program should build with gcc's -Wall -Werror and -ansi flags. If
|
||||||
the -pedantic flag is used, gcc will complain about the length of the
|
the -pedantic flag is used, gcc will complain about the length of the
|
||||||
data string and the sign of its type, and also the fact that main()
|
data string and the sign of its type, and also the fact that main()
|
||||||
returns with no value. The confusion with the sign of the char type
|
returns with no value. The confusion with the sign of the char type
|
||||||
doesn't matter with the data string because it's composed only of
|
doesn't matter with the data string because it's composed only of
|
||||||
printable characters under 127.
|
printable characters under 127.
|
||||||
|
|
||||||
When linting the program with lclint, it complains about a huge list
|
When linting the program with lclint, it complains about a huge list
|
||||||
of things that, if corrected to make lint happy, would probably double
|
of things that, if corrected to make lint happy, would probably double
|
||||||
the size of the source code.
|
the size of the source code.
|
||||||
|
|
||||||
Reference in new issue
Block a user