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.

213 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 "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. bool fRunning;
  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. fHostDLL ( buffer_size, sample_rate ),
  80. fAdaptedDLL ( buffer_size, sample_rate ),
  81. fRunning ( false )
  82. {}
  83. virtual ~JackAudioAdapterInterface()
  84. {}
  85. void SetRingBuffers ( JackResampler** input, JackResampler** output )
  86. {
  87. fCaptureRingBuffer = input;
  88. fPlaybackRingBuffer = output;
  89. }
  90. bool IsRunning()
  91. {
  92. return fRunning;
  93. }
  94. virtual void Reset()
  95. {
  96. fRunning = false;
  97. }
  98. void ResetRingBuffers();
  99. virtual int Open();
  100. virtual int Close();
  101. virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
  102. {
  103. fHostBufferSize = buffer_size;
  104. fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
  105. return 0;
  106. }
  107. virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
  108. {
  109. fAdaptedBufferSize = buffer_size;
  110. fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
  111. return 0;
  112. }
  113. virtual int SetBufferSize ( jack_nframes_t buffer_size )
  114. {
  115. SetHostBufferSize ( buffer_size );
  116. SetAdaptedBufferSize ( buffer_size );
  117. return 0;
  118. }
  119. virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
  120. {
  121. fHostSampleRate = sample_rate;
  122. fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
  123. return 0;
  124. }
  125. virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
  126. {
  127. fAdaptedSampleRate = sample_rate;
  128. fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
  129. return 0;
  130. }
  131. virtual int SetSampleRate ( jack_nframes_t sample_rate )
  132. {
  133. SetHostSampleRate ( sample_rate );
  134. SetAdaptedSampleRate ( sample_rate );
  135. return 0;
  136. }
  137. virtual void SetCallbackTime ( jack_time_t callback_usec )
  138. {
  139. fHostDLL.IncFrame ( callback_usec );
  140. }
  141. void ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 );
  142. void SetInputs ( int inputs )
  143. {
  144. jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
  145. fCaptureChannels = inputs;
  146. }
  147. void SetOutputs ( int outputs )
  148. {
  149. jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
  150. fPlaybackChannels = outputs;
  151. }
  152. int GetInputs()
  153. {
  154. jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
  155. return fCaptureChannels;
  156. }
  157. int GetOutputs()
  158. {
  159. jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
  160. return fPlaybackChannels;
  161. }
  162. };
  163. }
  164. #endif