Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

player.c 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Audio player for the phytotron
  3. */
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <fcntl.h>
  8. #include <ao/ao.h>
  9. #include <sndfile.h>
  10. /* --------------------------------------------------------------------- */
  11. #define T_BUFF_WAVES (8192*4)
  12. #define T_FNAME 1000
  13. static ao_device *device;
  14. static ao_sample_format format;
  15. static int coefficient;
  16. static int16_t buffer[T_BUFF_WAVES];
  17. /* --------------------------------------------------------------------- */
  18. int init_waveout(int smplrate)
  19. {
  20. int default_driver;
  21. ao_initialize();
  22. default_driver = ao_default_driver_id();
  23. #if DEBUG_LEVEL
  24. fprintf(stderr, "%s : ao default driver #%d\n", __func__, default_driver);
  25. #endif
  26. memset(&format, 0, sizeof(format));
  27. format.bits = 16;
  28. format.channels = 2;
  29. format.rate = smplrate;
  30. format.byte_format = AO_FMT_LITTLE;
  31. device = ao_open_live(default_driver, &format, NULL);
  32. if (device == NULL) {
  33. fprintf(stderr, "Error opening AO device.\n");
  34. return -1;
  35. }
  36. return 0;
  37. }
  38. /* --------------------------------------------------------------------- */
  39. int close_waveout(void)
  40. {
  41. ao_close(device);
  42. ao_shutdown();
  43. return 0;
  44. }
  45. /* --------------------------------------------------------------------- */
  46. int blast_this_file(char *fname)
  47. {
  48. SNDFILE *sndf;
  49. SF_INFO sfinfo;
  50. int foo, lus;
  51. sndf = sf_open(fname, SFM_READ, &sfinfo);
  52. if (NULL==sndf)
  53. {
  54. perror("sf_open");
  55. abort();
  56. }
  57. #if DEBUG_LEVEL
  58. fprintf(stderr, "samplerate : %d\n", sfinfo.samplerate);
  59. fprintf(stderr, "frames : %ld\n", sfinfo.frames);
  60. fprintf(stderr, "seekable : %d\n", sfinfo.seekable);
  61. #endif
  62. while ((lus = sf_read_short(sndf, buffer, T_BUFF_WAVES)))
  63. {
  64. #if DEBUG_LEVEL
  65. fprintf(stderr, "%s : %d bytes read\n", fname, lus);
  66. #endif
  67. }
  68. /* do some cleanup */
  69. sf_close(sndf);
  70. return -1;
  71. }
  72. /* --------------------------------------------------------------------- */
  73. /* --------------------------------------------------------------------- */