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"
32 #define TABLE_MAX 100000
48 Measure fTable
[TABLE_MAX
];
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
);
62 \brief Base class for audio adapters.
65 class JackAudioAdapterInterface
75 int fPlaybackChannels
;
78 jack_nframes_t fHostBufferSize
;
79 jack_nframes_t fHostSampleRate
;
82 jack_nframes_t fAdaptedBufferSize
;
83 jack_nframes_t fAdaptedSampleRate
;
86 JackPIControler fPIControler
;
88 JackResampler
** fCaptureRingBuffer
;
89 JackResampler
** fPlaybackRingBuffer
;
91 unsigned int fQuality
;
92 unsigned int fRingbufferCurSize
;
93 jack_time_t fPullAndPushTime
;
98 void ResetRingBuffers();
99 void AdaptRingBufferSize();
100 void GrowRingBufferSize();
104 JackAudioAdapterInterface(jack_nframes_t buffer_size
, jack_nframes_t sample_rate
, jack_nframes_t ring_buffer_size
= DEFAULT_ADAPTATIVE_SIZE
):
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
),
114 fRingbufferCurSize(ring_buffer_size
),
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
) :
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),
133 fRingbufferCurSize(ring_buffer_size
),
139 virtual ~JackAudioAdapterInterface()
142 virtual void Reset();
144 virtual void Create();
145 virtual void Destroy();
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
);
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
);