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.

104 lines
2.8KB

  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 "JackIOAdapter.h"
  16. #include <stdio.h>
  17. namespace Jack
  18. {
  19. void MeasureTable::Write(int time1, int time2, float r1, float r2, int pos1, int pos2)
  20. {
  21. fTable[fCount].time1 = time1;
  22. fTable[fCount].time2 = time2;
  23. fTable[fCount].r1 = r1;
  24. fTable[fCount].r2 = r2;
  25. fTable[fCount].pos1 = pos1;
  26. fTable[fCount].pos2 = pos2;
  27. fCount++;
  28. if (fCount == TABLE_MAX)
  29. fCount--;
  30. }
  31. void MeasureTable::Save()
  32. {
  33. FILE* file = fopen("JackIOAdapter.log", "w");
  34. for (int i = 1; i < TABLE_MAX; i++) {
  35. fprintf(file, "%d \t %d \t %d \t %f \t %f \t %d \t %d \n",
  36. fTable[i].delta, fTable[i+1].time1 - fTable[i].time1,
  37. fTable[i+1].time2 - fTable[i].time2,
  38. fTable[i].r1, fTable[i].r2, fTable[i].pos1, fTable[i].pos2);
  39. }
  40. fclose(file);
  41. }
  42. void JackIOAdapterInterface::ResampleFactor(jack_nframes_t& frame1, jack_nframes_t& frame2)
  43. {
  44. if (!fRunning) {
  45. fRunning = true;
  46. jack_time_t time = jack_get_time();
  47. fProducerDLL.Init(time);
  48. fConsumerDLL.Init(time);
  49. }
  50. // DLL
  51. jack_time_t time = jack_get_time();
  52. fProducerDLL.IncFrame(time);
  53. jack_nframes_t time1 = fConsumerDLL.Time2Frames(time);
  54. jack_nframes_t time2 = fProducerDLL.Time2Frames(time);
  55. double src_ratio_output = double(time2) / double(time1);
  56. double src_ratio_input = double(time1) / double(time2);
  57. if (src_ratio_input < 0.7f || src_ratio_input > 1.3f) {
  58. jack_error("src_ratio_input = %f", src_ratio_input);
  59. src_ratio_input = 1;
  60. time1 = 1;
  61. time2 = 1;
  62. }
  63. if (src_ratio_output < 0.7f || src_ratio_output > 1.3f) {
  64. jack_error("src_ratio_output = %f", src_ratio_output);
  65. src_ratio_output = 1;
  66. time1 = 1;
  67. time2 = 1;
  68. }
  69. src_ratio_input = Range(0.7f, 1.3f, src_ratio_input);
  70. src_ratio_output = Range(0.7f, 1.3f, src_ratio_output);
  71. jack_log("Callback resampler src_ratio_input = %f src_ratio_output = %f", src_ratio_input, src_ratio_output);
  72. frame1 = time1;
  73. frame2 = time2;
  74. }
  75. int JackIOAdapterInterface::Open()
  76. {
  77. return 0;
  78. }
  79. int JackIOAdapterInterface::Close()
  80. {
  81. return 0;
  82. }
  83. } // namespace