ref: ba1cc6be935043feef77df2c069c9e2759786a97
parent: a3746888080f34c0618ec8da0a29eafbc92057ea
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Mar 7 06:56:02 EST 2023
a bit better example; build it on default rule
--- a/leaf/mkfile
+++ b/leaf/mkfile
@@ -1,5 +1,6 @@
</$objtype/mkfile
LIB=libleaf.$objtype.a
+TARG=plan9_example
CFLAGS=$CFLAGS -p -IInc -IExternals -IExternals/plan9 -D__plan9__=1
@@ -54,14 +55,17 @@
LIBOBJ=${OFILES:%=$LIB(%)}
-default:V: $LIB
+default:V: $LIB $TARG
-all:V: $LIB
+all:V: $LIB $TARG
$LIB: $LIBOBJ
ar vu $LIB $newmember
$LIB(%.$O):N: %.$O
+
+$TARG: $TARG.$O
+ $LD $LDFLAGS -o $target $prereq
clean:V:
rm -f */*.[$OS] */*/*.[$OS] *.a
--- a/leaf/plan9_example.c
+++ b/leaf/plan9_example.c
@@ -11,7 +11,7 @@
main(int, char **)
{
LEAF leaf;
- tCycle cycle;
+ tCycle cycle, cycle2;
char mem[1000];
Biobuf out;
int i;
@@ -18,13 +18,14 @@
LEAF_init(&leaf, 44100, mem, 1000, fandom);
tCycle_init(&cycle, &leaf);
- tCycle_setFreq(&cycle, 220);
+ tCycle_init(&cycle2, &leaf);
+ tCycle_setFreq(&cycle2, 10);
Binit(&out, 1, OWRITE);
- for(i = 0; i < 44100; i++){
- float f = tCycle_tick(&cycle);
+ for(i = 0; i < 2*44100; i++){
s16int s[2];
- s[0] = 16384.0f*(f - 0.5f);
+ tCycle_setFreq(&cycle, 800 + 400*tCycle_tick(&cycle2));
+ s[0] = 16384.0f*(tCycle_tick(&cycle) - 0.5f);
s[1] = s[0];
Bwrite(&out, s, sizeof(s));
}