ref: 3857bca195cc72156c8fa7c64dda78299b8f8054
parent: e87ff1ef2c8d42e13a23dc3e58942093126491ee
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Mar 7 07:49:17 EST 2023
better example: involve reverb
--- a/leaf/plan9_example.c
+++ b/leaf/plan9_example.c
@@ -11,23 +11,30 @@
main(int, char **)
{
LEAF leaf;
- tCycle cycle, cycle2;
- char mem[1000];
+ tDattorroReverb reverb;
+ tCycle cycle, cycle2, cycle3;
+ char *mem;
Biobuf out;
int i;
- LEAF_init(&leaf, 44100, mem, 1000, fandom);
+ setfcr(getfcr() & ~(FPINVAL|FPOVFL));
+ mem = malloc(1*1024*1024);
+ LEAF_init(&leaf, 44100, mem, 1*1024*1024, fandom);
+ tDattorroReverb_init(&reverb, &leaf);
tCycle_init(&cycle, &leaf);
tCycle_init(&cycle2, &leaf);
- tCycle_setFreq(&cycle2, 10);
+ tCycle_init(&cycle3, &leaf);
+ tCycle_setFreq(&cycle3, 5);
Binit(&out, 1, OWRITE);
- for(i = 0; i < 2*44100; i++){
- s16int s[2];
+ for(i = 0; i < 10*44100; i++){
+ float f[2];
+ tCycle_setFreq(&cycle2, 3 + 2*tCycle_tick(&cycle3));
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));
+ tDattorroReverb_tickStereo(&reverb, tCycle_tick(&cycle)/10.0f, f);
+ f[0] /= 2.0f;
+ f[1] /= 2.0f;
+ Bwrite(&out, f, sizeof(f));
}
exits(nil);