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.

161 lines
3.7KB

  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. #define TABLE_MAX 100000
  26. struct Measure
  27. {
  28. int delta;
  29. int time1;
  30. int time2;
  31. float r1;
  32. float r2;
  33. int pos1;
  34. int pos2;
  35. };
  36. struct MeasureTable
  37. {
  38. Measure fTable[TABLE_MAX];
  39. int fCount;
  40. MeasureTable():fCount(0)
  41. {}
  42. void Write(int time1, int time2, float r1, float r2, int pos1, int pos2);
  43. void Save();
  44. };
  45. /*!
  46. \brief Base class for audio adapters.
  47. */
  48. class JackAudioAdapterInterface
  49. {
  50. protected:
  51. #ifdef DEBUG
  52. MeasureTable fTable;
  53. #endif
  54. int fCaptureChannels;
  55. int fPlaybackChannels;
  56. jack_nframes_t fBufferSize;
  57. jack_nframes_t fSampleRate;
  58. // DLL
  59. JackAtomicDelayLockedLoop fProducerDLL;
  60. JackAtomicDelayLockedLoop fConsumerDLL;
  61. JackResampler** fCaptureRingBuffer;
  62. JackResampler** fPlaybackRingBuffer;
  63. bool fRunning;
  64. public:
  65. JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate)
  66. :fBufferSize(buffer_size),
  67. fSampleRate(sample_rate),
  68. fProducerDLL(buffer_size, sample_rate),
  69. fConsumerDLL(buffer_size, sample_rate),
  70. fRunning(false)
  71. {}
  72. virtual ~JackAudioAdapterInterface()
  73. {}
  74. void SetRingBuffers(JackResampler** input, JackResampler** output)
  75. {
  76. fCaptureRingBuffer = input;
  77. fPlaybackRingBuffer = output;
  78. }
  79. bool IsRunning() {return fRunning;}
  80. virtual void Reset() {fRunning = false;}
  81. void ResetRingBuffers();
  82. virtual int Open();
  83. virtual int Close();
  84. virtual int SetBufferSize(jack_nframes_t buffer_size)
  85. {
  86. fBufferSize = buffer_size;
  87. fConsumerDLL.Init(fBufferSize, fSampleRate);
  88. fProducerDLL.Init(fBufferSize, fSampleRate);
  89. return 0;
  90. }
  91. virtual int SetSampleRate(jack_nframes_t sample_rate)
  92. {
  93. fSampleRate = sample_rate;
  94. fConsumerDLL.Init(fBufferSize, fSampleRate);
  95. // Producer (Audio) keeps the same SR
  96. return 0;
  97. }
  98. virtual int SetAudioSampleRate(jack_nframes_t sample_rate)
  99. {
  100. fSampleRate = sample_rate;
  101. // Consumer keeps the same SR
  102. fProducerDLL.Init(fBufferSize, fSampleRate);
  103. return 0;
  104. }
  105. virtual void SetCallbackTime(jack_time_t callback_usec)
  106. {
  107. fConsumerDLL.IncFrame(callback_usec);
  108. }
  109. void ResampleFactor(jack_nframes_t& frame1, jack_nframes_t& frame2);
  110. int GetInputs()
  111. {
  112. return fCaptureChannels;
  113. }
  114. int GetOutputs()
  115. {
  116. return fPlaybackChannels;
  117. }
  118. };
  119. }
  120. #endif