Jack2 1.9.6
|
00001 /* 00002 Copyright (C) 2008 Grame 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 00018 */ 00019 00020 #ifndef __JackAudioAdapterInterface__ 00021 #define __JackAudioAdapterInterface__ 00022 00023 #include "JackResampler.h" 00024 #include "JackFilters.h" 00025 #include "JackConstants.h" 00026 #include <stdio.h> 00027 00028 namespace Jack 00029 { 00030 00031 #ifdef JACK_MONITOR 00032 00033 #define TABLE_MAX 100000 00034 00035 struct Measure 00036 { 00037 int delta; 00038 int time1; 00039 int time2; 00040 float r1; 00041 float r2; 00042 int pos1; 00043 int pos2; 00044 }; 00045 00046 struct MeasureTable 00047 { 00048 00049 Measure fTable[TABLE_MAX]; 00050 int fCount; 00051 00052 MeasureTable() :fCount ( 0 ) 00053 {} 00054 00055 void Write(int time1, int time2, float r1, float r2, int pos1, int pos2); 00056 void Save(unsigned int fHostBufferSize, unsigned int fHostSampleRate, unsigned int fAdaptedSampleRate, unsigned int fAdaptedBufferSize); 00057 00058 }; 00059 00060 #endif 00061 00066 class JackAudioAdapterInterface 00067 { 00068 00069 protected: 00070 00071 #ifdef JACK_MONITOR 00072 MeasureTable fTable; 00073 #endif 00074 //channels 00075 int fCaptureChannels; 00076 int fPlaybackChannels; 00077 00078 //host parameters 00079 jack_nframes_t fHostBufferSize; 00080 jack_nframes_t fHostSampleRate; 00081 00082 //adapted parameters 00083 jack_nframes_t fAdaptedBufferSize; 00084 jack_nframes_t fAdaptedSampleRate; 00085 00086 //PI controler 00087 JackPIControler fPIControler; 00088 00089 JackResampler** fCaptureRingBuffer; 00090 JackResampler** fPlaybackRingBuffer; 00091 00092 unsigned int fQuality; 00093 unsigned int fRingbufferCurSize; 00094 jack_time_t fPullAndPushTime; 00095 00096 bool fRunning; 00097 bool fAdaptative; 00098 00099 void ResetRingBuffers(); 00100 void AdaptRingBufferSize(); 00101 void GrowRingBufferSize(); 00102 00103 public: 00104 00105 JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ): 00106 fCaptureChannels ( 0 ), 00107 fPlaybackChannels ( 0 ), 00108 fHostBufferSize ( buffer_size ), 00109 fHostSampleRate ( sample_rate ), 00110 fAdaptedBufferSize ( buffer_size), 00111 fAdaptedSampleRate ( sample_rate ), 00112 fPIControler(sample_rate / sample_rate, 256), 00113 fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL), 00114 fQuality(0), 00115 fRingbufferCurSize(DEFAULT_ADAPTATIVE_SIZE), 00116 fPullAndPushTime(0), 00117 fRunning(false), 00118 fAdaptative(true) 00119 {} 00120 00121 virtual ~JackAudioAdapterInterface() 00122 {} 00123 00124 virtual void Reset(); 00125 00126 void Create(); 00127 void Destroy(); 00128 00129 virtual int Open() 00130 { 00131 return 0; 00132 } 00133 00134 virtual int Close() 00135 { 00136 return 0; 00137 } 00138 00139 virtual int SetHostBufferSize ( jack_nframes_t buffer_size ) 00140 { 00141 fHostBufferSize = buffer_size; 00142 if (fAdaptative) 00143 AdaptRingBufferSize(); 00144 return 0; 00145 } 00146 00147 virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size ) 00148 { 00149 fAdaptedBufferSize = buffer_size; 00150 if (fAdaptative) 00151 AdaptRingBufferSize(); 00152 return 0; 00153 } 00154 00155 virtual int SetBufferSize ( jack_nframes_t buffer_size ) 00156 { 00157 SetHostBufferSize ( buffer_size ); 00158 SetAdaptedBufferSize ( buffer_size ); 00159 return 0; 00160 } 00161 00162 virtual int SetHostSampleRate ( jack_nframes_t sample_rate ) 00163 { 00164 fHostSampleRate = sample_rate; 00165 fPIControler.Init(double(fHostSampleRate) / double(fAdaptedSampleRate)); 00166 return 0; 00167 } 00168 00169 virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate ) 00170 { 00171 fAdaptedSampleRate = sample_rate; 00172 fPIControler.Init(double(fHostSampleRate) / double(fAdaptedSampleRate)); 00173 return 0; 00174 } 00175 00176 virtual int SetSampleRate ( jack_nframes_t sample_rate ) 00177 { 00178 SetHostSampleRate ( sample_rate ); 00179 SetAdaptedSampleRate ( sample_rate ); 00180 return 0; 00181 } 00182 00183 void SetInputs ( int inputs ) 00184 { 00185 jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs ); 00186 fCaptureChannels = inputs; 00187 } 00188 00189 void SetOutputs ( int outputs ) 00190 { 00191 jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs ); 00192 fPlaybackChannels = outputs; 00193 } 00194 00195 int GetInputs() 00196 { 00197 jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels ); 00198 return fCaptureChannels; 00199 } 00200 00201 int GetOutputs() 00202 { 00203 jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels ); 00204 return fPlaybackChannels; 00205 } 00206 00207 int PushAndPull(float** inputBuffer, float** outputBuffer, unsigned int inNumberFrames); 00208 int PullAndPush(float** inputBuffer, float** outputBuffer, unsigned int inNumberFrames); 00209 00210 }; 00211 00212 } 00213 00214 #endif