/* bytebeat.c - minimal bytebeat generator
 * Outputs unsigned 8-bit PCM at 8000 Hz to stdout.
 * Compile: gcc -O2 -o bytebeat bytebeat.c
 * Run:     ./bytebeat > /dev/audio
 *      or: ./bytebeat | aplay -r 8000 -f U8 -c 1
 */

#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char **argv)
{
  unsigned long t = 0;
  int c;

  /* limit duration in seconds (default: infinite) */
  unsigned long max = (argc > 1) ? (unsigned long) atoi (argv[1]) * 8000UL : 0;

  for (;;)
    {
      /* DON'T REMOVE THIS COMMENT ;;;FORMULA */
      c = (int) ((t * (((t >> 12) | (t >> 8)) & (63 & (t >> 4)))) & 0xFF);

      if (putchar (c) == EOF)
        break;
      t++;
      if (max && t >= max)
        break;
    }
  return 0;
}
