Mercurial > hg > sonic-visualiser
comparison audioio/PhaseVocoderTimeStretcher.cpp @ 22:80126455d169
* add samplerate parameter to timestretcher (not properly used yet),
and update credits
author | Chris Cannam |
---|---|
date | Fri, 15 Sep 2006 13:35:37 +0000 |
parents | 7da85e0b85e9 |
children | e74f508db18c |
comparison
equal
deleted
inserted
replaced
21:7da85e0b85e9 | 22:80126455d169 |
---|---|
18 #include <iostream> | 18 #include <iostream> |
19 #include <cassert> | 19 #include <cassert> |
20 | 20 |
21 //#define DEBUG_PHASE_VOCODER_TIME_STRETCHER 1 | 21 //#define DEBUG_PHASE_VOCODER_TIME_STRETCHER 1 |
22 | 22 |
23 PhaseVocoderTimeStretcher::PhaseVocoderTimeStretcher(size_t channels, | 23 PhaseVocoderTimeStretcher::PhaseVocoderTimeStretcher(size_t sampleRate, |
24 size_t channels, | |
24 float ratio, | 25 float ratio, |
25 bool sharpen, | 26 bool sharpen, |
26 size_t maxProcessInputBlockSize) : | 27 size_t maxProcessInputBlockSize) : |
28 m_sampleRate(sampleRate), | |
27 m_channels(channels), | 29 m_channels(channels), |
28 m_ratio(ratio), | 30 m_ratio(ratio), |
29 m_sharpen(sharpen), | 31 m_sharpen(sharpen), |
30 m_totalCount(0), | 32 m_totalCount(0), |
31 m_transientCount(0), | 33 m_transientCount(0), |
33 { | 35 { |
34 m_wlen = 1024; | 36 m_wlen = 1024; |
35 | 37 |
36 //!!! In transient sharpening mode, we need to pick the window | 38 //!!! In transient sharpening mode, we need to pick the window |
37 //length so as to be more or less fixed in audio duration (i.e. we | 39 //length so as to be more or less fixed in audio duration (i.e. we |
38 //need to know the sample rate) | 40 //need to exploit the sample rate) |
41 | |
42 //!!! have to work out the relationship between wlen and transient | |
43 //threshold | |
39 | 44 |
40 if (ratio < 1) { | 45 if (ratio < 1) { |
41 if (ratio < 0.4) { | 46 if (ratio < 0.4) { |
42 m_n1 = 1024; | 47 m_n1 = 1024; |
43 m_wlen = 2048; | 48 m_wlen = 2048; |
63 if (m_sharpen) { | 68 if (m_sharpen) { |
64 if (m_wlen < 2048) m_wlen = 2048; | 69 if (m_wlen < 2048) m_wlen = 2048; |
65 } | 70 } |
66 m_n1 = m_n2 / ratio; | 71 m_n1 = m_n2 / ratio; |
67 } | 72 } |
73 | |
74 m_transientThreshold = m_wlen / 4.5; | |
68 | 75 |
69 m_analysisWindow = new Window<float>(HanningWindow, m_wlen); | 76 m_analysisWindow = new Window<float>(HanningWindow, m_wlen); |
70 m_synthesisWindow = new Window<float>(HanningWindow, m_wlen); | 77 m_synthesisWindow = new Window<float>(HanningWindow, m_wlen); |
71 | 78 |
72 m_prevPhase = new float *[m_channels]; | 79 m_prevPhase = new float *[m_channels]; |
415 m_prevTransientMag[i] = sqrmag; | 422 m_prevTransientMag[i] = sqrmag; |
416 } | 423 } |
417 | 424 |
418 bool isTransient = false; | 425 bool isTransient = false; |
419 | 426 |
420 if (count > m_wlen / 4.5 && //!!! | 427 if (count > m_transientThreshold && |
421 count > m_prevTransientScore * 1.2) { | 428 count > m_prevTransientScore * 1.2) { |
422 isTransient = true; | 429 isTransient = true; |
423 std::cerr << "isTransient (count = " << count << ", prev = " << m_prevTransientScore << ")" << std::endl; | 430 std::cerr << "isTransient (count = " << count << ", prev = " << m_prevTransientScore << ")" << std::endl; |
424 } | 431 } |
425 | 432 |