mirror of
https://github.com/thestk/stk
synced 2026-01-12 12:31:53 +00:00
103 lines
9.3 KiB
HTML
103 lines
9.3 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>The Synthesis ToolKit in C++ (STK)</TITLE>
|
|
<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
|
|
</HEAD>
|
|
<BODY BGCOLOR="#FFFFFF">
|
|
<CENTER>
|
|
<img src="princeton.gif"> <img src="ccrma.gif"> <img src="mcgill.gif"><P>
|
|
<a class="qindex" href="index.html">Home</a> <a class="qindex" href="information.html">Information</a> <a class="qindex" href="classes.html">Classes</a> <a class="qindex" href="download.html">Download</a> <a class="qindex" href="usage.html">Usage</a> <a class="qindex" href="maillist.html">Mail List</a> <a class="qindex" href="system.html">Requirements</a> <a class="qindex" href="links.html">Links</a> <a class="qindex" href="faq.html">FAQ</a> <a class="qindex" href="tutorial.html">Tutorial</a></CENTER>
|
|
<HR>
|
|
<!-- Generated by Doxygen 1.6.2 -->
|
|
<div class="navpath"><a class="el" href="dir_f14fd23bc74c76f288031ad23b3f3505.html">include</a>
|
|
</div>
|
|
<div class="contents">
|
|
<h1>PitShift.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef STK_PITSHIFT_H</span>
|
|
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define STK_PITSHIFT_H</span>
|
|
<a name="l00003"></a>00003 <span class="preprocessor"></span>
|
|
<a name="l00004"></a>00004 <span class="preprocessor">#include "Effect.h"</span>
|
|
<a name="l00005"></a>00005 <span class="preprocessor">#include "DelayL.h"</span>
|
|
<a name="l00006"></a>00006
|
|
<a name="l00007"></a>00007 <span class="keyword">namespace </span>stk {
|
|
<a name="l00008"></a>00008
|
|
<a name="l00009"></a>00009 <span class="comment">/***************************************************/</span>
|
|
<a name="l00018"></a>00018 <span class="comment">/***************************************************/</span>
|
|
<a name="l00019"></a>00019
|
|
<a name="l00020"></a>00020 <span class="keyword">const</span> <span class="keywordtype">int</span> maxDelay = 5024;
|
|
<a name="l00021"></a>00021
|
|
<a name="l00022"></a><a class="code" href="classstk_1_1PitShift.html">00022</a> <span class="keyword">class </span><a class="code" href="classstk_1_1PitShift.html" title="STK simple pitch shifter effect class.">PitShift</a> : <span class="keyword">public</span> <a class="code" href="classstk_1_1Effect.html" title="STK abstract effects parent class.">Effect</a>
|
|
<a name="l00023"></a>00023 {
|
|
<a name="l00024"></a>00024 <span class="keyword">public</span>:
|
|
<a name="l00026"></a>00026 <a class="code" href="classstk_1_1PitShift.html#a8fdf3ef3b1a94e126a2953c6b8ed8cca" title="Class constructor.">PitShift</a>( <span class="keywordtype">void</span> );
|
|
<a name="l00027"></a>00027
|
|
<a name="l00029"></a>00029 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1PitShift.html#afa1b0ff95ef9a22991525f72d703220e" title="Reset and clear all internal state.">clear</a>( <span class="keywordtype">void</span> );
|
|
<a name="l00030"></a>00030
|
|
<a name="l00032"></a>00032 <span class="keywordtype">void</span> <a class="code" href="classstk_1_1PitShift.html#a1ade8534def67636af6f0d7e50825891" title="Set the pitch shift factor (1.0 produces no shift).">setShift</a>( StkFloat shift );
|
|
<a name="l00033"></a>00033
|
|
<a name="l00035"></a><a class="code" href="classstk_1_1PitShift.html#a782ad7b47c450c1584cebd20570f17e3">00035</a> StkFloat <a class="code" href="classstk_1_1PitShift.html#a782ad7b47c450c1584cebd20570f17e3" title="Return the last computed output value.">lastOut</a>( <span class="keywordtype">void</span> )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> lastFrame_[0]; };
|
|
<a name="l00036"></a>00036
|
|
<a name="l00038"></a>00038 StkFloat <a class="code" href="classstk_1_1PitShift.html#a433fcd3da3e7b08cb8b3392865e93033" title="Input one sample to the effect and return one output.">tick</a>( StkFloat input );
|
|
<a name="l00039"></a>00039
|
|
<a name="l00041"></a>00041
|
|
<a name="l00049"></a>00049 <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& <a class="code" href="classstk_1_1PitShift.html#a433fcd3da3e7b08cb8b3392865e93033" title="Input one sample to the effect and return one output.">tick</a>( <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& frames, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> channel = 0 );
|
|
<a name="l00050"></a>00050
|
|
<a name="l00052"></a>00052
|
|
<a name="l00060"></a>00060 <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& <a class="code" href="classstk_1_1PitShift.html#a433fcd3da3e7b08cb8b3392865e93033" title="Input one sample to the effect and return one output.">tick</a>( <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a>& iFrames, <a class="code" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a> &oFrames, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> iChannel = 0, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> oChannel = 0 );
|
|
<a name="l00061"></a>00061
|
|
<a name="l00062"></a>00062 <span class="keyword">protected</span>:
|
|
<a name="l00063"></a>00063
|
|
<a name="l00064"></a>00064 <a class="code" href="classstk_1_1DelayL.html" title="STK linear interpolating delay line class.">DelayL</a> delayLine_[2];
|
|
<a name="l00065"></a>00065 StkFloat delay_[2];
|
|
<a name="l00066"></a>00066 StkFloat env_[2];
|
|
<a name="l00067"></a>00067 StkFloat rate_;
|
|
<a name="l00068"></a>00068 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> delayLength_;
|
|
<a name="l00069"></a>00069 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> halfLength_;
|
|
<a name="l00070"></a>00070
|
|
<a name="l00071"></a>00071 };
|
|
<a name="l00072"></a>00072
|
|
<a name="l00073"></a><a class="code" href="classstk_1_1PitShift.html#a433fcd3da3e7b08cb8b3392865e93033">00073</a> <span class="keyword">inline</span> StkFloat <a class="code" href="classstk_1_1PitShift.html#a433fcd3da3e7b08cb8b3392865e93033" title="Input one sample to the effect and return one output.">PitShift :: tick</a>( StkFloat input )
|
|
<a name="l00074"></a>00074 {
|
|
<a name="l00075"></a>00075 <span class="comment">// Calculate the two delay length values, keeping them within the</span>
|
|
<a name="l00076"></a>00076 <span class="comment">// range 12 to maxDelay-12.</span>
|
|
<a name="l00077"></a>00077 delay_[0] += rate_;
|
|
<a name="l00078"></a>00078 <span class="keywordflow">while</span> ( delay_[0] > maxDelay-12 ) delay_[0] -= delayLength_;
|
|
<a name="l00079"></a>00079 <span class="keywordflow">while</span> ( delay_[0] < 12 ) delay_[0] += delayLength_;
|
|
<a name="l00080"></a>00080
|
|
<a name="l00081"></a>00081 delay_[1] = delay_[0] + halfLength_;
|
|
<a name="l00082"></a>00082 <span class="keywordflow">while</span> ( delay_[1] > maxDelay-12 ) delay_[1] -= delayLength_;
|
|
<a name="l00083"></a>00083 <span class="keywordflow">while</span> ( delay_[1] < 12 ) delay_[1] += delayLength_;
|
|
<a name="l00084"></a>00084
|
|
<a name="l00085"></a>00085 <span class="comment">// Set the new delay line lengths.</span>
|
|
<a name="l00086"></a>00086 delayLine_[0].<a class="code" href="classstk_1_1DelayL.html#a80dd30628502a7c3b37ff045176eb91f" title="Set the delay-line length.">setDelay</a>( delay_[0] );
|
|
<a name="l00087"></a>00087 delayLine_[1].<a class="code" href="classstk_1_1DelayL.html#a80dd30628502a7c3b37ff045176eb91f" title="Set the delay-line length.">setDelay</a>( delay_[1] );
|
|
<a name="l00088"></a>00088
|
|
<a name="l00089"></a>00089 <span class="comment">// Calculate a triangular envelope.</span>
|
|
<a name="l00090"></a>00090 env_[1] = fabs( ( delay_[0] - halfLength_ + 12 ) * ( 1.0 / (halfLength_ + 12 ) ) );
|
|
<a name="l00091"></a>00091 env_[0] = 1.0 - env_[1];
|
|
<a name="l00092"></a>00092
|
|
<a name="l00093"></a>00093 <span class="comment">// Delay input and apply envelope.</span>
|
|
<a name="l00094"></a>00094 lastFrame_[0] = env_[0] * delayLine_[0].<a class="code" href="classstk_1_1DelayL.html#a1d01bbaf40cc20a0b70241bb8072da7f" title="Input one sample to the filter and return one output.">tick</a>( input );
|
|
<a name="l00095"></a>00095 lastFrame_[0] += env_[1] * delayLine_[1].<a class="code" href="classstk_1_1DelayL.html#a1d01bbaf40cc20a0b70241bb8072da7f" title="Input one sample to the filter and return one output.">tick</a>( input );
|
|
<a name="l00096"></a>00096
|
|
<a name="l00097"></a>00097 <span class="comment">// Compute effect mix and output.</span>
|
|
<a name="l00098"></a>00098 lastFrame_[0] *= effectMix_;
|
|
<a name="l00099"></a>00099 lastFrame_[0] += ( 1.0 - effectMix_ ) * input;
|
|
<a name="l00100"></a>00100
|
|
<a name="l00101"></a>00101 <span class="keywordflow">return</span> lastFrame_[0];
|
|
<a name="l00102"></a>00102 }
|
|
<a name="l00103"></a>00103
|
|
<a name="l00104"></a>00104 } <span class="comment">// stk namespace</span>
|
|
<a name="l00105"></a>00105
|
|
<a name="l00106"></a>00106 <span class="preprocessor">#endif</span>
|
|
<a name="l00107"></a>00107 <span class="preprocessor"></span>
|
|
</pre></div></div>
|
|
<HR>
|
|
|
|
<table>
|
|
<tr><td><A HREF="http://ccrma.stanford.edu/software/stk/"><I>The Synthesis ToolKit in C++ (STK)</I></A></td></tr>
|
|
<tr><td>©1995-2011 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
|
|
</table>
|
|
|
|
</BODY>
|
|
</HTML>
|