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.

156 lines
4.1KB

  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. class JackAudioAdapterInterface
  46. {
  47. protected:
  48. #ifdef DEBUG
  49. MeasureTable fTable;
  50. #endif
  51. int fCaptureChannels;
  52. int fPlaybackChannels;
  53. jack_nframes_t fBufferSize;
  54. jack_nframes_t fSampleRate;
  55. // DLL
  56. JackAtomicDelayLockedLoop fProducerDLL;
  57. JackAtomicDelayLockedLoop fConsumerDLL;
  58. JackResampler** fCaptureRingBuffer;
  59. JackResampler** fPlaybackRingBuffer;
  60. bool fRunning;
  61. public:
  62. JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate)
  63. :fBufferSize(buffer_size),
  64. fSampleRate(sample_rate),
  65. fProducerDLL(buffer_size, sample_rate),
  66. fConsumerDLL(buffer_size, sample_rate),
  67. fRunning(false)
  68. {}
  69. virtual ~JackAudioAdapterInterface()
  70. {}
  71. void SetRingBuffers(JackResampler** input, JackResampler** output)
  72. {
  73. fCaptureRingBuffer = input;
  74. fPlaybackRingBuffer = output;
  75. }
  76. bool IsRunning() {return fRunning;}
  77. virtual void Reset() {fRunning = false;}
  78. void ResetRingBuffers();
  79. virtual int Open();
  80. virtual int Close();
  81. virtual int SetBufferSize(jack_nframes_t buffer_size)
  82. {
  83. fBufferSize = buffer_size;
  84. fConsumerDLL.Init(fBufferSize, fSampleRate);
  85. fProducerDLL.Init(fBufferSize, fSampleRate);
  86. return 0;
  87. }
  88. virtual int SetSampleRate(jack_nframes_t sample_rate)
  89. {
  90. fSampleRate = sample_rate;
  91. fConsumerDLL.Init(fBufferSize, fSampleRate);
  92. // Producer (Audio) keeps the same SR
  93. return 0;
  94. }
  95. virtual int SetAudioSampleRate(jack_nframes_t sample_rate)
  96. {
  97. fSampleRate = sample_rate;
  98. // Consumer keeps the same SR
  99. fProducerDLL.Init(fBufferSize, fSampleRate);
  100. return 0;
  101. }
  102. virtual void SetCallbackTime(jack_time_t callback_usec)
  103. {
  104. fConsumerDLL.IncFrame(callback_usec);
  105. }
  106. void ResampleFactor(jack_nframes_t& frame1, jack_nframes_t& frame2);
  107. int GetInputs()
  108. {
  109. return fCaptureChannels;
  110. }
  111. int GetOutputs()
  112. {
  113. return fPlaybackChannels;
  114. }
  115. };
  116. }
  117. #endif