beep.c 983 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2014 K. Lange
  5. */
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <fcntl.h>
  9. int spkr = 0;
  10. struct spkr {
  11. int length;
  12. int frequency;
  13. };
  14. void note(int length, int frequency) {
  15. struct spkr s = {
  16. .length = length,
  17. .frequency = frequency,
  18. };
  19. write(spkr, &s, sizeof(s));
  20. }
  21. int main(int argc, char * argv[]) {
  22. spkr = open("/dev/spkr", O_WRONLY);
  23. if (spkr == -1) {
  24. fprintf(stderr, "%s: could not open speaker\n", argv[0]);
  25. }
  26. note(20, 15680);
  27. note(10, 11747);
  28. note(10, 12445);
  29. note(20, 13969);
  30. note(10, 12445);
  31. note(10, 11747);
  32. note(20, 10465);
  33. note(10, 10465);
  34. note(10, 12445);
  35. note(20, 15680);
  36. note(10, 13969);
  37. note(10, 12445);
  38. note(30, 11747);
  39. note(10, 12445);
  40. note(20, 13969);
  41. note(20, 15680);
  42. note(20, 12445);
  43. note(20, 10465);
  44. note(20, 10465);
  45. return 0;
  46. }