2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * Created by Alberto de Campo, Sekhar Ramacrishnan, Julian Rohrhuber on Sun May 30 2004.
25 * Copyright (c) 2004 HfbK. All rights reserved.
30 #include "SC_PlugIn.h"
32 static InterfaceTable
*ft
;
34 struct LFDNoise0
: public Unit
39 struct LFDNoise1
: public Unit
47 struct LFDNoise3
: public Unit
50 float mLevelA
, mLevelB
, mLevelC
, mLevelD
;
53 struct LFDClipNoise
: public Unit
59 //////////////////////////////////////////////////////////////////////////////////////////////////
65 void LFDNoise0_next(LFDNoise0
*unit
, int inNumSamples
);
66 void LFDNoise0_next_k(LFDNoise0
*unit
, int inNumSamples
);
67 void LFDNoise0_Ctor(LFDNoise0
*unit
);
69 void LFDNoise1_next(LFDNoise1
*unit
, int inNumSamples
);
70 void LFDNoise1_next_k(LFDNoise1
*unit
, int inNumSamples
);
71 void LFDNoise1_Ctor(LFDNoise1
*unit
);
74 void LFDNoise3_next(LFDNoise3
*unit
, int inNumSamples
);
75 void LFDNoise3_next_k(LFDNoise3
*unit
, int inNumSamples
);
76 void LFDNoise3_Ctor(LFDNoise3
*unit
);
78 void LFDClipNoise_next(LFDClipNoise
*unit
, int inNumSamples
);
79 void LFDClipNoise_Ctor(LFDClipNoise
*unit
);
82 //////////////////////////////////////////////////////////////////////////////////////////////////
84 void LFDNoise0_next(LFDNoise0
*unit
, int inNumSamples
)
88 float level
= unit
->mLevel
;
89 float phase
= unit
->mPhase
;
90 float smpdur
= SAMPLEDUR
;
94 phase
-= ZXP(freq
) * smpdur
;
96 phase
= sc_wrap(phase
, 0.f
, 1.f
);
97 level
= frand2(s1
,s2
,s3
);
101 unit
->mLevel
= level
;
102 unit
->mPhase
= phase
;
107 void LFDNoise0_next_k(LFDNoise0
*unit
, int inNumSamples
)
109 float *out
= ZOUT(0);
110 float freq
= ZIN0(0);
111 float level
= unit
->mLevel
;
112 float phase
= unit
->mPhase
;
113 float smpdur
= SAMPLEDUR
;
114 float dphase
= smpdur
* freq
;
121 phase
= sc_wrap(phase
, 0.f
, 1.f
);
122 level
= frand2(s1
,s2
,s3
);
126 unit
->mLevel
= level
;
127 unit
->mPhase
= phase
;
132 void LFDNoise0_Ctor(LFDNoise0
* unit
)
134 if (INRATE(0) == calc_FullRate
) {
135 SETCALC(LFDNoise0_next
);
137 SETCALC(LFDNoise0_next_k
);
143 LFDNoise0_next(unit
, 1);
146 //////////////////////////////////////////////////////////////////////////////////////////////////
148 void LFDNoise1_next(LFDNoise1
*unit
, int inNumSamples
)
150 float *out
= ZOUT(0);
151 float *freq
= ZIN(0);
152 float prevLevel
= unit
->mPrevLevel
;
153 float nextLevel
= unit
->mNextLevel
;
154 float phase
= unit
->mPhase
;
155 float smpdur
= SAMPLEDUR
;
160 phase
-= ZXP(freq
) * smpdur
;
162 phase
= sc_wrap(phase
, 0.f
, 1.f
);
163 prevLevel
= nextLevel
;
164 nextLevel
= frand2(s1
,s2
,s3
);
166 ZXP(out
) = nextLevel
+ ( phase
* (prevLevel
- nextLevel
) );
168 unit
->mPrevLevel
= prevLevel
;
169 unit
->mNextLevel
= nextLevel
;
170 unit
->mPhase
= phase
;
174 void LFDNoise1_next_k(LFDNoise1
*unit
, int inNumSamples
)
176 float *out
= ZOUT(0);
177 float freq
= ZIN0(0);
178 float prevLevel
= unit
->mPrevLevel
;
179 float nextLevel
= unit
->mNextLevel
;
180 float phase
= unit
->mPhase
;
181 float smpdur
= SAMPLEDUR
;
182 float dphase
= freq
* smpdur
;
189 phase
= sc_wrap(phase
, 0.f
, 1.f
);
190 prevLevel
= nextLevel
;
191 nextLevel
= frand2(s1
,s2
,s3
);
193 ZXP(out
)= nextLevel
+ ( phase
* (prevLevel
- nextLevel
) );
195 unit
->mPrevLevel
= prevLevel
;
196 unit
->mNextLevel
= nextLevel
;
197 unit
->mPhase
= phase
;
201 void LFDNoise1_Ctor(LFDNoise1
* unit
)
203 if (INRATE(0) == calc_FullRate
) {
204 SETCALC(LFDNoise1_next
);
206 SETCALC(LFDNoise1_next_k
);
210 unit
->mPrevLevel
= 0.f
;
211 unit
->mNextLevel
= unit
->mParent
->mRGen
->frand2();
213 LFDNoise1_next(unit
, 1);
216 ////////////////////////////////////////////////////////////////////////////////////////////////////////
218 void LFDNoise3_next(LFDNoise3
*unit
, int inNumSamples
)
220 float *out
= ZOUT(0);
221 float *freq
= ZIN(0);
222 float a
= unit
->mLevelA
;
223 float b
= unit
->mLevelB
;
224 float c
= unit
->mLevelC
;
225 float d
= unit
->mLevelD
;
226 float phase
= unit
->mPhase
;
227 float smpdur
= SAMPLEDUR
;
232 phase
-= ZXP(freq
) * smpdur
;
234 phase
= sc_wrap(phase
, 0.f
, 1.f
);
238 d
= frand2(s1
,s2
,s3
) * 0.8f
; // limits max interpol. overshoot to 1.
240 ZXP(out
) = cubicinterp(1.f
- phase
, a
, b
, c
, d
);
246 unit
->mPhase
= phase
;
250 void LFDNoise3_next_k(LFDNoise3
*unit
, int inNumSamples
)
252 float *out
= ZOUT(0);
253 float freq
= ZIN0(0);
254 float a
= unit
->mLevelA
;
255 float b
= unit
->mLevelB
;
256 float c
= unit
->mLevelC
;
257 float d
= unit
->mLevelD
;
258 float phase
= unit
->mPhase
;
259 float dphase
= freq
* SAMPLEDUR
;
266 phase
= sc_wrap(phase
, 0.f
, 1.f
);
270 d
= frand2(s1
,s2
,s3
) * 0.8f
; // limits max interpol. overshoot to 1.
272 ZXP(out
) = cubicinterp(1.f
- phase
, a
, b
, c
, d
);
278 unit
->mPhase
= phase
;
282 void LFDNoise3_Ctor(LFDNoise3
* unit
)
284 if (INRATE(0) == calc_FullRate
) {
285 SETCALC(LFDNoise3_next
);
287 SETCALC(LFDNoise3_next_k
);
292 unit
->mLevelA
= frand2(s1
, s2
, s3
) * 0.8f
; // limits max interpol. overshoot to 1.
293 unit
->mLevelB
= frand2(s1
, s2
, s3
) * 0.8f
;
294 unit
->mLevelC
= frand2(s1
, s2
, s3
) * 0.8f
;
295 unit
->mLevelD
= frand2(s1
, s2
, s3
) * 0.8f
;
298 LFDNoise3_next(unit
, 1);
301 ////////////////////////////////////////////////////////////////////////////////////////////////////////
302 void LFDClipNoise_next(LFDClipNoise
*unit
, int inNumSamples
)
304 float *out
= ZOUT(0);
305 float *freq
= ZIN(0);
306 float level
= unit
->mLevel
;
307 float phase
= unit
->mPhase
;
308 float smpdur
= SAMPLEDUR
;
312 phase
-= ZXP(freq
) * smpdur
;
314 phase
= sc_wrap(phase
, 0.f
, 1.f
);
315 level
= fcoin(s1
,s2
,s3
);
320 unit
->mLevel
= level
;
321 unit
->mPhase
= phase
;
326 void LFDClipNoise_next_k(LFDClipNoise
*unit
, int inNumSamples
)
328 float *out
= ZOUT(0);
329 float freq
= ZIN0(0);
330 float level
= unit
->mLevel
;
331 float phase
= unit
->mPhase
;
332 float smpdur
= SAMPLEDUR
;
333 float dphase
= smpdur
* freq
;
340 phase
= sc_wrap(phase
, 0.f
, 1.f
);
341 level
= fcoin(s1
,s2
,s3
);
345 unit
->mLevel
= level
;
346 unit
->mPhase
= phase
;
351 void LFDClipNoise_Ctor(LFDClipNoise
* unit
)
353 if (INRATE(0) == calc_FullRate
) {
354 SETCALC(LFDClipNoise_next
);
356 SETCALC(LFDClipNoise_next_k
);
362 LFDClipNoise_next(unit
, 1);
369 ////////////////////////////////////////////////////////////////////////////////////////////////////////
376 DefineSimpleUnit(LFDNoise0
);
377 DefineSimpleUnit(LFDNoise1
);
378 DefineSimpleUnit(LFDNoise3
);
379 DefineSimpleUnit(LFDClipNoise
);
383 ////////////////////////////////////////////////////////////////////////////////////////////////////////