[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Sc-devel] SF.net SVN: supercollider: [6655] trunk



Revision: 6655
          http://svn.sourceforge.net/supercollider/?rev=6655&view=rev
Author:   joshpar
Date:     2007-11-19 20:50:34 -0800 (Mon, 19 Nov 2007)

Log Message:
-----------
add FFTTrigger

Modified Paths:
--------------
    trunk/Source/plugins/FFT_UGens.cpp
    trunk/build/SCClassLibrary/Common/Audio/FFT.sc

Added Paths:
-----------
    trunk/build/Help/UGens/FFT/FFTTrigger.html

Modified: trunk/Source/plugins/FFT_UGens.cpp
===================================================================
--- trunk/Source/plugins/FFT_UGens.cpp	2007-11-19 23:13:14 UTC (rev 6654)
+++ trunk/Source/plugins/FFT_UGens.cpp	2007-11-20 04:50:34 UTC (rev 6655)
@@ -111,6 +111,11 @@
 	float m_scalefactor; // Different FFT algorithms introduce different scaling through ->FFT->IFFT->
 };
 
+struct FFTTrigger : public FFTBase
+{
+	int m_numPeriods, m_periodsRemain, m_polar;
+};
+
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 extern "C"
@@ -123,7 +128,9 @@
 	void IFFT_Ctor(IFFT* unit);
 	void IFFT_next(IFFT *unit, int inNumSamples);
 	void IFFT_Dtor(IFFT* unit);
-
+	
+	void FFTTrigger_Ctor(FFTTrigger* unit);
+	void FFTTrigger_next(FFTTrigger* unit, int inNumSamples);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
@@ -577,6 +584,43 @@
 #endif
 }
 
+void FFTTrigger_Ctor(FFTTrigger *unit)
+{
+	World *world = unit->mWorld;
+
+	uint32 bufnum = (uint32)IN0(0);
+	//Print("FFTBase_Ctor: bufnum is %i\n", bufnum);
+	if (bufnum >= world->mNumSndBufs) bufnum = 0;
+	SndBuf *buf = world->mSndBufs + bufnum; 
+	
+	unit->m_fftsndbuf = buf;
+	unit->m_fftbufnum = bufnum;
+	unit->m_bufsize = buf->samples;
+
+	int numSamples = unit->mWorld->mFullRate.mBufLength;
+	float dataHopSize = IN0(1);
+	int initPolar = unit->m_polar = (int)IN0(2);
+	unit->m_numPeriods = unit->m_periodsRemain = (int)(((float)unit->m_bufsize * dataHopSize) / numSamples) - 1; 
+		
+	buf->coord = (IN0(2) == 1.f) ? coord_Polar : coord_Complex;
+	    
+	OUT0(0) = IN0(0);
+	SETCALC(FFTTrigger_next);
+}
+
+void FFTTrigger_next(FFTTrigger *unit, int inNumSamples)
+{	
+	if (unit->m_periodsRemain > 0) {
+		ZOUT0(0) = -1.f;
+		unit->m_periodsRemain--;
+	} else {
+		ZOUT0(0) = unit->m_fftbufnum;
+		unit->m_pos = 0;
+		unit->m_periodsRemain = unit->m_numPeriods;		
+	}
+		
+}
+
 void init_SCComplex(InterfaceTable *inTable);
 
 void initFFT(InterfaceTable *inTable)
@@ -587,5 +631,6 @@
 
 	DefineDtorUnit(FFT);
 	DefineDtorUnit(IFFT);
+	DefineSimpleUnit(FFTTrigger);
 }
 

