pa_mac_core_blocking.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Internal blocking interfaces for PortAudio Apple AUHAL implementation
  3. *
  4. * PortAudio Portable Real-Time Audio Library
  5. * Latest Version at: http://www.portaudio.com
  6. *
  7. * Written by Bjorn Roche of XO Audio LLC, from PA skeleton code.
  8. * Portions copied from code by Dominic Mazzoni (who wrote a HAL implementation)
  9. *
  10. * Dominic's code was based on code by Phil Burk, Darren Gibbs,
  11. * Gord Peters, Stephane Letz, and Greg Pfiel.
  12. *
  13. * The following people also deserve acknowledgements:
  14. *
  15. * Olivier Tristan for feedback and testing
  16. * Glenn Zelniker and Z-Systems engineering for sponsoring the Blocking I/O
  17. * interface.
  18. *
  19. *
  20. * Based on the Open Source API proposed by Ross Bencina
  21. * Copyright (c) 1999-2002 Ross Bencina, Phil Burk
  22. *
  23. * Permission is hereby granted, free of charge, to any person obtaining
  24. * a copy of this software and associated documentation files
  25. * (the "Software"), to deal in the Software without restriction,
  26. * including without limitation the rights to use, copy, modify, merge,
  27. * publish, distribute, sublicense, and/or sell copies of the Software,
  28. * and to permit persons to whom the Software is furnished to do so,
  29. * subject to the following conditions:
  30. *
  31. * The above copyright notice and this permission notice shall be
  32. * included in all copies or substantial portions of the Software.
  33. *
  34. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  35. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  36. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  37. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  38. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  39. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  40. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  41. */
  42. /*
  43. * The text above constitutes the entire PortAudio license; however,
  44. * the PortAudio community also makes the following non-binding requests:
  45. *
  46. * Any person wishing to distribute modifications to the Software is
  47. * requested to send the modifications to the original developer so that
  48. * they can be incorporated into the canonical version. It is also
  49. * requested that these non-binding requests be included along with the
  50. * license above.
  51. */
  52. /**
  53. @file
  54. @ingroup hostapi_src
  55. */
  56. #ifndef PA_MAC_CORE_BLOCKING_H_
  57. #define PA_MAC_CORE_BLOCKING_H_
  58. #include "pa_ringbuffer.h"
  59. #include "portaudio.h"
  60. #include "pa_mac_core_utilities.h"
  61. /*
  62. * Number of miliseconds to busy wait whil waiting for data in blocking calls.
  63. */
  64. #define PA_MAC_BLIO_BUSY_WAIT_SLEEP_INTERVAL (5)
  65. /*
  66. * Define exactly one of these blocking methods
  67. * PA_MAC_BLIO_MUTEX is not actively maintained.
  68. */
  69. #define PA_MAC_BLIO_BUSY_WAIT
  70. /*
  71. #define PA_MAC_BLIO_MUTEX
  72. */
  73. typedef struct {
  74. PaUtilRingBuffer inputRingBuffer;
  75. PaUtilRingBuffer outputRingBuffer;
  76. size_t ringBufferFrames;
  77. PaSampleFormat inputSampleFormat;
  78. size_t inputSampleSizeActual;
  79. size_t inputSampleSizePow2;
  80. PaSampleFormat outputSampleFormat;
  81. size_t outputSampleSizeActual;
  82. size_t outputSampleSizePow2;
  83. size_t framesPerBuffer;
  84. int inChan;
  85. int outChan;
  86. //PaStreamCallbackFlags statusFlags;
  87. uint32_t statusFlags;
  88. PaError errors;
  89. /* Here we handle blocking, using condition variables. */
  90. #ifdef PA_MAC_BLIO_MUTEX
  91. volatile bool isInputEmpty;
  92. pthread_mutex_t inputMutex;
  93. pthread_cond_t inputCond;
  94. volatile bool isOutputFull;
  95. pthread_mutex_t outputMutex;
  96. pthread_cond_t outputCond;
  97. #endif
  98. }
  99. PaMacBlio;
  100. /*
  101. * These functions operate on condition and related variables.
  102. */
  103. PaError initializeBlioRingBuffers(
  104. PaMacBlio *blio,
  105. PaSampleFormat inputSampleFormat,
  106. PaSampleFormat outputSampleFormat,
  107. size_t framesPerBuffer,
  108. long ringBufferSize,
  109. int inChan,
  110. int outChan );
  111. PaError destroyBlioRingBuffers( PaMacBlio *blio );
  112. PaError resetBlioRingBuffers( PaMacBlio *blio );
  113. int BlioCallback(
  114. const void *input, void *output,
  115. unsigned long frameCount,
  116. const PaStreamCallbackTimeInfo* timeInfo,
  117. PaStreamCallbackFlags statusFlags,
  118. void *userData );
  119. void waitUntilBlioWriteBufferIsFlushed( PaMacBlio *blio );
  120. #endif /*PA_MAC_CORE_BLOCKING_H_*/