Rename system_midi:* back to system:midi_*
[jack2.git] / common / JackAudioAdapterInterface.h
blob36be35aa863e840c0b5c4179ef5250ec942311c9
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 <stdio.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(unsigned int fHostBufferSize, unsigned int fHostSampleRate, unsigned int fAdaptedSampleRate, unsigned int fAdaptedBufferSize);
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 //PI controller
86 JackPIControler fPIControler;
88 JackResampler** fCaptureRingBuffer;
89 JackResampler** fPlaybackRingBuffer;
91 unsigned int fQuality;
92 unsigned int fRingbufferCurSize;
93 jack_time_t fPullAndPushTime;
95 bool fRunning;
96 bool fAdaptative;
98 void ResetRingBuffers();
99 void AdaptRingBufferSize();
100 void GrowRingBufferSize();
102 public:
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)
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)
139 virtual ~JackAudioAdapterInterface()
142 virtual void Reset();
144 virtual void Create();
145 virtual void Destroy();
147 virtual int Open()
149 return 0;
152 virtual int Close()
154 return 0;
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();
168 virtual int GetInputLatency(int port_index) { return 0; }
169 virtual int GetOutputLatency(int port_index) { return 0; }
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);
178 #endif