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.

217 lines
5.3KB

  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. namespace Jack
  20. {
  21. #ifdef JACK_MONITOR
  22. #define TABLE_MAX 100000
  23. struct Measure
  24. {
  25. int delta;
  26. int time1;
  27. int time2;
  28. float r1;
  29. float r2;
  30. int pos1;
  31. int pos2;
  32. };
  33. struct MeasureTable
  34. {
  35. Measure fTable[TABLE_MAX];
  36. int fCount;
  37. MeasureTable() :fCount ( 0 )
  38. {}
  39. void Write ( int time1, int time2, float r1, float r2, int pos1, int pos2 );
  40. void Save();
  41. };
  42. #endif
  43. /*!
  44. \brief Base class for audio adapters.
  45. */
  46. class JackAudioAdapterInterface
  47. {
  48. protected:
  49. #ifdef JACK_MONITOR
  50. MeasureTable fTable;
  51. #endif
  52. //channels
  53. int fCaptureChannels;
  54. int fPlaybackChannels;
  55. //host parameters
  56. jack_nframes_t fHostBufferSize;
  57. jack_nframes_t fHostSampleRate;
  58. //adapted parameters
  59. jack_nframes_t fAdaptedBufferSize;
  60. jack_nframes_t fAdaptedSampleRate;
  61. //delay locked loop
  62. JackAtomicDelayLockedLoop fHostDLL;
  63. JackAtomicDelayLockedLoop fAdaptedDLL;
  64. JackResampler** fCaptureRingBuffer;
  65. JackResampler** fPlaybackRingBuffer;
  66. unsigned int fQuality;
  67. bool fRunning;
  68. public:
  69. JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ) :
  70. fCaptureChannels ( 0 ),
  71. fPlaybackChannels ( 0 ),
  72. fHostBufferSize ( buffer_size ),
  73. fHostSampleRate ( sample_rate ),
  74. fAdaptedBufferSize ( buffer_size),
  75. fAdaptedSampleRate ( sample_rate ),
  76. fHostDLL ( buffer_size, sample_rate ),
  77. fAdaptedDLL ( buffer_size, sample_rate ),
  78. fQuality(0),
  79. fRunning ( false )
  80. {}
  81. virtual ~JackAudioAdapterInterface()
  82. {}
  83. void SetRingBuffers ( JackResampler** input, JackResampler** output )
  84. {
  85. fCaptureRingBuffer = input;
  86. fPlaybackRingBuffer = output;
  87. }
  88. bool IsRunning()
  89. {
  90. return fRunning;
  91. }
  92. virtual void Reset()
  93. {
  94. fRunning = false;
  95. }
  96. void ResetRingBuffers();
  97. unsigned int GetQuality()
  98. {
  99. return fQuality;
  100. }
  101. virtual int Open();
  102. virtual int Close();
  103. virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
  104. {
  105. fHostBufferSize = buffer_size;
  106. fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
  107. return 0;
  108. }
  109. virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
  110. {
  111. fAdaptedBufferSize = buffer_size;
  112. fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
  113. return 0;
  114. }
  115. virtual int SetBufferSize ( jack_nframes_t buffer_size )
  116. {
  117. SetHostBufferSize ( buffer_size );
  118. SetAdaptedBufferSize ( buffer_size );
  119. return 0;
  120. }
  121. virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
  122. {
  123. fHostSampleRate = sample_rate;
  124. fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
  125. return 0;
  126. }
  127. virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
  128. {
  129. fAdaptedSampleRate = sample_rate;
  130. fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
  131. return 0;
  132. }
  133. virtual int SetSampleRate ( jack_nframes_t sample_rate )
  134. {
  135. SetHostSampleRate ( sample_rate );
  136. SetAdaptedSampleRate ( sample_rate );
  137. return 0;
  138. }
  139. virtual void SetCallbackTime ( jack_time_t callback_usec )
  140. {
  141. fHostDLL.IncFrame ( callback_usec );
  142. }
  143. void ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 );
  144. void SetInputs ( int inputs )
  145. {
  146. jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
  147. fCaptureChannels = inputs;
  148. }
  149. void SetOutputs ( int outputs )
  150. {
  151. jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
  152. fPlaybackChannels = outputs;
  153. }
  154. int GetInputs()
  155. {
  156. jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
  157. return fCaptureChannels;
  158. }
  159. int GetOutputs()
  160. {
  161. jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
  162. return fPlaybackChannels;
  163. }
  164. };
  165. }
  166. #endif