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

Re: [Sc-devel] Amplitude.kr problem



A while ago Julian reworked the Amplitude UGen slightly to allow the
coefficients to be modulated. Julian, you left some old calc-func code
in there, deactivated using some "#if" macros. Is it OK to remove the
old code? Would make it easier to work on fixing the current code...

I don't know which of the two are to be the better one. Well the first is being used, so maybe it is supposed to be the one.


#if 1

void Amplitude_next(Amplitude* unit, int inNumSamples)
{
	float *out = ZOUT(0);
	float *in = ZIN(0);

	float relaxcoef = unit->m_relaxcoef;
	float clampcoef = unit->m_clampcoef;
	float previn = unit->m_previn;

	float val;
	LOOP(inNumSamples,
		val = fabs(ZXP(in));
		if (val < previn) {
			val = val + (previn - val) * relaxcoef;
		} else {
			val = val + (previn - val) * clampcoef;
		}
		ZXP(out) = previn = val;
	);

	unit->m_previn = previn;
}

#else

void Amplitude_next(Amplitude* unit, int inNumSamples)
{
	float *out = ZOUT(0);
	float *in = ZIN(0);

	float maxval = 0.f;
	LOOP(inNumSamples,
		float val = fabs(ZXP(in));
		if (val > maxval) maxval = val;
	);

	float previn = unit->m_previn;
	float coef = maxval < previn ? unit->m_relaxcoef : unit->m_clampcoef ;

LOOP(inNumSamples, ZXP(out) = previn = maxval + (previn - maxval) * coef; );

	unit->m_previn = previn;
}

#endif


Dan


2007/12/13, Josh Parmenter <josh@xxxxxxxxxxxxxxxxx>:
 I think option 1 makes sense. Pitch.kr can take an audio input, so it
 makes sense (to me at least) that Amplitude should be able to also.

 Josh

 On Dec 13, 2007, at 1:50 PM, Dan Stowell wrote:

 > Hi all,
 >
 > Applying Amplitude.kr to an audio-rate signal is allowed, in fact all
 > the examples in the helpfile do this. However, I noticed that the UGen
 > doesn't really handle this case "correctly" - if run at control-rate
 > it simply expects its input to be control rate; the end result on
 > audio-rate input is a dodgy downsampling which can lead to incorrect
 > results.
 >
 > For example, these two should really give similar results but they
 > don't (give them a few seconds to converge):
 >
 > x = {(Amplitude.kr(Impulse.ar(44100/64, 0.0),1,1)).poll}.play // 1
 > x = {(Amplitude.kr(Impulse.ar(44100/64, 0.02),1,1)).poll}.play // 0
 >
 > Same goes for these:
 >
 > x = {(Amplitude.kr(SinOsc.ar(44100/64, 0.0),1,1)).poll}.play // 0.098
 > x = {(Amplitude.kr(SinOsc.ar(44100/64, pi/4),1,1)).poll}.play // 0.77
 >
 > Options for fixing this:
 >
 > (1) Alter the UGen source, add a new calc func to deal with the a-to-k
 > (2) Make Amplitude a subclass of Filter, so it refuses to run k-rate
 > on an a-rate input (unhelpful!)
 > (3) Alter the Amplitude class so it automatically replaces
 > Amplitude.kr(x.ar) with A2K.kr(Amplitude.ar(x.ar))
 >
 > Any particular thoughts?
 >
 > Dan
 >
 > --
 > http://www.mcld.co.uk
 > _______________________________________________
 > Sc-devel mailing list
 > Sc-devel@xxxxxxxxxxxxxxx
 > http://www.create.ucsb.edu/mailman/listinfo/sc-devel

 ******************************************
 /* Joshua D. Parmenter
 http://www.realizedsound.net/josh/

 "Every composer - at all times and in all cases - gives his own
 interpretation of how modern society is structured: whether actively
 or passively, consciously or unconsciously, he makes choices in this
 regard. He may be conservative or he may subject himself to continual
 renewal; or he may strive for a revolutionary, historical or social
 palingenesis." - Luigi Nono
 */


 _______________________________________________
 Sc-devel mailing list
 Sc-devel@xxxxxxxxxxxxxxx
 http://www.create.ucsb.edu/mailman/listinfo/sc-devel



--
http://www.mcld.co.uk

_______________________________________________
Sc-devel mailing list
Sc-devel@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-devel


--





.