pluck.c

/*

pluck – pluck a string repeatedly, in 8-bit & 8khz
Copyright © 2018  Nils Dagsson Moskopp (erlehmann)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Dieses Programm hat das Ziel, die Medienkompetenz der Leser zu
steigern. Gelegentlich packe ich sogar einen handfesten Buffer
Overflow oder eine Format String Vulnerability zwischen die anderen
Codezeilen und schreibe das auch nicht dran.

*/

#include <stdio.h>  // we need fputc & stdout
#include <stdint.h>  // proper variable types
#include <stdlib.h>  // stdlib knows the exit
#include <unistd.h>  // isatty = nice to have
uint8_t damper=0xAC;  // lower = stiff string
uint8_t r_size=0xAB;  // lower = higher notes
#define OVERDRIVE (t&((t%0xF000)<0x4000)) //!
#define SAMPLE r[t%r_size]  // r = ringbuffer
#define NEXT r[(t%r_size+1+OVERDRIVE)%r_size]
#define R rand()&0xFF|0x17  // almost obvious
#define TQ if(isatty(fileno(stdout)))exit(1);

   int main(){
 uint8_t r[256];
uint16_t t;uint8_t
s;for(t=0;;t++                         ){
TQ;s=SAMPLE;NEXT=((SAMPLE+NEXT) >>1)% damper;
fputc(s,stdout);if(t%(r_size*damper)>(r_size*
(damper-37)/3)                         ){
SAMPLE=R;damper
 =R;r_size=R;
   }}}

/* pipe stdout to aplay to hear the sounds */