00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "JackAudioAdapter.h"
00021 #include <stdio.h>
00022
00023 namespace Jack
00024 {
00025
00026 #ifdef JACK_MONITOR
00027
00028 void MeasureTable::Write(int time1, int time2, float r1, float r2, int pos1, int pos2)
00029 {
00030 int pos = (++fCount) % TABLE_MAX;
00031 fTable[pos].time1 = time1;
00032 fTable[pos].time2 = time2;
00033 fTable[pos].r1 = r1;
00034 fTable[pos].r2 = r2;
00035 fTable[pos].pos1 = pos1;
00036 fTable[pos].pos2 = pos2;
00037 }
00038
00039 void MeasureTable::Save()
00040 {
00041 char buffer[1024];
00042 FILE* file = fopen("JackAudioAdapter.log", "w");
00043
00044 int max = (fCount) % TABLE_MAX - 1;
00045 for (int i = 1; i < max; i++)
00046 {
00047 fprintf(file, "%d \t %d \t %d \t %f \t %f \t %d \t %d \n",
00048 fTable[i].delta, fTable[i+1].time1 - fTable[i].time1,
00049 fTable[i+1].time2 - fTable[i].time2,
00050 fTable[i].r1, fTable[i].r2, fTable[i].pos1, fTable[i].pos2);
00051 }
00052 fclose(file);
00053
00054
00055 file = fopen("AdapterTiming1.plot", "w");
00056 fprintf(file, "set multiplot\n");
00057 fprintf(file, "set grid\n");
00058 fprintf(file, "set title \"Audio adapter timing\"\n");
00059 fprintf(file, "set xlabel \"audio cycles\"\n");
00060 fprintf(file, "set ylabel \"frames\"\n");
00061 fprintf(file, "plot ");
00062 sprintf(buffer, "\"JackAudioAdapter.log\" using 2 title \"Consumer interrupt period\" with lines,");
00063 fprintf(file, buffer);
00064 sprintf(buffer, "\"JackAudioAdapter.log\" using 3 title \"Producer interrupt period\" with lines");
00065 fprintf(file, buffer);
00066 fclose(file);
00067
00068
00069 file = fopen("AdapterTiming2.plot", "w");
00070 fprintf(file, "set multiplot\n");
00071 fprintf(file, "set grid\n");
00072 fprintf(file, "set title \"Audio adapter timing\"\n");
00073 fprintf(file, "set xlabel \"audio cycles\"\n");
00074 fprintf(file, "set ylabel \"resampling ratio\"\n");
00075 fprintf(file, "plot ");
00076 sprintf(buffer, "\"JackAudioAdapter.log\" using 4 title \"Ratio 1\" with lines,");
00077 fprintf(file, buffer);
00078 sprintf(buffer, "\"JackAudioAdapter.log\" using 5 title \"Ratio 2\" with lines");
00079 fprintf(file, buffer);
00080 fclose(file);
00081
00082
00083 file = fopen("AdapterTiming3.plot", "w");
00084 fprintf(file, "set multiplot\n");
00085 fprintf(file, "set grid\n");
00086 fprintf(file, "set title \"Audio adapter timing\"\n");
00087 fprintf(file, "set xlabel \"audio cycles\"\n");
00088 fprintf(file, "set ylabel \"frames\"\n");
00089 fprintf(file, "plot ");
00090 sprintf(buffer, "\"JackAudioAdapter.log\" using 6 title \"Frames position in consumer ringbuffer\" with lines,");
00091 fprintf(file, buffer);
00092 sprintf(buffer, "\"JackAudioAdapter.log\" using 7 title \"Frames position in producer ringbuffer\" with lines");
00093 fprintf(file, buffer);
00094 fclose(file);
00095 }
00096
00097 #endif
00098
00099 void JackAudioAdapterInterface::ResetRingBuffers()
00100 {
00101 int i;
00102 for (i = 0; i < fCaptureChannels; i++)
00103 fCaptureRingBuffer[i]->Reset();
00104 for (i = 0; i < fPlaybackChannels; i++)
00105 fPlaybackRingBuffer[i]->Reset();
00106 }
00107
00108 void JackAudioAdapterInterface::ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 )
00109 {
00110 jack_time_t time = jack_get_time();
00111
00112 if ( !fRunning )
00113 {
00114
00115 fRunning = true;
00116 fHostDLL.Init ( time );
00117 fAdaptedDLL.Init ( time );
00118 frame1 = 1;
00119 frame2 = 1;
00120 }
00121 else
00122 {
00123
00124 fAdaptedDLL.IncFrame(time);
00125 jack_nframes_t time1 = fHostDLL.Time2Frames(time);
00126 jack_nframes_t time2 = fAdaptedDLL.Time2Frames(time);
00127 frame1 = time1;
00128 frame2 = time2;
00129 jack_log("JackAudioAdapterInterface::ResampleFactor time1 = %ld time2 = %ld src_ratio_input = %f src_ratio_output = %f",
00130 long(time1), long(time2), double(time1) / double(time2), double(time2) / double(time1));
00131 }
00132 }
00133
00134 int JackAudioAdapterInterface::Open()
00135 {
00136 return 0;
00137 }
00138
00139 int JackAudioAdapterInterface::Close()
00140 {
00141 return 0;
00142 }
00143
00144 }