Added: trunk/build/Help/UGens/FFT/FFTTrigger.html
===================================================================
--- trunk/build/Help/UGens/FFT/FFTTrigger.html	                        (rev 0)
+++ trunk/build/Help/UGens/FFT/FFTTrigger.html	2007-11-20 04:50:34 UTC (rev 6655)
@@ -0,0 +1,56 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd";>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<title></title>
+<meta name="Generator" content="Cocoa HTML Writer">
+<meta name="CocoaVersion" content="949">
+<style type="text/css">
+p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
+p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
+p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco}
+p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #a91616}
+span.s1 {font: 15.0px Helvetica}
+span.s2 {color: #0014bc}
+span.s3 {color: #000000}
+span.Apple-tab-span {white-space:pre}
+</style>
+</head>
+<body>
+<p class="p1"><span class="s1"><b>FFTTrigger<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></b></span><b>Outputs the necessary signal for FFT chains, without doing an FFT on a signal</b></p>
+<p class="p2"><br></p>
+<p class="p1"><b>FFTrigger(buffer, hop, polar)</b></p>
+<p class="p2"><br></p>
+<p class="p1"><span class="Apple-tab-span">	</span>buffer - a buffer to condition for FFT use</p>
+<p class="p1"><span class="Apple-tab-span">	</span>hop - the hop size for timing triggers (defaults to 0.5)</p>
+<p class="p1"><span class="Apple-tab-span">	</span>polar - a flag. If 0.0, the buffer will be prepared for complex data, if &gt; 0.0, polar data is set up.</p>
+<p class="p2"><span class="Apple-tab-span">	</span></p>
+<p class="p3">(</p>
+<p class="p3">s.boot.doWhenBooted{</p>
+<p class="p3"><span class="Apple-tab-span">	</span>b = <span class="s2">Buffer</span>.alloc(s, 512);</p>
+<p class="p3">};</p>
+<p class="p3">)</p>
+<p class="p4">// Reminder: This isn't the intended typical usage! It's OK to do this though.</p>
+<p class="p3">(</p>
+<p class="p3">x = {</p>
+<p class="p3"><span class="Apple-tab-span">	</span><span class="s2">var</span> mags, phases, chain, sig;</p>
+<p class="p4"><span class="s3"><span class="Apple-tab-span">	</span></span>// Create simple undulating magnitudes</p>
+<p class="p3"><span class="Apple-tab-span">	</span>mags = {<span class="s2">FSinOsc</span>.kr(<span class="s2">ExpRand</span>(0.1, 1)).range(0, 1)}.dup(100);</p>
+<p class="p4"><span class="s3"><span class="Apple-tab-span">	</span></span>// Then give them a "rolloff" to make the sound less unpleasant</p>
+<p class="p3"><span class="Apple-tab-span">	</span>mags = mags<span class="Apple-converted-space">  </span>* ((1, 0.99 .. 0.01).squared);</p>
+<p class="p4"><span class="s3"><span class="Apple-tab-span">	</span></span>// Let's turn the bins on and off at different rates, I'm *sure* that'll sound interesting</p>
+<p class="p3"><span class="Apple-tab-span">	</span>mags = mags * {<span class="s2">LFPulse</span>.kr(2 ** <span class="s2">IRand</span>(-3, 5)).range(0, 1)}.dup(100);</p>
+<p class="p4"><span class="s3"><span class="Apple-tab-span">	</span></span>// Let's ignore phase for now</p>
+<p class="p3"><span class="Apple-tab-span">	</span>phases = 0.dup(100);</p>
+<p class="p3"><span class="Apple-tab-span">	</span>chain = <span class="s2">FFTTrigger</span>(b.bufnum, 0.5);</p>
+<p class="p4"><span class="s3"><span class="Apple-tab-span">	</span></span>// Now we can do the packing</p>
+<p class="p3"><span class="Apple-tab-span">	</span>chain = <span class="s2">PackFFT</span>(chain, 512, [mags, phases].flop.flatten, 0, 99, 1);</p>
+<p class="p3"><span class="Apple-tab-span">	</span>sig = <span class="s2">IFFT</span>(chain);</p>
+<p class="p3"><span class="Apple-tab-span">	</span><span class="s2">Out</span>.ar(0, sig.dup);</p>
+<p class="p3">}.play(s);</p>
+<p class="p3">)</p>
+<p class="p3">x.free;</p>
+<p class="p3">b.free;</p>
+</body>
+</html>

Modified: trunk/build/SCClassLibrary/Common/Audio/FFT.sc
===================================================================
--- trunk/build/SCClassLibrary/Common/Audio/FFT.sc	2007-11-19 23:13:14 UTC (rev 6654)
+++ trunk/build/SCClassLibrary/Common/Audio/FFT.sc	2007-11-20 04:50:34 UTC (rev 6655)
@@ -145,9 +145,14 @@
 	}
 }
 
+FFTTrigger : PV_ChainUGen 
+{
+	*new { | buffer, hop = 0.5, polar = 0.0|
+		^this.multiNew('control', buffer, hop, polar)
+	}
+}	
 
 
-
 ////////////////////////////////////////////////////
 /*
 PV_OscBank : PV_ChainUGen 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.