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.

214 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 "ringbuffer.h"
  18. #include "jack.h"
  19. #include "JackError.h"
  20. #include "JackResampler.h"
  21. #include "JackConstants.h"
  22. #include "JackFilters.h"
  23. #include <samplerate.h>
  24. namespace Jack
  25. {
  26. #ifdef JACK_MONITOR
  27. #define TABLE_MAX 100000
  28. struct Measure
  29. {
  30. int delta;
  31. int time1;
  32. int time2;
  33. float r1;
  34. float r2;
  35. int pos1;
  36. int pos2;
  37. };
  38. struct MeasureTable
  39. {
  40. Measure fTable[TABLE_MAX];
  41. int fCount;
  42. MeasureTable() :fCount ( 0 )
  43. {}
  44. void Write ( int time1, int time2, float r1, float r2, int pos1, int pos2 );
  45. void Save();
  46. };
  47. #endif
  48. /*!
  49. \brief Base class for audio adapters.
  50. */
  51. class JackAudioAdapterInterface
  52. {
  53. protected:
  54. #ifdef JACK_MONITOR
  55. MeasureTable fTable;
  56. #endif
  57. //channels
  58. int fCaptureChannels;
  59. int fPlaybackChannels;
  60. //host parameters
  61. jack_nframes_t fHostBufferSize;
  62. jack_nframes_t fHostSampleRate;
  63. //adapted parameters
  64. jack_nframes_t fAdaptedBufferSize;
  65. jack_nframes_t fAdaptedSampleRate;
  66. //delay locked loop
  67. JackAtomicDelayLockedLoop fHostDLL;
  68. JackAtomicDelayLockedLoop fAdaptedDLL;
  69. JackResampler** fCaptureRingBuffer;
  70. JackResampler** fPlaybackRingBuffer;
  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. fRunning ( false )
  83. {}
  84. virtual ~JackAudioAdapterInterface()
  85. {}
  86. void SetRingBuffers ( JackResampler** input, JackResampler** output )
  87. {
  88. fCaptureRingBuffer = input;
  89. fPlaybackRingBuffer = output;
  90. }
  91. bool IsRunning()
  92. {
  93. return fRunning;
  94. }
  95. virtual void Reset()
  96. {
  97. fRunning = false;
  98. }
  99. void ResetRingBuffers();
  100. virtual int Open();
  101. virtual int Close();
  102. virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
  103. {
  104. fHostBufferSize = buffer_size;
  105. fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
  106. return 0;
  107. }
  108. virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
  109. {
  110. fAdaptedBufferSize = buffer_size;
  111. fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
  112. return 0;
  113. }
  114. virtual int SetBufferSize ( jack_nframes_t buffer_size )
  115. {
  116. SetHostBufferSize ( buffer_size );
  117. SetAdaptedBufferSize ( buffer_size );
  118. return 0;
  119. }
  120. virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
  121. {
  122. fHostSampleRate = sample_rate;
  123. fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
  124. return 0;
  125. }
  126. virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
  127. {
  128. fAdaptedSampleRate = sample_rate;
  129. fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
  130. return 0;
  131. }
  132. virtual int SetSampleRate ( jack_nframes_t sample_rate )
  133. {
  134. SetHostSampleRate ( sample_rate );
  135. SetAdaptedSampleRate ( sample_rate );
  136. return 0;
  137. }
  138. virtual void SetCallbackTime ( jack_time_t callback_usec )
  139. {
  140. fHostDLL.IncFrame ( callback_usec );
  141. }
  142. void ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 );
  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. };
  164. }
  165. #endif