1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
<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="namespacestk.html">stk</a>::<a class="el" href="classstk_1_1BlitSquare.html">BlitSquare</a>
</div>
<div class="contents">
<h1>stk::BlitSquare Class Reference</h1><!-- doxytag: class="stk::BlitSquare" --><!-- doxytag: inherits="stk::Generator" -->
<p>STK band-limited square wave class.
<a href="#_details">More...</a></p>
<p><code>#include <<a class="el" href="BlitSquare_8h_source.html">BlitSquare.h</a>></code></p>
<div class="dynheader">
Inheritance diagram for stk::BlitSquare:</div>
<div class="dynsection">
<div class="center">
<img src="classstk_1_1BlitSquare.png" usemap="#stk::BlitSquare_map" alt=""/>
<map id="stk::BlitSquare_map" name="stk::BlitSquare_map">
<area href="classstk_1_1Generator.html" alt="stk::Generator" shape="rect" coords="0,56,90,80"/>
<area href="classstk_1_1Stk.html" alt="stk::Stk" shape="rect" coords="0,0,90,24"/>
</map>
</div>
</div>
<p><a href="classstk_1_1BlitSquare-members.html">List of all members.</a></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2"><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a2cb3aee415a6ee75fa85b01e4e85d70b"></a><!-- doxytag: member="stk::BlitSquare::BlitSquare" ref="a2cb3aee415a6ee75fa85b01e4e85d70b" args="(StkFloat frequency=220.0)" -->
</td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#a2cb3aee415a6ee75fa85b01e4e85d70b">BlitSquare</a> (StkFloat frequency=220.0)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Default constructor that initializes BLIT frequency to 220 Hz. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a4bc6e424ca1631f353f55846084634ef"></a><!-- doxytag: member="stk::BlitSquare::~BlitSquare" ref="a4bc6e424ca1631f353f55846084634ef" args="()" -->
</td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#a4bc6e424ca1631f353f55846084634ef">~BlitSquare</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Class destructor. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8f6dbe07d7f64b24cc9a41f6208dd6c4"></a><!-- doxytag: member="stk::BlitSquare::reset" ref="a8f6dbe07d7f64b24cc9a41f6208dd6c4" args="()" -->
void </td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#a8f6dbe07d7f64b24cc9a41f6208dd6c4">reset</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Resets the oscillator state and phase to 0. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#aeface58980a3ec865131f3cad59bbbef">setPhase</a> (StkFloat phase)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Set the phase of the signal. <a href="#aeface58980a3ec865131f3cad59bbbef"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">StkFloat </td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#abbda8cb84bcd36fc6d96130e9832a6af">getPhase</a> () const </td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Get the current phase of the signal. <a href="#abbda8cb84bcd36fc6d96130e9832a6af"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8d0d8e0a12987ebccc56c09c7e7dbd6a"></a><!-- doxytag: member="stk::BlitSquare::setFrequency" ref="a8d0d8e0a12987ebccc56c09c7e7dbd6a" args="(StkFloat frequency)" -->
void </td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#a8d0d8e0a12987ebccc56c09c7e7dbd6a">setFrequency</a> (StkFloat frequency)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Set the impulse train rate in terms of a frequency in Hz. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#a94521b4224d0873f5e783c721c123b21">setHarmonics</a> (unsigned int nHarmonics=0)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Set the number of harmonics generated in the signal. <a href="#a94521b4224d0873f5e783c721c123b21"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a77972e4e1c53600bf80cf692601ccae1"></a><!-- doxytag: member="stk::BlitSquare::lastOut" ref="a77972e4e1c53600bf80cf692601ccae1" args="(void) const " -->
StkFloat </td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#a77972e4e1c53600bf80cf692601ccae1">lastOut</a> (void) const </td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Return the last computed output value. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a04366d55cecb4c8a726ea0519683d817"></a><!-- doxytag: member="stk::BlitSquare::tick" ref="a04366d55cecb4c8a726ea0519683d817" args="(void)" -->
StkFloat </td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#a04366d55cecb4c8a726ea0519683d817">tick</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Compute and return one output sample. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classstk_1_1StkFrames.html">StkFrames</a> & </td><td class="memItemRight" valign="bottom"><a class="el" href="classstk_1_1BlitSquare.html#a7df894d40b3d6effbb2a09819356258d">tick</a> (<a class="el" href="classstk_1_1StkFrames.html">StkFrames</a> &frames, unsigned int channel=0)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Fill a channel of the <a class="el" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a> object with computed outputs. <a href="#a7df894d40b3d6effbb2a09819356258d"></a><br/></td></tr>
</table>
<hr/><a name="_details"></a><h2>Detailed Description</h2>
<p>STK band-limited square wave class. </p>
<p>This class generates a band-limited square wave signal. It is derived in part from the approach reported by Stilson and Smith in "Alias-Free Digital Synthesis of Classic Analog Waveforms", 1996. The algorithm implemented in this class uses a SincM function with an even M value to achieve a bipolar bandlimited impulse train. This signal is then integrated to achieve a square waveform. The integration process has an associated DC offset so a DC blocking filter is applied at the output.</p>
<p>The user can specify both the fundamental frequency of the waveform and the number of harmonics contained in the resulting signal.</p>
<p>If nHarmonics is 0, then the signal will contain all harmonics up to half the sample rate. Note, however, that this setting may produce aliasing in the signal when the frequency is changing (no automatic modification of the number of harmonics is performed by the <a class="el" href="classstk_1_1BlitSquare.html#a8d0d8e0a12987ebccc56c09c7e7dbd6a" title="Set the impulse train rate in terms of a frequency in Hz.">setFrequency()</a> function). Also note that the harmonics of a square wave fall at odd integer multiples of the fundamental, so aliasing will happen with a lower fundamental than with the other <a class="el" href="classstk_1_1Blit.html" title="STK band-limited impulse train class.">Blit</a> waveforms. This class is not guaranteed to be well behaved in the presence of significant aliasing.</p>
<p>Based on initial code of Robin Davies, 2005. Modified algorithm code by Gary Scavone, 2005 - 2006. </p>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="aeface58980a3ec865131f3cad59bbbef"></a><!-- doxytag: member="stk::BlitSquare::setPhase" ref="aeface58980a3ec865131f3cad59bbbef" args="(StkFloat phase)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void stk::BlitSquare::setPhase </td>
<td>(</td>
<td class="paramtype">StkFloat </td>
<td class="paramname"> <em>phase</em></td>
<td> ) </td>
<td><code> [inline]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Set the phase of the signal. </p>
<p>Set the phase of the signal, in the range 0 to 1. </p>
<p><div class="fragment"><pre class="fragment"><a name="l00058"></a>00058 { phase_ = PI * phase; };
</pre></div></p>
</div>
</div>
<a class="anchor" id="abbda8cb84bcd36fc6d96130e9832a6af"></a><!-- doxytag: member="stk::BlitSquare::getPhase" ref="abbda8cb84bcd36fc6d96130e9832a6af" args="() const " -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">StkFloat stk::BlitSquare::getPhase </td>
<td>(</td>
<td class="paramname"></td>
<td> ) </td>
<td> const<code> [inline]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Get the current phase of the signal. </p>
<p>Get the phase of the signal, in the range [0 to 1.0). </p>
<p><div class="fragment"><pre class="fragment"><a name="l00064"></a>00064 { <span class="keywordflow">return</span> phase_ / PI; };
</pre></div></p>
</div>
</div>
<a class="anchor" id="a94521b4224d0873f5e783c721c123b21"></a><!-- doxytag: member="stk::BlitSquare::setHarmonics" ref="a94521b4224d0873f5e783c721c123b21" args="(unsigned int nHarmonics=0)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void stk::BlitSquare::setHarmonics </td>
<td>(</td>
<td class="paramtype">unsigned int </td>
<td class="paramname"> <em>nHarmonics</em> = <code>0</code></td>
<td> ) </td>
<td></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Set the number of harmonics generated in the signal. </p>
<p>This function sets the number of harmonics contained in the resulting signal. It is equivalent to (2 * M) + 1 in the BLIT algorithm. The default value of 0 sets the algorithm for maximum harmonic content (harmonics up to half the sample rate). This parameter is not checked against the current sample rate and fundamental frequency. Thus, aliasing can result if one or more harmonics for a given fundamental frequency exceeds fs / 2. This behavior was chosen over the potentially more problematic solution of automatically modifying the M parameter, which can produce audible clicks in the signal. </p>
</div>
</div>
<a class="anchor" id="a7df894d40b3d6effbb2a09819356258d"></a><!-- doxytag: member="stk::BlitSquare::tick" ref="a7df894d40b3d6effbb2a09819356258d" args="(StkFrames &frames, unsigned int channel=0)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classstk_1_1StkFrames.html">StkFrames</a> & stk::BlitSquare::tick </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classstk_1_1StkFrames.html">StkFrames</a> & </td>
<td class="paramname"> <em>frames</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">unsigned int </td>
<td class="paramname"> <em>channel</em> = <code>0</code></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td><code> [inline, virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>Fill a channel of the <a class="el" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a> object with computed outputs. </p>
<p>The <code>channel</code> argument must be less than the number of channels in the <a class="el" href="classstk_1_1StkFrames.html" title="An STK class to handle vectorized audio data.">StkFrames</a> argument (the first channel is specified by 0). However, range checking is only performed if _STK_DEBUG_ is defined during compilation, in which case an out-of-range value will trigger an <a class="el" href="classstk_1_1StkError.html" title="STK error handling class.">StkError</a> exception. </p>
<p>Implements <a class="el" href="classstk_1_1Generator.html#a86bb0421223cf27e25704d5f27b97425">stk::Generator</a>.</p>
<p><div class="fragment"><pre class="fragment"><a name="l00152"></a>00152 {
<a name="l00153"></a>00153 <span class="preprocessor">#if defined(_STK_DEBUG_)</span>
<a name="l00154"></a>00154 <span class="preprocessor"></span> <span class="keywordflow">if</span> ( channel >= frames.channels() ) {
<a name="l00155"></a>00155 oStream_ << <span class="stringliteral">"BlitSquare::tick(): channel and StkFrames arguments are incompatible!"</span>;
<a name="l00156"></a>00156 <a class="code" href="classstk_1_1Stk.html#a48ac73a0d8ca28445ba1a054e1f061ff" title="Static function for error reporting and handling using c-strings.">handleError</a>( StkError::FUNCTION_ARGUMENT );
<a name="l00157"></a>00157 }
<a name="l00158"></a>00158 <span class="preprocessor">#endif</span>
<a name="l00159"></a>00159 <span class="preprocessor"></span>
<a name="l00160"></a>00160 StkFloat *samples = &frames[channel];
<a name="l00161"></a>00161 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> hop = frames.channels();
<a name="l00162"></a>00162 <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i<frames.frames(); i++, samples += hop )
<a name="l00163"></a>00163 *samples = <a class="code" href="classstk_1_1BlitSquare.html#a04366d55cecb4c8a726ea0519683d817" title="Compute and return one output sample.">BlitSquare::tick</a>();
<a name="l00164"></a>00164
<a name="l00165"></a>00165 <span class="keywordflow">return</span> frames;
<a name="l00166"></a>00166 }
</pre></div></p>
</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="BlitSquare_8h_source.html">BlitSquare.h</a></li>
</ul>
</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-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
</table>
</BODY>
</HTML>
|