jack2 codebase
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.

218 lines
5.5KB

  1. /*
  2. Copyright (C) 2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifndef __JackAudioAdapterInterface__
  16. #define __JackAudioAdapterInterface__
  17. #include "JackResampler.h"
  18. #include "JackFilters.h"
  19. #include "JackConstants.h"
  20. namespace Jack
  21. {
  22. #ifdef JACK_MONITOR
  23. #define TABLE_MAX 100000
  24. struct Measure
  25. {
  26. int delta;
  27. int time1;
  28. int time2;
  29. float r1;
  30. float r2;
  31. int pos1;
  32. int pos2;
  33. };
  34. struct MeasureTable
  35. {
  36. Measure fTable[TABLE_MAX];
  37. int fCount;
  38. MeasureTable() :fCount ( 0 )
  39. {}
  40. void Write ( int time1, int time2, float r1, float r2, int pos1, int pos2 );
  41. void Save();
  42. };
  43. #endif
  44. /*!
  45. \brief Base class for audio adapters.
  46. */
  47. class JackAudioAdapterInterface
  48. {
  49. protected:
  50. #ifdef JACK_MONITOR
  51. MeasureTable fTable;
  52. #endif
  53. //channels
  54. int fCaptureChannels;
  55. int fPlaybackChannels;
  56. //host parameters
  57. jack_nframes_t fHostBufferSize;
  58. jack_nframes_t fHostSampleRate;
  59. //adapted parameters
  60. jack_nframes_t fAdaptedBufferSize;
  61. jack_nframes_t fAdaptedSampleRate;
  62. //delay locked loop
  63. JackAtomicDelayLockedLoop fHostDLL;
  64. JackAtomicDelayLockedLoop fAdaptedDLL;
  65. JackResampler** fCaptureRingBuffer;
  66. JackResampler** fPlaybackRingBuffer;
  67. unsigned int fQuality;
  68. unsigned int fRingbufferSize;
  69. bool fRunning;
  70. void ResetRingBuffers();
  71. void ResampleFactor ( jack_time_t& frame1, jack_time_t& frame2 );
  72. virtual void SetCallbackTime ( jack_time_t callback_usec )
  73. {
  74. fHostDLL.IncFrame ( callback_usec );
  75. }
  76. public:
  77. JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ):
  78. fCaptureChannels ( 0 ),
  79. fPlaybackChannels ( 0 ),
  80. fHostBufferSize ( buffer_size ),
  81. fHostSampleRate ( sample_rate ),
  82. fAdaptedBufferSize ( buffer_size),
  83. fAdaptedSampleRate ( sample_rate ),
  84. fHostDLL ( buffer_size, sample_rate ),
  85. fAdaptedDLL ( buffer_size, sample_rate ),
  86. fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL),
  87. fQuality(0), fRingbufferSize(DEFAULT_RB_SIZE),
  88. fRunning(false)
  89. {}
  90. virtual ~JackAudioAdapterInterface()
  91. {}
  92. bool IsRunning()
  93. {
  94. return fRunning;
  95. }
  96. virtual void Reset();
  97. void Create();
  98. void Destroy();
  99. virtual int Open()
  100. {
  101. return 0;
  102. }
  103. virtual int Close()
  104. {
  105. return 0;
  106. }
  107. virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
  108. {
  109. fHostBufferSize = buffer_size;
  110. fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
  111. return 0;
  112. }
  113. virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
  114. {
  115. fAdaptedBufferSize = buffer_size;
  116. fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
  117. return 0;
  118. }
  119. virtual int SetBufferSize ( jack_nframes_t buffer_size )
  120. {
  121. SetHostBufferSize ( buffer_size );
  122. SetAdaptedBufferSize ( buffer_size );
  123. return 0;
  124. }
  125. virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
  126. {
  127. fHostSampleRate = sample_rate;
  128. fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
  129. return 0;
  130. }
  131. virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
  132. {
  133. fAdaptedSampleRate = sample_rate;
  134. fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
  135. return 0;
  136. }
  137. virtual int SetSampleRate ( jack_nframes_t sample_rate )
  138. {
  139. SetHostSampleRate ( sample_rate );
  140. SetAdaptedSampleRate ( sample_rate );
  141. return 0;
  142. }
  143. void SetInputs ( int inputs )
  144. {
  145. jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
  146. fCaptureChannels = inputs;
  147. }
  148. void SetOutputs ( int outputs )
  149. {
  150. jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
  151. fPlaybackChannels = outputs;
  152. }
  153. int GetInputs()
  154. {
  155. jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
  156. return fCaptureChannels;
  157. }
  158. int GetOutputs()
  159. {
  160. jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
  161. return fPlaybackChannels;
  162. }
  163. void PushAndPull(float** inputBuffer, float** outputBuffer, unsigned int inNumberFrames);
  164. void PullAndPush(float** inputBuffer, float** outputBuffer, unsigned int inNumberFrames);
  165. };
  166. }
  167. #endif