ff110d14b683b76424ed67ad798f560382dbffc7
[ardour.git] / libs / rubberband / src / StretcherChannelData.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     Rubber Band
5     An audio time-stretching and pitch-shifting library.
6     Copyright 2007 Chris Cannam.
7     
8     This program is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License as
10     published by the Free Software Foundation; either version 2 of the
11     License, or (at your option) any later version.  See the file
12     COPYING included with this distribution for more information.
13 */
14
15 #ifndef _RUBBERBAND_STRETCHERCHANNELDATA_H_
16 #define _RUBBERBAND_STRETCHERCHANNELDATA_H_
17
18 #include "StretcherImpl.h"
19
20 #include <set>
21
22 namespace RubberBand
23 {
24
25 class Resampler;
26         
27 class RubberBandStretcher::Impl::ChannelData
28 {
29 public:        
30     /**
31      * Construct a ChannelData structure.
32      *
33      * The window size passed in here is the size for the FFT
34      * calculation, and most of the buffer sizes also depend on
35      * it.  In practice it is always a power of two and except for
36      * very extreme stretches is always either 1024, 2048 or 4096.
37      *
38      * The outbuf size depends on other factors as well, including
39      * the pitch scale factor and any maximum processing block
40      * size specified by the user of the code.
41      */
42     ChannelData(size_t windowSize, size_t outbufSize);
43
44     /**
45      * Construct a ChannelData structure that can process at
46      * different FFT sizes without requiring reallocation when the
47      * size changes.  The size can subsequently be changed with a
48      * call to setWindowSize.  Reallocation will only be necessary
49      * if setWindowSize is called with a value not equal to one of
50      * those passed in to the constructor.
51      *
52      * The outbufSize should be the maximum possible outbufSize to
53      * avoid reallocation, which will happen if setOutbufSize is
54      * called subsequently.
55      */
56     ChannelData(const std::set<size_t> &windowSizes,
57                 size_t initialWindowSize, size_t outbufSize);
58     ~ChannelData();
59
60     /**
61      * Reset buffers
62      */
63     void reset();
64
65     /**
66      * Set the FFT and buffer sizes from the given processing
67      * window size.  If this ChannelData was constructed with a set
68      * of window sizes and the given window size here was among
69      * them, no reallocation will be required.
70      */
71     void setWindowSize(size_t windowSize);
72
73     /**
74      * Set the outbufSize for the channel data.  Reallocation will
75      * occur.
76      */
77     void setOutbufSize(size_t outbufSize);
78
79     RingBuffer<float> *inbuf;
80     RingBuffer<float> *outbuf;
81
82     double *mag;
83     double *phase;
84
85     double *prevPhase;
86     double *unwrappedPhase;
87
88     size_t *freqPeak;
89
90     float *accumulator;
91     size_t accumulatorFill;
92     float *windowAccumulator;
93
94     float *fltbuf;
95     double *dblbuf; // owned by FFT object, only used for time domain FFT i/o
96
97     size_t prevIncrement; // only used in RT mode
98
99     size_t chunkCount;
100     size_t inCount;
101     long inputSize; // set only after known (when data ended); -1 previously
102     size_t outCount;
103
104     bool draining;
105     bool outputComplete;
106
107     FFT *fft;
108     std::map<size_t, FFT *> ffts;
109
110     Resampler *resampler;
111     float *resamplebuf;
112     size_t resamplebufSize;
113
114 private:
115     void construct(const std::set<size_t> &windowSizes,
116                    size_t initialWindowSize, size_t outbufSize);
117 };        
118
119 }
120
121 #endif