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.

116 lines
3.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. #include "JackAlsaIOAdapter.h"
  16. namespace Jack
  17. {
  18. int JackAlsaIOAdapter::Open()
  19. {
  20. if (fAudioInterface.open() == 0) {
  21. fAudioInterface.longinfo();
  22. fThread.AcquireRealTime(85);
  23. fThread.StartSync();
  24. return 0;
  25. } else {
  26. return -1;
  27. }
  28. }
  29. int JackAlsaIOAdapter::Close()
  30. {
  31. fTable.Save();
  32. fThread.Stop();
  33. return fAudioInterface.close();
  34. }
  35. bool JackAlsaIOAdapter::Init()
  36. {
  37. fAudioInterface.write();
  38. fAudioInterface.write();
  39. return true;
  40. }
  41. bool JackAlsaIOAdapter::Execute()
  42. {
  43. if (fAudioInterface.read() < 0)
  44. return false;
  45. if (!fRunning) {
  46. fRunning = true;
  47. jack_time_t time = jack_get_time();
  48. fProducerDLL.Init(time);
  49. fConsumerDLL.Init(time);
  50. }
  51. // DLL
  52. jack_time_t time = jack_get_time();
  53. fProducerDLL.IncFrame(time);
  54. jack_nframes_t time1 = fConsumerDLL.Time2Frames(time);
  55. jack_nframes_t time2 = fProducerDLL.Time2Frames(time);
  56. double src_ratio_output = double(time2) / double(time1);
  57. double src_ratio_input = double(time1) / double(time2);
  58. if (src_ratio_input < 0.1f || src_ratio_input > 1.9f) {
  59. jack_error("src_ratio_input = %f", src_ratio_input);
  60. src_ratio_input = 1;
  61. time1 = 1;
  62. time2 = 1;
  63. }
  64. if (src_ratio_output < 0.1f || src_ratio_output > 1.9f) {
  65. jack_error("src_ratio_output = %f", src_ratio_output);
  66. src_ratio_output = 1;
  67. time1 = 1;
  68. time2 = 1;
  69. }
  70. src_ratio_input = Range(0.1f, 1.9f, src_ratio_input);
  71. src_ratio_output = Range(0.1f, 1.9f, src_ratio_output);
  72. jack_log("Callback resampler src_ratio_input = %f src_ratio_output = %f", src_ratio_input, src_ratio_output);
  73. for (int i = 0; i < fCaptureChannels; i++) {
  74. fCaptureRingBuffer[i]->SetRatio(time1, time2);
  75. fCaptureRingBuffer[i]->WriteResample(fAudioInterface.fInputSoftChannels[i], fBufferSize);
  76. }
  77. for (int i = 0; i < fPlaybackChannels; i++) {
  78. fPlaybackRingBuffer[i]->SetRatio(time2, time1);
  79. fPlaybackRingBuffer[i]->ReadResample(fAudioInterface.fOutputSoftChannels[i], fBufferSize);
  80. }
  81. fTable.Write(time1, time2, src_ratio_input, src_ratio_output,
  82. fCaptureRingBuffer[0]->ReadSpace(), fPlaybackRingBuffer[0]->WriteSpace());
  83. if (fAudioInterface.write() < 0)
  84. return false;
  85. return true;
  86. }
  87. int JackAlsaIOAdapter::SetBufferSize(jack_nframes_t buffer_size)
  88. {
  89. return 0;
  90. }
  91. }