00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __JackAudioAdapterInterface__
00021 #define __JackAudioAdapterInterface__
00022
00023 #include "ringbuffer.h"
00024 #include "jack.h"
00025 #include "JackError.h"
00026 #include "JackResampler.h"
00027 #include "JackConstants.h"
00028 #include "JackFilters.h"
00029 #include <samplerate.h>
00030
00031 namespace Jack
00032 {
00033
00034 #ifdef JACK_MONITOR
00035
00036 #define TABLE_MAX 100000
00037
00038 struct Measure
00039 {
00040 int delta;
00041 int time1;
00042 int time2;
00043 float r1;
00044 float r2;
00045 int pos1;
00046 int pos2;
00047 };
00048
00049 struct MeasureTable
00050 {
00051
00052 Measure fTable[TABLE_MAX];
00053 int fCount;
00054
00055 MeasureTable() :fCount ( 0 )
00056 {}
00057
00058 void Write ( int time1, int time2, float r1, float r2, int pos1, int pos2 );
00059 void Save();
00060
00061 };
00062
00063 #endif
00064
00069 class JackAudioAdapterInterface
00070 {
00071
00072 protected:
00073
00074 #ifdef JACK_MONITOR
00075 MeasureTable fTable;
00076 #endif
00077
00078 int fCaptureChannels;
00079 int fPlaybackChannels;
00080
00081
00082 jack_nframes_t fHostBufferSize;
00083 jack_nframes_t fHostSampleRate;
00084
00085
00086 jack_nframes_t fAdaptedBufferSize;
00087 jack_nframes_t fAdaptedSampleRate;
00088
00089
00090 JackAtomicDelayLockedLoop fHostDLL;
00091 JackAtomicDelayLockedLoop fAdaptedDLL;
00092
00093 JackResampler** fCaptureRingBuffer;
00094 JackResampler** fPlaybackRingBuffer;
00095
00096 unsigned int fQuality;
00097
00098 bool fRunning;
00099
00100 public:
00101
00102 JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ) :
00103 fCaptureChannels ( 0 ),
00104 fPlaybackChannels ( 0 ),
00105 fHostBufferSize ( buffer_size ),
00106 fHostSampleRate ( sample_rate ),
00107 fAdaptedBufferSize ( buffer_size),
00108 fAdaptedSampleRate ( sample_rate ),
00109 fHostDLL ( buffer_size, sample_rate ),
00110 fAdaptedDLL ( buffer_size, sample_rate ),
00111 fQuality(0),
00112 fRunning ( false )
00113 {}
00114
00115 virtual ~JackAudioAdapterInterface()
00116 {}
00117
00118 void SetRingBuffers ( JackResampler** input, JackResampler** output )
00119 {
00120 fCaptureRingBuffer = input;
00121 fPlaybackRingBuffer = output;
00122 }
00123
00124 bool IsRunning()
00125 {
00126 return fRunning;
00127 }
00128
00129 virtual void Reset()
00130 {
00131 fRunning = false;
00132 }
00133
00134 void ResetRingBuffers();
00135
00136 unsigned int GetQuality()
00137 {
00138 return fQuality;
00139 }
00140
00141 virtual int Open();
00142 virtual int Close();
00143
00144 virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
00145 {
00146 fHostBufferSize = buffer_size;
00147 fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
00148 return 0;
00149 }
00150
00151 virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
00152 {
00153 fAdaptedBufferSize = buffer_size;
00154 fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
00155 return 0;
00156 }
00157
00158 virtual int SetBufferSize ( jack_nframes_t buffer_size )
00159 {
00160 SetHostBufferSize ( buffer_size );
00161 SetAdaptedBufferSize ( buffer_size );
00162 return 0;
00163 }
00164
00165 virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
00166 {
00167 fHostSampleRate = sample_rate;
00168 fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
00169 return 0;
00170 }
00171
00172 virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
00173 {
00174 fAdaptedSampleRate = sample_rate;
00175 fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
00176 return 0;
00177 }
00178
00179 virtual int SetSampleRate ( jack_nframes_t sample_rate )
00180 {
00181 SetHostSampleRate ( sample_rate );
00182 SetAdaptedSampleRate ( sample_rate );
00183 return 0;
00184 }
00185
00186 virtual void SetCallbackTime ( jack_time_t callback_usec )
00187 {
00188 fHostDLL.IncFrame ( callback_usec );
00189 }
00190
00191 void ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 );
00192
00193 void SetInputs ( int inputs )
00194 {
00195 jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
00196 fCaptureChannels = inputs;
00197 }
00198
00199 void SetOutputs ( int outputs )
00200 {
00201 jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
00202 fPlaybackChannels = outputs;
00203 }
00204
00205 int GetInputs()
00206 {
00207 jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
00208 return fCaptureChannels;
00209 }
00210
00211 int GetOutputs()
00212 {
00213 jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
00214 return fPlaybackChannels;
00215 }
00216
00217 };
00218
00219 }
00220
00221 #endif