annotate audioio/IntegerTimeStretcher.h @ 40:a996c0ef6177

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