annotate audioio/IntegerTimeStretcher.h @ 38:54287e5e7451 sv1-v0.9rc1 sv1-v0.9rc2

* Make vertical scale alignment modes work in note layer as well as time-value layer, and several significant fixes to it * Make it possible to draw notes properly on the note layer * Show units (and frequencies etc in note layer's case) in the time-value and note layer description boxes * Minor fix to item edit dialog layout * Some minor menu rearrangement * Comment out a lot of debug output * Add SV website and reference URLs to Help menu, and add code to (attempt to) open them in the user's preferred browser
author Chris Cannam
date Fri, 12 May 2006 14:40:43 +0000
parents 2eb25a26390f
children 4ed2448582cc
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@27 44 void process(double *input, double *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@27 71 void processBlock(double *in, double *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@27 77 Window<double> *m_window;
Chris@27 78
Chris@27 79 fftw_complex *m_time;
Chris@27 80 fftw_complex *m_freq;
Chris@27 81 double *m_dbuf;
Chris@27 82
Chris@27 83 fftw_plan m_plan;
Chris@27 84 fftw_plan m_iplan;
Chris@27 85
Chris@27 86 RingBuffer<double> m_inbuf;
Chris@27 87 RingBuffer<double> m_outbuf;
Chris@27 88 double *m_mashbuf;
Chris@27 89 };
Chris@27 90
Chris@27 91 #endif