comparison audioio/IntegerTimeStretcher.h @ 0:cd5d7ff8ef38

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