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.

226 lines
6.1KB

  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(unsigned int fHostBufferSize, unsigned int fHostSampleRate, unsigned int fAdaptedSampleRate, unsigned int fAdaptedBufferSize);
  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. //PI controler
  63. JackPIControler fPIControler;
  64. JackResampler** fCaptureRingBuffer;
  65. JackResampler** fPlaybackRingBuffer;
  66. unsigned int fQuality;
  67. unsigned int fRingbufferSize;
  68. jack_time_t fPullAndPushTime;
  69. bool fRunning;
  70. void ResetRingBuffers();
  71. public:
  72. JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ):
  73. fCaptureChannels ( 0 ),
  74. fPlaybackChannels ( 0 ),
  75. fHostBufferSize ( buffer_size ),
  76. fHostSampleRate ( sample_rate ),
  77. fAdaptedBufferSize ( buffer_size),
  78. fAdaptedSampleRate ( sample_rate ),
  79. fPIControler(sample_rate / sample_rate, 256),
  80. fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL),
  81. fQuality(0), fRingbufferSize(DEFAULT_RB_SIZE),
  82. fPullAndPushTime(0),
  83. fRunning(false)
  84. {}
  85. JackAudioAdapterInterface ( jack_nframes_t host_buffer_size,
  86. jack_nframes_t host_sample_rate,
  87. jack_nframes_t adapted_buffer_size,
  88. jack_nframes_t adapted_sample_rate ) :
  89. fCaptureChannels ( 0 ),
  90. fPlaybackChannels ( 0 ),
  91. fHostBufferSize ( host_buffer_size ),
  92. fHostSampleRate ( host_sample_rate ),
  93. fAdaptedBufferSize ( adapted_buffer_size),
  94. fAdaptedSampleRate ( adapted_sample_rate ),
  95. fPIControler(host_sample_rate / host_sample_rate, 256),
  96. fQuality(0),
  97. fRingbufferSize(DEFAULT_RB_SIZE),
  98. fPullAndPushTime(0),
  99. fRunning ( false )
  100. {}
  101. virtual ~JackAudioAdapterInterface()
  102. {}
  103. bool IsRunning()
  104. {
  105. return fRunning;
  106. }
  107. virtual void Reset();
  108. virtual void Create();
  109. virtual void Destroy();
  110. virtual int Open()
  111. {
  112. return 0;
  113. }
  114. virtual int Close()
  115. {
  116. return 0;
  117. }
  118. virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
  119. {
  120. fHostBufferSize = buffer_size;
  121. return 0;
  122. }
  123. virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
  124. {
  125. fAdaptedBufferSize = buffer_size;
  126. return 0;
  127. }
  128. virtual int SetBufferSize ( jack_nframes_t buffer_size )
  129. {
  130. SetHostBufferSize ( buffer_size );
  131. SetAdaptedBufferSize ( buffer_size );
  132. return 0;
  133. }
  134. virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
  135. {
  136. fHostSampleRate = sample_rate;
  137. fPIControler.Init(double(fHostSampleRate) / double(fAdaptedSampleRate));
  138. return 0;
  139. }
  140. virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
  141. {
  142. fAdaptedSampleRate = sample_rate;
  143. fPIControler.Init(double(fHostSampleRate) / double(fAdaptedSampleRate));
  144. return 0;
  145. }
  146. virtual int SetSampleRate ( jack_nframes_t sample_rate )
  147. {
  148. SetHostSampleRate ( sample_rate );
  149. SetAdaptedSampleRate ( sample_rate );
  150. return 0;
  151. }
  152. void SetInputs ( int inputs )
  153. {
  154. jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
  155. fCaptureChannels = inputs;
  156. }
  157. void SetOutputs ( int outputs )
  158. {
  159. jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
  160. fPlaybackChannels = outputs;
  161. }
  162. int GetInputs()
  163. {
  164. jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
  165. return fCaptureChannels;
  166. }
  167. int GetOutputs()
  168. {
  169. jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
  170. return fPlaybackChannels;
  171. }
  172. int PushAndPull(float** inputBuffer, float** outputBuffer, unsigned int frames);
  173. int PullAndPush(float** inputBuffer, float** outputBuffer, unsigned int frames);
  174. };
  175. }
  176. #endif