Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
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.

156 lines
4.8 KiB

  1. /* $OpenBSD: sndio.h,v 1.9 2015/12/20 11:29:29 ratchov Exp $ */
  2. /*
  3. * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef SNDIO_H
  18. #define SNDIO_H
  19. #include <sys/types.h>
  20. /*
  21. * default audio device and MIDI port
  22. */
  23. #define SIO_DEVANY "default"
  24. #define MIO_PORTANY "default"
  25. /*
  26. * private ``handle'' structure
  27. */
  28. struct sio_hdl;
  29. struct mio_hdl;
  30. /*
  31. * parameters of a full-duplex stream
  32. */
  33. struct sio_par {
  34. unsigned int bits; /* bits per sample */
  35. unsigned int bps; /* bytes per sample */
  36. unsigned int sig; /* 1 = signed, 0 = unsigned */
  37. unsigned int le; /* 1 = LE, 0 = BE byte order */
  38. unsigned int msb; /* 1 = MSB, 0 = LSB aligned */
  39. unsigned int rchan; /* number channels for recording direction */
  40. unsigned int pchan; /* number channels for playback direction */
  41. unsigned int rate; /* frames per second */
  42. unsigned int bufsz; /* end-to-end buffer size */
  43. #define SIO_IGNORE 0 /* pause during xrun */
  44. #define SIO_SYNC 1 /* resync after xrun */
  45. #define SIO_ERROR 2 /* terminate on xrun */
  46. unsigned int xrun; /* what to do on overruns/underruns */
  47. unsigned int round; /* optimal bufsz divisor */
  48. unsigned int appbufsz; /* minimum buffer size */
  49. int __pad[3]; /* for future use */
  50. unsigned int __magic; /* for internal/debug purposes only */
  51. };
  52. /*
  53. * capabilities of a stream
  54. */
  55. struct sio_cap {
  56. #define SIO_NENC 8
  57. #define SIO_NCHAN 8
  58. #define SIO_NRATE 16
  59. #define SIO_NCONF 4
  60. struct sio_enc { /* allowed sample encodings */
  61. unsigned int bits;
  62. unsigned int bps;
  63. unsigned int sig;
  64. unsigned int le;
  65. unsigned int msb;
  66. } enc[SIO_NENC];
  67. unsigned int rchan[SIO_NCHAN]; /* allowed values for rchan */
  68. unsigned int pchan[SIO_NCHAN]; /* allowed values for pchan */
  69. unsigned int rate[SIO_NRATE]; /* allowed rates */
  70. int __pad[7]; /* for future use */
  71. unsigned int nconf; /* number of elements in confs[] */
  72. struct sio_conf {
  73. unsigned int enc; /* mask of enc[] indexes */
  74. unsigned int rchan; /* mask of chan[] indexes (rec) */
  75. unsigned int pchan; /* mask of chan[] indexes (play) */
  76. unsigned int rate; /* mask of rate[] indexes */
  77. } confs[SIO_NCONF];
  78. };
  79. #define SIO_XSTRINGS { "ignore", "sync", "error" }
  80. /*
  81. * mode bitmap
  82. */
  83. #define SIO_PLAY 1
  84. #define SIO_REC 2
  85. #define MIO_OUT 4
  86. #define MIO_IN 8
  87. /*
  88. * default bytes per sample for the given bits per sample
  89. */
  90. #define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
  91. /*
  92. * default value of "sio_par->le" flag
  93. */
  94. #if BYTE_ORDER == LITTLE_ENDIAN
  95. #define SIO_LE_NATIVE 1
  96. #else
  97. #define SIO_LE_NATIVE 0
  98. #endif
  99. /*
  100. * maximum value of volume, eg. for sio_setvol()
  101. */
  102. #define SIO_MAXVOL 127
  103. #ifdef __cplusplus
  104. extern "C" {
  105. #endif
  106. struct pollfd;
  107. void sio_initpar(struct sio_par *);
  108. struct sio_hdl *sio_open(const char *, unsigned int, int);
  109. void sio_close(struct sio_hdl *);
  110. int sio_setpar(struct sio_hdl *, struct sio_par *);
  111. int sio_getpar(struct sio_hdl *, struct sio_par *);
  112. int sio_getcap(struct sio_hdl *, struct sio_cap *);
  113. void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *);
  114. size_t sio_write(struct sio_hdl *, const void *, size_t);
  115. size_t sio_read(struct sio_hdl *, void *, size_t);
  116. int sio_start(struct sio_hdl *);
  117. int sio_stop(struct sio_hdl *);
  118. int sio_nfds(struct sio_hdl *);
  119. int sio_pollfd(struct sio_hdl *, struct pollfd *, int);
  120. int sio_revents(struct sio_hdl *, struct pollfd *);
  121. int sio_eof(struct sio_hdl *);
  122. int sio_setvol(struct sio_hdl *, unsigned int);
  123. int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned int), void *);
  124. struct mio_hdl *mio_open(const char *, unsigned int, int);
  125. void mio_close(struct mio_hdl *);
  126. size_t mio_write(struct mio_hdl *, const void *, size_t);
  127. size_t mio_read(struct mio_hdl *, void *, size_t);
  128. int mio_nfds(struct mio_hdl *);
  129. int mio_pollfd(struct mio_hdl *, struct pollfd *, int);
  130. int mio_revents(struct mio_hdl *, struct pollfd *);
  131. int mio_eof(struct mio_hdl *);
  132. int mio_rmidi_getfd(const char *, unsigned int, int);
  133. struct mio_hdl *mio_rmidi_fdopen(int, unsigned int, int);
  134. int sio_sun_getfd(const char *, unsigned int, int);
  135. struct sio_hdl *sio_sun_fdopen(int, unsigned int, int);
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* !defined(SNDIO_H) */