Fix for profiling mode.
[jack2.git] / common / JackAudioAdapterInterface.h
blob83b151098daab8ba68da894c1bfd480e697ca1bb
1 /*
2 Copyright (C) 2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __JackAudioAdapterInterface__
21 #define __JackAudioAdapterInterface__
23 #include "JackResampler.h"
24 #include "JackFilters.h"
25 #include "JackConstants.h"
27 namespace Jack
30 #ifdef JACK_MONITOR
32 #define TABLE_MAX 100000
34 struct Measure
36 int delta;
37 int time1;
38 int time2;
39 float r1;
40 float r2;
41 int pos1;
42 int pos2;
45 struct MeasureTable
48 Measure fTable[TABLE_MAX];
49 int fCount;
51 MeasureTable() :fCount ( 0 )
54 void Write ( int time1, int time2, float r1, float r2, int pos1, int pos2 );
55 void Save();
59 #endif
61 /*!
62 \brief Base class for audio adapters.
65 class JackAudioAdapterInterface
68 protected:
70 #ifdef JACK_MONITOR
71 MeasureTable fTable;
72 #endif
73 //channels
74 int fCaptureChannels;
75 int fPlaybackChannels;
77 //host parameters
78 jack_nframes_t fHostBufferSize;
79 jack_nframes_t fHostSampleRate;
81 //adapted parameters
82 jack_nframes_t fAdaptedBufferSize;
83 jack_nframes_t fAdaptedSampleRate;
85 //delay locked loop
86 JackAtomicDelayLockedLoop fHostDLL;
87 JackAtomicDelayLockedLoop fAdaptedDLL;
89 JackResampler** fCaptureRingBuffer;
90 JackResampler** fPlaybackRingBuffer;
92 unsigned int fQuality;
94 bool fRunning;
96 public:
98 JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ) :
99 fCaptureChannels ( 0 ),
100 fPlaybackChannels ( 0 ),
101 fHostBufferSize ( buffer_size ),
102 fHostSampleRate ( sample_rate ),
103 fAdaptedBufferSize ( buffer_size),
104 fAdaptedSampleRate ( sample_rate ),
105 fHostDLL ( buffer_size, sample_rate ),
106 fAdaptedDLL ( buffer_size, sample_rate ),
107 fQuality(0),
108 fRunning ( false )
111 virtual ~JackAudioAdapterInterface()
114 void SetRingBuffers ( JackResampler** input, JackResampler** output )
116 fCaptureRingBuffer = input;
117 fPlaybackRingBuffer = output;
120 bool IsRunning()
122 return fRunning;
125 virtual void Reset()
127 fRunning = false;
130 void ResetRingBuffers();
132 unsigned int GetQuality()
134 return fQuality;
137 virtual int Open();
138 virtual int Close();
140 virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
142 fHostBufferSize = buffer_size;
143 fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
144 return 0;
147 virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
149 fAdaptedBufferSize = buffer_size;
150 fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
151 return 0;
154 virtual int SetBufferSize ( jack_nframes_t buffer_size )
156 SetHostBufferSize ( buffer_size );
157 SetAdaptedBufferSize ( buffer_size );
158 return 0;
161 virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
163 fHostSampleRate = sample_rate;
164 fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
165 return 0;
168 virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
170 fAdaptedSampleRate = sample_rate;
171 fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
172 return 0;
175 virtual int SetSampleRate ( jack_nframes_t sample_rate )
177 SetHostSampleRate ( sample_rate );
178 SetAdaptedSampleRate ( sample_rate );
179 return 0;
182 virtual void SetCallbackTime ( jack_time_t callback_usec )
184 fHostDLL.IncFrame ( callback_usec );
187 void ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 );
189 void SetInputs ( int inputs )
191 jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
192 fCaptureChannels = inputs;
195 void SetOutputs ( int outputs )
197 jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
198 fPlaybackChannels = outputs;
201 int GetInputs()
203 jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
204 return fCaptureChannels;
207 int GetOutputs()
209 jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
210 return fPlaybackChannels;
217 #endif