Better isolation of server and clients system resources to allow starting the server...
[jack2.git] / common / JackAudioAdapterInterface.h
blob74b6bbfdb0b76191417769c8f115d2c06b7b9479
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 "ringbuffer.h"
24 #include "jack.h"
25 #include "JackError.h"
26 #include "JackResampler.h"
27 #include "JackFilters.h"
28 #include <samplerate.h>
30 namespace Jack
33 #ifdef JACK_MONITOR
35 #define TABLE_MAX 100000
37 struct Measure
39 int delta;
40 int time1;
41 int time2;
42 float r1;
43 float r2;
44 int pos1;
45 int pos2;
48 struct MeasureTable
51 Measure fTable[TABLE_MAX];
52 int fCount;
54 MeasureTable() :fCount ( 0 )
57 void Write ( int time1, int time2, float r1, float r2, int pos1, int pos2 );
58 void Save();
62 #endif
64 /*!
65 \brief Base class for audio adapters.
68 class JackAudioAdapterInterface
71 protected:
73 #ifdef JACK_MONITOR
74 MeasureTable fTable;
75 #endif
76 //channels
77 int fCaptureChannels;
78 int fPlaybackChannels;
80 //host parameters
81 jack_nframes_t fHostBufferSize;
82 jack_nframes_t fHostSampleRate;
84 //adapted parameters
85 jack_nframes_t fAdaptedBufferSize;
86 jack_nframes_t fAdaptedSampleRate;
88 //delay locked loop
89 JackAtomicDelayLockedLoop fHostDLL;
90 JackAtomicDelayLockedLoop fAdaptedDLL;
92 JackResampler** fCaptureRingBuffer;
93 JackResampler** fPlaybackRingBuffer;
95 bool fRunning;
97 public:
99 JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ) :
100 fCaptureChannels ( 0 ),
101 fPlaybackChannels ( 0 ),
102 fHostBufferSize ( buffer_size ),
103 fHostSampleRate ( sample_rate ),
104 fAdaptedBufferSize ( buffer_size),
105 fAdaptedSampleRate ( sample_rate ),
106 fHostDLL ( buffer_size, sample_rate ),
107 fAdaptedDLL ( buffer_size, sample_rate ),
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 virtual int Open();
133 virtual int Close();
135 virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
137 fHostBufferSize = buffer_size;
138 fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
139 return 0;
142 virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
144 fAdaptedBufferSize = buffer_size;
145 fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
146 return 0;
149 virtual int SetBufferSize ( jack_nframes_t buffer_size )
151 SetHostBufferSize ( buffer_size );
152 SetAdaptedBufferSize ( buffer_size );
153 return 0;
156 virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
158 fHostSampleRate = sample_rate;
159 fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
160 return 0;
163 virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
165 fAdaptedSampleRate = sample_rate;
166 fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
167 return 0;
170 virtual int SetSampleRate ( jack_nframes_t sample_rate )
172 SetHostSampleRate ( sample_rate );
173 SetAdaptedSampleRate ( sample_rate );
174 return 0;
177 virtual void SetCallbackTime ( jack_time_t callback_usec )
179 fHostDLL.IncFrame ( callback_usec );
182 void ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 );
184 void SetInputs ( int inputs )
186 jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
187 fCaptureChannels = inputs;
190 void SetOutputs ( int outputs )
192 jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
193 fPlaybackChannels = outputs;
196 int GetInputs()
198 jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
199 return fCaptureChannels;
202 int GetOutputs()
204 jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
205 return fPlaybackChannels;
212 #endif