annotate 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
rev   line source
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@0 37 IntegerTimeStretcher(size_t 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@0 44 void process(float *input, float *output, size_t samples);
Chris@0 45
Chris@0 46 /**
Chris@0 47 * Get the hop size for input. Smaller values may produce better
Chris@0 48 * results, at a cost in processing time. Larger values are
Chris@0 49 * faster but increase the likelihood of echo-like effects. The
Chris@0 50 * default is 64, which is usually pretty good, though heavy on
Chris@0 51 * processor power.
Chris@0 52 */
Chris@0 53 size_t getInputIncrement() const { return m_n1; }
Chris@0 54
Chris@0 55 /**
Chris@0 56 * Get the window size for FFT processing. Must be larger than
Chris@0 57 * the input and output increments. The default is 2048.
Chris@0 58 */
Chris@0 59 size_t getWindowSize() const { return m_wlen; }
Chris@0 60
Chris@0 61 /**
Chris@0 62 * Get the window type. The default is a Hanning window.
Chris@0 63 */
Chris@0 64 WindowType getWindowType() const { return m_window->getType(); }
Chris@0 65
Chris@0 66 size_t getRatio() const { return m_ratio; }
Chris@0 67 size_t getOutputIncrement() const { return getInputIncrement() * getRatio(); }
Chris@0 68 size_t getProcessingLatency() const;
Chris@0 69
Chris@0 70 protected:
Chris@0 71 void processBlock(float *in, float *out);
Chris@0 72
Chris@0 73 size_t m_ratio;
Chris@0 74 size_t m_n1;
Chris@0 75 size_t m_n2;
Chris@0 76 size_t m_wlen;
Chris@0 77 Window<float> *m_window;
Chris@0 78
Chris@0 79 fftwf_complex *m_time;
Chris@0 80 fftwf_complex *m_freq;
Chris@0 81 float *m_dbuf;
Chris@0 82
Chris@0 83 fftwf_plan m_plan;
Chris@0 84 fftwf_plan m_iplan;
Chris@0 85
Chris@0 86 RingBuffer<float> m_inbuf;
Chris@0 87 RingBuffer<float> m_outbuf;
Chris@0 88 float *m_mashbuf;
Chris@0 89 };
Chris@0 90
Chris@0 91 #endif