JackAudioAdapterInterface.h 5.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
Copyright (C) 2008 Grame

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

sletz's avatar
sletz committed
20
21
#ifndef __JackAudioAdapterInterface__
#define __JackAudioAdapterInterface__
22

sletz's avatar
sletz committed
23
#include "JackResampler.h"
sletz's avatar
sletz committed
24
#include "JackFilters.h"
sletz's avatar
sletz committed
25
#include "JackConstants.h"
sletz's avatar
sletz committed
26

27
28
29
namespace Jack
{

30
31
#ifdef JACK_MONITOR

sletz's avatar
sletz committed
32
33
#define TABLE_MAX 100000

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    struct Measure
    {
        int delta;
        int time1;
        int time2;
        float r1;
        float r2;
        int pos1;
        int pos2;
    };

    struct MeasureTable
    {

        Measure fTable[TABLE_MAX];
        int fCount;

        MeasureTable() :fCount ( 0 )
        {}
sletz's avatar
sletz committed
53

54
55
        void Write ( int time1, int time2, float r1, float r2, int pos1, int pos2 );
        void Save();
sletz's avatar
sletz committed
56

57
    };
sletz's avatar
sletz committed
58

59
60
#endif

61
62
63
    /*!
    \brief Base class for audio adapters.
    */
sletz's avatar
sletz committed
64

65
66
    class JackAudioAdapterInterface
    {
moret's avatar
moret committed
67

68
    protected:
moret's avatar
moret committed
69

70
#ifdef JACK_MONITOR
71
        MeasureTable fTable;
72
#endif
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
        //channels
        int fCaptureChannels;
        int fPlaybackChannels;

        //host parameters
        jack_nframes_t fHostBufferSize;
        jack_nframes_t fHostSampleRate;

        //adapted parameters
        jack_nframes_t fAdaptedBufferSize;
        jack_nframes_t fAdaptedSampleRate;

        //delay locked loop
        JackAtomicDelayLockedLoop fHostDLL;
        JackAtomicDelayLockedLoop fAdaptedDLL;

        JackResampler** fCaptureRingBuffer;
        JackResampler** fPlaybackRingBuffer;
91
92
        
        unsigned int fQuality;
93
94
95
96
97
98
99
100
101
102
103
104
105
106

        bool fRunning;

    public:

        JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate ) :
                fCaptureChannels ( 0 ),
                fPlaybackChannels ( 0 ),
                fHostBufferSize ( buffer_size ),
                fHostSampleRate ( sample_rate ),
                fAdaptedBufferSize ( buffer_size),
                fAdaptedSampleRate ( sample_rate ),
                fHostDLL ( buffer_size, sample_rate ),
                fAdaptedDLL ( buffer_size, sample_rate ),
107
                fQuality(0),
108
109
110
111
112
                fRunning ( false )
        {}

        virtual ~JackAudioAdapterInterface()
        {}
moret's avatar
moret committed
113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
        void SetRingBuffers ( JackResampler** input, JackResampler** output )
        {
            fCaptureRingBuffer = input;
            fPlaybackRingBuffer = output;
        }

        bool IsRunning()
        {
            return fRunning;
        }

        virtual void Reset()
        {
            fRunning = false;
        }

        void ResetRingBuffers();
131
132
133
134
135
        
        unsigned int GetQuality()
        {
            return fQuality;
        }
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

        virtual int Open();
        virtual int Close();

        virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
        {
            fHostBufferSize = buffer_size;
            fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
            return 0;
        }

        virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
        {
            fAdaptedBufferSize = buffer_size;
            fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
            return 0;
        }

        virtual int SetBufferSize ( jack_nframes_t buffer_size )
        {
            SetHostBufferSize ( buffer_size );
            SetAdaptedBufferSize ( buffer_size );
            return 0;
        }

        virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
        {
            fHostSampleRate = sample_rate;
            fHostDLL.Init ( fHostBufferSize, fHostSampleRate );
            return 0;
        }

        virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
        {
            fAdaptedSampleRate = sample_rate;
            fAdaptedDLL.Init ( fAdaptedBufferSize, fAdaptedSampleRate );
            return 0;
        }

        virtual int SetSampleRate ( jack_nframes_t sample_rate )
        {
            SetHostSampleRate ( sample_rate );
            SetAdaptedSampleRate ( sample_rate );
            return 0;
        }

        virtual void SetCallbackTime ( jack_time_t callback_usec )
        {
            fHostDLL.IncFrame ( callback_usec );
        }

        void ResampleFactor ( jack_nframes_t& frame1, jack_nframes_t& frame2 );

        void SetInputs ( int inputs )
        {
            jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
            fCaptureChannels = inputs;
        }

        void SetOutputs ( int outputs )
        {
            jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
            fPlaybackChannels = outputs;
        }

        int GetInputs()
        {
            jack_log ( "JackAudioAdapterInterface::GetInputs %d", fCaptureChannels );
            return fCaptureChannels;
        }

        int GetOutputs()
        {
            jack_log ( "JackAudioAdapterInterface::GetOutputs %d", fPlaybackChannels );
            return fPlaybackChannels;
        }
212
213

    };
sletz's avatar
sletz committed
214

215
216
217
}

#endif