logo

bytemedia

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

battery_low.c (1091B)


  1. #define _XOPEN_SOURCE 700
  2. #include <stdio.h>
  3. #include <inttypes.h> // uint32_t
  4. #include "au.h"
  5. #include "misc.h"
  6. #include "instruments.h"
  7. #include "effects.h"
  8. void
  9. note(int dur, struct au_header *header, int hertz, float volume) {
  10. char buf[4];
  11. for(int t = 0;t<dur;t++) {
  12. //float tune = pure_sin(header, hertz, t);
  13. float tune = clarinet(header, hertz, t);
  14. float vol = crossfade(dur, t, volume);
  15. putchar((uint8_t)(tune * vol));
  16. }
  17. }
  18. int
  19. main(void)
  20. {
  21. // Use AU defaults
  22. struct au_header header = {
  23. .offset = 24, // no-annotation, in octets
  24. .length = 0xFFFFFFFF, // unknown data size
  25. .encoding = AU_ENCODING_8B_LPCM,
  26. .samplerate = 48000, // Hz
  27. .channels = 1
  28. };
  29. header.length = header.samplerate;
  30. // fd 1 is stdout
  31. write_au_header(1, &header);
  32. int volume = 60;
  33. int ref_tune = 440;
  34. note(header.samplerate/4, &header, note_to_hertz(ref_tune, 2-8), volume);
  35. note(header.samplerate/4, &header, note_to_hertz(ref_tune, 3-8), volume*0.9);
  36. note(header.samplerate/4, &header, note_to_hertz(ref_tune, 0-8), volume*0.7);
  37. silence(header.samplerate/4);
  38. return 0;
  39. }