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.

221 lines
5.4KB

  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 "ringbuffer.h"
  18. #include "jack.h"
  19. #include "JackError.h"
  20. #include "JackResampler.h"
  21. #include "JackFilters.h"
  22. #include <samplerate.h>
  23. namespace Jack
  24. {
  25. #ifdef JACK_MONITOR
  26. #define TABLE_MAX 100000
  27. struct Measure
  28. {
  29. int delta;
  30. int time1;
  31. int time2;
  32. float r1;
  33. float r2;
  34. int pos1;
  35. int pos2;
  36. };
  37. struct MeasureTable
  38. {
  39. Measure fTable[TABLE_MAX];
  40. int fCount;
  41. MeasureTable() :fCount ( 0 )
  42. {}
  43. void Write ( int time1, int time2, float r1, float r2, int pos1, int pos2 );
  44. void Save();
  45. };
  46. #endif
  47. /*!
  48. \brief Base class for audio adapters.
  49. */
  50. class JackAudioAdapterInterface
  51. {
  52. protected:
  53. #ifdef JACK_MONITOR
  54. MeasureTable fTable;
  55. #endif
  56. //channels
  57. int fCaptureChannels;
  58. int fPlaybackChannels;
  59. //host parameters
  60. jack_nframes_t fHostBufferSize;
  61. jack_nframes_t fHostSampleRate;
  62. //adapted parameters
  63. jack_nframes_t fAdaptedBufferSize;
  64. jack_nframes_t fAdaptedSampleRate;
  65. //delay locked loop
  66. JackAtomicDelayLockedLoop fHostDLL;
  67. JackAtomicDelayLockedLoop fAdaptedDLL;
  68. JackResampler** fCaptureRingBuffer;
  69. JackResampler** fPlaybackRingBuffer;
  70. unsigned int fQuality;
  71. bool fRunning;
  72. public:
  73. JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ) :
  74. fCaptureChannels ( 0 ),
  75. fPlaybackChannels ( 0 ),
  76. fHostBufferSize ( buffer_size ),
  77. fHostSampleRate ( sample_rate ),
  78. fAdaptedBufferSize ( buffer_size),
  79. fAdaptedSampleRate ( sample_rate ),
  80. fHostDLL ( buffer_size, sample_rate ),
  81. fAdaptedDLL ( buffer_size, sample_rate ),
  82. fQuality(0),
  83. fRunning ( false )
  84. {}
  85. virtual ~JackAudioAdapterInterface()
  86. {}
  87. void SetRingBuffers ( JackResampler** input, JackResampler** output )
  88. {
  89. fCaptureRingBuffer = input;
  90. fPlaybackRingBuffer = output;
  91. }
  92. bool IsRunning()
  93. {
  94. return fRunning;
  95. }
  96. virtual void Reset()
  97. {
  98. fRunning = false;
  99. }
  100. void ResetRingBuffers();
  101. unsigned int GetQuality()
  102. {
  103. return fQuality;
  104. }
  105. virtual int Open();
  106. virtual int Close();
  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. virtual void SetCallbackTime ( jack_time_t callback_usec )
  144. {
  145. fHostDLL.IncFrame ( callback_usec );
  146. }
  147. void ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 );
  148. void SetInputs ( int inputs )
  149. {
  150. jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
  151. fCaptureChannels = inputs;
  152. }
  153. void SetOutputs ( int outputs )
  154. {
  155. jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
  156. fPlaybackChannels = outputs;
  157. }
  158. int GetInputs()
  159. {
  160. jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
  161. return fCaptureChannels;
  162. }
  163. int GetOutputs()
  164. {
  165. jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
  166. return fPlaybackChannels;
  167. }
  168. };
  169. }
  170. #endif