Jack2  1.9.9
JackAudioAdapterInterface.h
1 /*
2 Copyright (C) 2008 Grame
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #ifndef __JackAudioAdapterInterface__
21 #define __JackAudioAdapterInterface__
22 
23 #include "JackResampler.h"
24 #include "JackFilters.h"
25 #include <stdio.h>
26 
27 namespace Jack
28 {
29 
30 #ifdef JACK_MONITOR
31 
32 #define TABLE_MAX 100000
33 
34  struct Measure
35  {
36  int delta;
37  int time1;
38  int time2;
39  float r1;
40  float r2;
41  int pos1;
42  int pos2;
43  };
44 
45  struct MeasureTable
46  {
47 
48  Measure fTable[TABLE_MAX];
49  int fCount;
50 
51  MeasureTable() :fCount(0)
52  {}
53 
54  void Write(int time1, int time2, float r1, float r2, int pos1, int pos2);
55  void Save(unsigned int fHostBufferSize, unsigned int fHostSampleRate, unsigned int fAdaptedSampleRate, unsigned int fAdaptedBufferSize);
56 
57  };
58 
59 #endif
60 
66  {
67 
68  protected:
69 
70 #ifdef JACK_MONITOR
71  MeasureTable fTable;
72 #endif
73  //channels
74  int fCaptureChannels;
75  int fPlaybackChannels;
76 
77  //host parameters
78  jack_nframes_t fHostBufferSize;
79  jack_nframes_t fHostSampleRate;
80 
81  //adapted parameters
82  jack_nframes_t fAdaptedBufferSize;
83  jack_nframes_t fAdaptedSampleRate;
84 
85  //PI controler
86  JackPIControler fPIControler;
87 
88  JackResampler** fCaptureRingBuffer;
89  JackResampler** fPlaybackRingBuffer;
90 
91  unsigned int fQuality;
92  unsigned int fRingbufferCurSize;
93  jack_time_t fPullAndPushTime;
94 
95  bool fRunning;
96  bool fAdaptative;
97 
98  void ResetRingBuffers();
99  void AdaptRingBufferSize();
100  void GrowRingBufferSize();
101 
102  public:
103 
104  JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate, jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE):
105  fCaptureChannels(0),
106  fPlaybackChannels(0),
107  fHostBufferSize(buffer_size),
108  fHostSampleRate(sample_rate),
109  fAdaptedBufferSize(buffer_size),
110  fAdaptedSampleRate(sample_rate),
111  fPIControler(sample_rate / sample_rate, 256),
112  fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL),
113  fQuality(0),
114  fRingbufferCurSize(ring_buffer_size),
115  fPullAndPushTime(0),
116  fRunning(false),
117  fAdaptative(true)
118  {}
119 
120  JackAudioAdapterInterface(jack_nframes_t host_buffer_size,
121  jack_nframes_t host_sample_rate,
122  jack_nframes_t adapted_buffer_size,
123  jack_nframes_t adapted_sample_rate,
124  jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE) :
125  fCaptureChannels(0),
126  fPlaybackChannels(0),
127  fHostBufferSize(host_buffer_size),
128  fHostSampleRate(host_sample_rate),
129  fAdaptedBufferSize(adapted_buffer_size),
130  fAdaptedSampleRate(adapted_sample_rate),
131  fPIControler(host_sample_rate / host_sample_rate, 256),
132  fQuality(0),
133  fRingbufferCurSize(ring_buffer_size),
134  fPullAndPushTime(0),
135  fRunning(false),
136  fAdaptative(true)
137  {}
138 
139  virtual ~JackAudioAdapterInterface()
140  {}
141 
142  virtual void Reset();
143 
144  virtual void Create();
145  virtual void Destroy();
146 
147  virtual int Open()
148  {
149  return 0;
150  }
151 
152  virtual int Close()
153  {
154  return 0;
155  }
156 
157  virtual int SetHostBufferSize(jack_nframes_t buffer_size);
158  virtual int SetAdaptedBufferSize(jack_nframes_t buffer_size);
159  virtual int SetBufferSize(jack_nframes_t buffer_size);
160  virtual int SetHostSampleRate(jack_nframes_t sample_rate);
161  virtual int SetAdaptedSampleRate(jack_nframes_t sample_rate);
162  virtual int SetSampleRate(jack_nframes_t sample_rate);
163  void SetInputs(int inputs);
164  void SetOutputs(int outputs);
165  int GetInputs();
166  int GetOutputs();
167 
168  virtual int GetInputLatency(int port_index) { return 0; }
169  virtual int GetOutputLatency(int port_index) { return 0; }
170 
171  int PushAndPull(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames);
172  int PullAndPush(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames);
173 
174  };
175 
176 }
177 
178 #endif
Base class for Resampler.
Definition: JackResampler.h:41
Base class for audio adapters.