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"
25 #include "JackError.h"
26 #include "JackResampler.h"
27 #include "JackFilters.h"
28 #include <samplerate.h>
35 #define TABLE_MAX 100000
51 Measure fTable
[TABLE_MAX
];
54 MeasureTable() :fCount ( 0 )
57 void Write ( int time1
, int time2
, float r1
, float r2
, int pos1
, int pos2
);
65 \brief Base class for audio adapters.
68 class JackAudioAdapterInterface
78 int fPlaybackChannels
;
81 jack_nframes_t fHostBufferSize
;
82 jack_nframes_t fHostSampleRate
;
85 jack_nframes_t fAdaptedBufferSize
;
86 jack_nframes_t fAdaptedSampleRate
;
89 JackAtomicDelayLockedLoop fHostDLL
;
90 JackAtomicDelayLockedLoop fAdaptedDLL
;
92 JackResampler
** fCaptureRingBuffer
;
93 JackResampler
** fPlaybackRingBuffer
;
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
),
111 virtual ~JackAudioAdapterInterface()
114 void SetRingBuffers ( JackResampler
** input
, JackResampler
** output
)
116 fCaptureRingBuffer
= input
;
117 fPlaybackRingBuffer
= output
;
130 void ResetRingBuffers();
135 virtual int SetHostBufferSize ( jack_nframes_t buffer_size
)
137 fHostBufferSize
= buffer_size
;
138 fHostDLL
.Init ( fHostBufferSize
, fHostSampleRate
);
142 virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size
)
144 fAdaptedBufferSize
= buffer_size
;
145 fAdaptedDLL
.Init ( fAdaptedBufferSize
, fAdaptedSampleRate
);
149 virtual int SetBufferSize ( jack_nframes_t buffer_size
)
151 SetHostBufferSize ( buffer_size
);
152 SetAdaptedBufferSize ( buffer_size
);
156 virtual int SetHostSampleRate ( jack_nframes_t sample_rate
)
158 fHostSampleRate
= sample_rate
;
159 fHostDLL
.Init ( fHostBufferSize
, fHostSampleRate
);
163 virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate
)
165 fAdaptedSampleRate
= sample_rate
;
166 fAdaptedDLL
.Init ( fAdaptedBufferSize
, fAdaptedSampleRate
);
170 virtual int SetSampleRate ( jack_nframes_t sample_rate
)
172 SetHostSampleRate ( sample_rate
);
173 SetAdaptedSampleRate ( sample_rate
);
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
;
198 jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels
);
199 return fCaptureChannels
;
204 jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels
);
205 return fPlaybackChannels
;