logo

bytemedia

Home to byte-level sounds, images, videos, … git clone https://hacktivis.me/git/bytemedia.git

2022-02-06.c (943B)


  1. #define _XOPEN_SOURCE 700
  2. #include <stdio.h>
  3. #include <inttypes.h> // uint32_t
  4. #include <math.h> // sinf(), M_PI, pow()
  5. #include "au.h"
  6. int
  7. main(void)
  8. {
  9. // Use AU defaults
  10. struct au_header header = {
  11. .offset = 24, // no-annotation, in octets
  12. .length = 0,
  13. .encoding = AU_ENCODING_8B_LPCM,
  14. .samplerate = 44000, // Hz
  15. .channels = 1
  16. };
  17. char buf[4];
  18. int32_t t;
  19. // fd 1 is stdout
  20. write_au_header(1, &header);
  21. //for(t = 0;;t++) {
  22. for(t = 0;t<header.samplerate*60;t++) {
  23. float tune;
  24. int freq = 140;
  25. //int freq = 180 + (t / (header.samplerate / 666) % 10);
  26. int phase = t >> 5;
  27. int volume = 20;
  28. tune = sinf(t * 2*M_PI * (freq + ((t>>3) % 300))/header.samplerate) * volume/9;
  29. //tune += sinf(t * 2*M_PI * (freq + ((t>>5) % 600))/header.samplerate) * volume/3;
  30. tune += sinf(t * 2*M_PI * (freq + ((713&t>>(t/header.samplerate/3)) % 2000))/header.samplerate) * volume/2;
  31. putchar((uint8_t)(tune));
  32. }
  33. return 0;
  34. }