Jack2 1.9.8
|
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 <stdio.h> 00026 00027 namespace Jack 00028 { 00029 00030 #ifdef JACK_MONITOR 00031 00032 #define TABLE_MAX 100000 00033 00034 struct Measure 00035 { 00036 int delta; 00037 int time1; 00038 int time2; 00039 float r1; 00040 float r2; 00041 int pos1; 00042 int pos2; 00043 }; 00044 00045 struct MeasureTable 00046 { 00047 00048 Measure fTable[TABLE_MAX]; 00049 int fCount; 00050 00051 MeasureTable() :fCount(0) 00052 {} 00053 00054 void Write(int time1, int time2, float r1, float r2, int pos1, int pos2); 00055 void Save(unsigned int fHostBufferSize, unsigned int fHostSampleRate, unsigned int fAdaptedSampleRate, unsigned int fAdaptedBufferSize); 00056 00057 }; 00058 00059 #endif 00060 00065 class JackAudioAdapterInterface 00066 { 00067 00068 protected: 00069 00070 #ifdef JACK_MONITOR 00071 MeasureTable fTable; 00072 #endif 00073 //channels 00074 int fCaptureChannels; 00075 int fPlaybackChannels; 00076 00077 //host parameters 00078 jack_nframes_t fHostBufferSize; 00079 jack_nframes_t fHostSampleRate; 00080 00081 //adapted parameters 00082 jack_nframes_t fAdaptedBufferSize; 00083 jack_nframes_t fAdaptedSampleRate; 00084 00085 //PI controler 00086 JackPIControler fPIControler; 00087 00088 JackResampler** fCaptureRingBuffer; 00089 JackResampler** fPlaybackRingBuffer; 00090 00091 unsigned int fQuality; 00092 unsigned int fRingbufferCurSize; 00093 jack_time_t fPullAndPushTime; 00094 00095 bool fRunning; 00096 bool fAdaptative; 00097 00098 void ResetRingBuffers(); 00099 void AdaptRingBufferSize(); 00100 void GrowRingBufferSize(); 00101 00102 public: 00103 00104 JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate, jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE): 00105 fCaptureChannels(0), 00106 fPlaybackChannels(0), 00107 fHostBufferSize(buffer_size), 00108 fHostSampleRate(sample_rate), 00109 fAdaptedBufferSize(buffer_size), 00110 fAdaptedSampleRate(sample_rate), 00111 fPIControler(sample_rate / sample_rate, 256), 00112 fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL), 00113 fQuality(0), 00114 fRingbufferCurSize(ring_buffer_size), 00115 fPullAndPushTime(0), 00116 fRunning(false), 00117 fAdaptative(true) 00118 {} 00119 00120 JackAudioAdapterInterface(jack_nframes_t host_buffer_size, 00121 jack_nframes_t host_sample_rate, 00122 jack_nframes_t adapted_buffer_size, 00123 jack_nframes_t adapted_sample_rate, 00124 jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE) : 00125 fCaptureChannels(0), 00126 fPlaybackChannels(0), 00127 fHostBufferSize(host_buffer_size), 00128 fHostSampleRate(host_sample_rate), 00129 fAdaptedBufferSize(adapted_buffer_size), 00130 fAdaptedSampleRate(adapted_sample_rate), 00131 fPIControler(host_sample_rate / host_sample_rate, 256), 00132 fQuality(0), 00133 fRingbufferCurSize(ring_buffer_size), 00134 fPullAndPushTime(0), 00135 fRunning(false), 00136 fAdaptative(true) 00137 {} 00138 00139 virtual ~JackAudioAdapterInterface() 00140 {} 00141 00142 virtual void Reset(); 00143 00144 virtual void Create(); 00145 virtual void Destroy(); 00146 00147 virtual int Open() 00148 { 00149 return 0; 00150 } 00151 00152 virtual int Close() 00153 { 00154 return 0; 00155 } 00156 00157 virtual int SetHostBufferSize(jack_nframes_t buffer_size) 00158 { 00159 fHostBufferSize = buffer_size; 00160 if (fAdaptative) { 00161 AdaptRingBufferSize(); 00162 } 00163 return 0; 00164 } 00165 00166 virtual int SetAdaptedBufferSize(jack_nframes_t buffer_size) 00167 { 00168 fAdaptedBufferSize = buffer_size; 00169 if (fAdaptative) { 00170 AdaptRingBufferSize(); 00171 } 00172 return 0; 00173 } 00174 00175 virtual int SetBufferSize(jack_nframes_t buffer_size) 00176 { 00177 SetHostBufferSize(buffer_size); 00178 SetAdaptedBufferSize(buffer_size); 00179 return 0; 00180 } 00181 00182 virtual int SetHostSampleRate(jack_nframes_t sample_rate) 00183 { 00184 fHostSampleRate = sample_rate; 00185 fPIControler.Init(double(fHostSampleRate) / double(fAdaptedSampleRate)); 00186 return 0; 00187 } 00188 00189 virtual int SetAdaptedSampleRate(jack_nframes_t sample_rate) 00190 { 00191 fAdaptedSampleRate = sample_rate; 00192 fPIControler.Init(double(fHostSampleRate) / double(fAdaptedSampleRate)); 00193 return 0; 00194 } 00195 00196 virtual int SetSampleRate(jack_nframes_t sample_rate) 00197 { 00198 SetHostSampleRate(sample_rate); 00199 SetAdaptedSampleRate(sample_rate); 00200 return 0; 00201 } 00202 00203 void SetInputs(int inputs) 00204 { 00205 jack_log("JackAudioAdapterInterface::SetInputs %d", inputs); 00206 fCaptureChannels = inputs; 00207 } 00208 00209 void SetOutputs(int outputs) 00210 { 00211 jack_log("JackAudioAdapterInterface::SetOutputs %d", outputs); 00212 fPlaybackChannels = outputs; 00213 } 00214 00215 int GetInputs() 00216 { 00217 //jack_log("JackAudioAdapterInterface::GetInputs %d", fCaptureChannels); 00218 return fCaptureChannels; 00219 } 00220 00221 int GetOutputs() 00222 { 00223 //jack_log ("JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels); 00224 return fPlaybackChannels; 00225 } 00226 00227 virtual int GetInputLatency(int port_index) { return 0; } 00228 virtual int GetOutputLatency(int port_index) { return 0; } 00229 00230 int PushAndPull(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames); 00231 int PullAndPush(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames); 00232 00233 }; 00234 00235 } 00236 00237 #endif