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.

146 lines
4.9KB

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