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.

140 lines
4.3KB

  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 "JackAudioAdapter.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. int pos = (++fCount) % TABLE_MAX;
  22. fTable[pos].time1 = time1;
  23. fTable[pos].time2 = time2;
  24. fTable[pos].r1 = r1;
  25. fTable[pos].r2 = r2;
  26. fTable[pos].pos1 = pos1;
  27. fTable[pos].pos2 = pos2;
  28. }
  29. void MeasureTable::Save()
  30. {
  31. char buffer[1024];
  32. FILE* file = fopen("JackAudioAdapter.log", "w");
  33. int MAX = (fCount) % TABLE_MAX - 1;
  34. for (int i = 1; i < 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. // Adapter timing 1
  42. file = fopen("AdapterTiming1.plot", "w");
  43. fprintf(file, "set multiplot\n");
  44. fprintf(file, "set grid\n");
  45. fprintf(file, "set title \"Audio adapter timing\"\n");
  46. fprintf(file, "set xlabel \"audio cycles\"\n");
  47. fprintf(file, "set ylabel \"frames\"\n");
  48. fprintf(file, "plot ");
  49. sprintf(buffer, "\"JackAudioAdapter.log\" using 2 title \"Consumer time\" with lines,");
  50. fprintf(file, buffer);
  51. sprintf(buffer, "\"JackAudioAdapter.log\" using 3 title \"Producer time\" with lines");
  52. fprintf(file, buffer);
  53. fclose(file);
  54. // Adapter timing 2
  55. file = fopen("AdapterTiming2.plot", "w");
  56. fprintf(file, "set multiplot\n");
  57. fprintf(file, "set grid\n");
  58. fprintf(file, "set title \"Audio adapter timing\"\n");
  59. fprintf(file, "set xlabel \"audio cycles\"\n");
  60. fprintf(file, "plot ");
  61. sprintf(buffer, "\"JackAudioAdapter.log\" using 4 title \"Ratio 1\" with lines,");
  62. fprintf(file, buffer);
  63. sprintf(buffer, "\"JackAudioAdapter.log\" using 5 title \"Ratio 2\" with lines");
  64. fprintf(file, buffer);
  65. fclose(file);
  66. // Adapter timing 3
  67. file = fopen("AdapterTiming3.plot", "w");
  68. fprintf(file, "set multiplot\n");
  69. fprintf(file, "set grid\n");
  70. fprintf(file, "set title \"Audio adapter timing\"\n");
  71. fprintf(file, "set xlabel \"audio cycles\"\n");
  72. fprintf(file, "set ylabel \"frames\"\n");
  73. fprintf(file, "plot ");
  74. sprintf(buffer, "\"JackAudioAdapter.log\" using 6 title \"Position in consumer ringbuffer\" with lines,");
  75. fprintf(file, buffer);
  76. sprintf(buffer, "\"JackAudioAdapter.log\" using 7 title \"Position in producer ringbuffer\" with lines");
  77. fprintf(file, buffer);
  78. fclose(file);
  79. }
  80. void JackAudioAdapterInterface::ResetRingBuffers()
  81. {
  82. int i;
  83. for (i = 0; i < fCaptureChannels; i++) {
  84. fCaptureRingBuffer[i]->Reset();
  85. }
  86. for (i = 0; i < fPlaybackChannels; i++) {
  87. fPlaybackRingBuffer[i]->Reset();
  88. }
  89. }
  90. void JackAudioAdapterInterface::ResampleFactor(jack_nframes_t& frame1, jack_nframes_t& frame2)
  91. {
  92. jack_time_t time = jack_get_time();
  93. if (!fRunning) {
  94. // Init DLL
  95. fRunning = true;
  96. fProducerDLL.Init(time);
  97. fConsumerDLL.Init(time);
  98. frame1 = 1;
  99. frame2 = 1;
  100. } else {
  101. // DLL
  102. fProducerDLL.IncFrame(time);
  103. jack_nframes_t time1 = fConsumerDLL.Time2Frames(time);
  104. jack_nframes_t time2 = fProducerDLL.Time2Frames(time);
  105. frame1 = time1;
  106. frame2 = time2;
  107. jack_log("JackAudioAdapterInterface::ResampleFactor time1 = %ld time2 = %ld src_ratio_input = %f src_ratio_output = %f",
  108. long(time1), long(time2), double(time1) / double(time2), double(time2) / double(time1));
  109. }
  110. }
  111. int JackAudioAdapterInterface::Open()
  112. {
  113. return 0;
  114. }
  115. int JackAudioAdapterInterface::Close()
  116. {
  117. return 0;
  118. }
  119. } // namespace