Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 Sonic Visualiser
|
Chris@0
|
5 An audio file viewer and annotation editor.
|
Chris@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@0
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@0
|
9 This program is free software; you can redistribute it and/or
|
Chris@0
|
10 modify it under the terms of the GNU General Public License as
|
Chris@0
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@0
|
12 License, or (at your option) any later version. See the file
|
Chris@0
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #ifndef _INTEGER_TIME_STRETCHER_H_
|
Chris@0
|
17 #define _INTEGER_TIME_STRETCHER_H_
|
Chris@0
|
18
|
Chris@0
|
19 #include "base/Window.h"
|
Chris@0
|
20 #include "base/RingBuffer.h"
|
Chris@0
|
21
|
Chris@0
|
22 #include <fftw3.h>
|
Chris@0
|
23
|
Chris@0
|
24 /**
|
Chris@0
|
25 * A time stretcher that slows down audio by an integer multiple of
|
Chris@0
|
26 * its original duration, preserving pitch. This uses the simple
|
Chris@0
|
27 * phase vocoder technique from DAFX pp275-276, adding a block-based
|
Chris@0
|
28 * stream oriented API.
|
Chris@0
|
29 *
|
Chris@0
|
30 * Causes significant transient smearing, but sounds good for steady
|
Chris@0
|
31 * notes and is generally predictable.
|
Chris@0
|
32 */
|
Chris@0
|
33
|
Chris@0
|
34 class IntegerTimeStretcher
|
Chris@0
|
35 {
|
Chris@0
|
36 public:
|
Chris@12
|
37 IntegerTimeStretcher(float ratio,
|
Chris@0
|
38 size_t maxProcessInputBlockSize,
|
Chris@0
|
39 size_t inputIncrement = 64,
|
Chris@0
|
40 size_t windowSize = 2048,
|
Chris@0
|
41 WindowType windowType = HanningWindow);
|
Chris@0
|
42 virtual ~IntegerTimeStretcher();
|
Chris@0
|
43
|
Chris@12
|
44 /**
|
Chris@12
|
45 * Process a block. The input array contains the given number of
|
Chris@12
|
46 * samples; the output has enough space for samples * m_ratio.
|
Chris@12
|
47 */
|
Chris@0
|
48 void process(float *input, float *output, size_t samples);
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * Get the hop size for input. Smaller values may produce better
|
Chris@0
|
52 * results, at a cost in processing time. Larger values are
|
Chris@0
|
53 * faster but increase the likelihood of echo-like effects. The
|
Chris@0
|
54 * default is 64, which is usually pretty good, though heavy on
|
Chris@0
|
55 * processor power.
|
Chris@0
|
56 */
|
Chris@0
|
57 size_t getInputIncrement() const { return m_n1; }
|
Chris@0
|
58
|
Chris@0
|
59 /**
|
Chris@0
|
60 * Get the window size for FFT processing. Must be larger than
|
Chris@0
|
61 * the input and output increments. The default is 2048.
|
Chris@0
|
62 */
|
Chris@0
|
63 size_t getWindowSize() const { return m_wlen; }
|
Chris@0
|
64
|
Chris@0
|
65 /**
|
Chris@0
|
66 * Get the window type. The default is a Hanning window.
|
Chris@0
|
67 */
|
Chris@0
|
68 WindowType getWindowType() const { return m_window->getType(); }
|
Chris@0
|
69
|
Chris@12
|
70 float getRatio() const { return m_ratio; }
|
Chris@0
|
71 size_t getOutputIncrement() const { return getInputIncrement() * getRatio(); }
|
Chris@0
|
72 size_t getProcessingLatency() const;
|
Chris@0
|
73
|
Chris@0
|
74 protected:
|
Chris@0
|
75 void processBlock(float *in, float *out);
|
Chris@0
|
76
|
Chris@12
|
77 float m_ratio;
|
Chris@0
|
78 size_t m_n1;
|
Chris@0
|
79 size_t m_n2;
|
Chris@0
|
80 size_t m_wlen;
|
Chris@0
|
81 Window<float> *m_window;
|
Chris@0
|
82
|
Chris@0
|
83 fftwf_complex *m_time;
|
Chris@0
|
84 fftwf_complex *m_freq;
|
Chris@0
|
85 float *m_dbuf;
|
Chris@12
|
86 float *m_prevPhase;
|
Chris@12
|
87 float *m_prevAdjustedPhase;
|
Chris@0
|
88
|
Chris@0
|
89 fftwf_plan m_plan;
|
Chris@0
|
90 fftwf_plan m_iplan;
|
Chris@0
|
91
|
Chris@0
|
92 RingBuffer<float> m_inbuf;
|
Chris@0
|
93 RingBuffer<float> m_outbuf;
|
Chris@0
|
94 float *m_mashbuf;
|
Chris@0
|
95 };
|
Chris@0
|
96
|
Chris@0
|
97 #endif
|