JackResampler.h 2.06 KB
Newer Older
sletz's avatar
sletz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
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.

*/

#ifndef __JackResampler__
#define __JackResampler__

#include "ringbuffer.h"
#include "JackError.h"
sletz's avatar
sletz committed
25

sletz's avatar
sletz committed
26
27
28
namespace Jack
{

sletz's avatar
sletz committed
29
#define DEFAULT_RB_SIZE 16384	
sletz's avatar
sletz committed
30

sletz's avatar
sletz committed
31
32
33
34
35
inline float Range(float min, float max, float val)
{
    return (val < min) ? min : ((val > max) ? max : val);
}
    
sletz's avatar
sletz committed
36
37
38
39
40
41
42
43
44
45
/*!
\brief Base class for Resampler.
*/

class JackResampler
{

    protected:
    
        jack_ringbuffer_t* fRingBuffer;
sletz's avatar
sletz committed
46
        double fRatio;
sletz's avatar
sletz committed
47
48
        unsigned int fRingBufferSize;
       
sletz's avatar
sletz committed
49
    public:
sletz's avatar
sletz committed
50
    
sletz's avatar
sletz committed
51
        JackResampler();
sletz's avatar
sletz committed
52
        JackResampler(unsigned int ringbuffer_size);
sletz's avatar
sletz committed
53
        virtual ~JackResampler();
sletz's avatar
sletz committed
54
        
sletz's avatar
sletz committed
55
        virtual void Reset();
sletz's avatar
sletz committed
56
        
sletz's avatar
sletz committed
57
58
59
60
61
62
63
64
        virtual unsigned int ReadResample(float* buffer, unsigned int frames);
        virtual unsigned int WriteResample(float* buffer, unsigned int frames);
        
        virtual unsigned int Read(float* buffer, unsigned int frames);
        virtual unsigned int Write(float* buffer, unsigned int frames);
        
        virtual unsigned int ReadSpace();
        virtual unsigned int WriteSpace();
sletz's avatar
sletz committed
65
66
67
68
69
        
        unsigned int GetOffset()
        {
            return (jack_ringbuffer_read_space(fRingBuffer) / sizeof(float)) - (fRingBufferSize / 2);
        }
sletz's avatar
sletz committed
70

sletz's avatar
sletz committed
71
        void SetRatio(double ratio)
sletz's avatar
sletz committed
72
        {
sletz's avatar
sletz committed
73
            fRatio = Range(0.25, 4.0, ratio);
sletz's avatar
sletz committed
74
        }
sletz's avatar
sletz committed
75
76
        
        double GetRatio()
sletz's avatar
sletz committed
77
        {
sletz's avatar
sletz committed
78
            return fRatio;
sletz's avatar
sletz committed
79
80
81
        }
 
    };
sletz's avatar
sletz committed
82
83
84
}

#endif