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.

184 lines
5.9KB

  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 <stdio.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. JackPIController** fPIControllerCapture;
  64. JackPIController** fPIControllerPlayback;
  65. JackResampler** fCaptureRingBuffer;
  66. JackResampler** fPlaybackRingBuffer;
  67. unsigned int fQuality;
  68. unsigned int fRingbufferCurSize;
  69. jack_time_t fPullAndPushTime;
  70. bool fRunning;
  71. bool fAdaptative;
  72. bool fResampleRatioPerChannel;
  73. void ResetRingBuffers();
  74. void AdaptRingBufferSize();
  75. void GrowRingBufferSize();
  76. public:
  77. JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate, jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE):
  78. fCaptureChannels(0),
  79. fPlaybackChannels(0),
  80. fHostBufferSize(buffer_size),
  81. fHostSampleRate(sample_rate),
  82. fAdaptedBufferSize(buffer_size),
  83. fAdaptedSampleRate(sample_rate),
  84. fPIControllerCapture(NULL), fPIControllerPlayback(NULL),
  85. fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL),
  86. fQuality(0),
  87. fRingbufferCurSize(ring_buffer_size),
  88. fPullAndPushTime(0),
  89. fRunning(false),
  90. fAdaptative(true),
  91. fResampleRatioPerChannel(false)
  92. {}
  93. JackAudioAdapterInterface(jack_nframes_t host_buffer_size,
  94. jack_nframes_t host_sample_rate,
  95. jack_nframes_t adapted_buffer_size,
  96. jack_nframes_t adapted_sample_rate,
  97. jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE) :
  98. fCaptureChannels(0),
  99. fPlaybackChannels(0),
  100. fHostBufferSize(host_buffer_size),
  101. fHostSampleRate(host_sample_rate),
  102. fAdaptedBufferSize(adapted_buffer_size),
  103. fAdaptedSampleRate(adapted_sample_rate),
  104. fPIControllerCapture(NULL), fPIControllerPlayback(NULL),
  105. fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL),
  106. fQuality(0),
  107. fRingbufferCurSize(ring_buffer_size),
  108. fPullAndPushTime(0),
  109. fRunning(false),
  110. fAdaptative(true),
  111. fResampleRatioPerChannel(false)
  112. {}
  113. virtual ~JackAudioAdapterInterface()
  114. {}
  115. virtual void Reset();
  116. virtual void Create();
  117. virtual void Destroy();
  118. virtual int Open()
  119. {
  120. return 0;
  121. }
  122. virtual int Close()
  123. {
  124. return 0;
  125. }
  126. virtual int SetHostBufferSize(jack_nframes_t buffer_size);
  127. virtual int SetAdaptedBufferSize(jack_nframes_t buffer_size);
  128. virtual int SetBufferSize(jack_nframes_t buffer_size);
  129. virtual int SetHostSampleRate(jack_nframes_t sample_rate);
  130. virtual int SetAdaptedSampleRate(jack_nframes_t sample_rate);
  131. virtual int SetSampleRate(jack_nframes_t sample_rate);
  132. void SetInputs(int inputs);
  133. void SetOutputs(int outputs);
  134. int GetInputs();
  135. int GetOutputs();
  136. virtual int GetInputLatency(int port_index) { return 0; }
  137. virtual int GetOutputLatency(int port_index) { return 0; }
  138. double GetSharedRatio(int delta_frames);
  139. int PushAndPull(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames);
  140. int PullAndPush(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames);
  141. };
  142. }
  143. #endif