편집 - 다음은 outDuration
과 그 다음 inDuration
사이의 1.0에 머무르는 새로운 기능입니다. 함수 서명을 변경했음을 유의하십시오. 입력 매개 변수는 이제 inDuration
, holdDuration
및 outDuration
입니다. 이 함수는 holdDuration
샘플의 경우 inDuration
과 outDuration
사이의 0에 머무른 다음 다른 holdDuration
샘플의 경우 outDuration
이후에 1.0으로 유지됩니다. 램프는 하프 칸 기능이며 원하는대로 변경할 수 있습니다.
public static double Calculate(UInt64 currentCounter, uint inDuration, uint holdDuration, uint outDuration)
{
UInt64 curTime;
double ret;
curTime = currentCounter % (inDuration + 2*holdDuration + outDuration); //this wrapping should really be handled by the caller
if (curTime < inDuration)
{
ret = 0.5 * (1.0 - Math.Cos(2.0 * Math.PI * (inDuration - curTime)/(2.0 * inDuration)));
}
else if (curTime < inDuration + holdDuration)
{
ret = 0.0;
}
else if (curTime < inDuration + holdDuration + outDuration)
{
ret = 0.5 * (1.0 - Math.Cos(2.0 * Math.PI * (curTime - inDuration - holdDuration)/(2.0 * outDuration)));
}
else
{
ret = 1.0;
}
return ret;
}
이것은 이전 버전과 동일한 주기성 기능을 가지고 있습니다.
다음은 두 사이클의 기능을 보여주는 그래프입니다. 테스트 루프는 내가 그런 것들에 대한 Hann function의 큰 팬이에요
for (ctr = 0; ctr < 20000; ctr++)
Calculate(ctr, 2500, 2250, 3000);
alt text http://img16.imageshack.us/img16/4443/oscfnxn2.png
첫 번째 버전이었다. 이것이 문제가된다면 그것은 지속적이고 차별화됩니다.다음은 간단한 구현입니다.
public static double Calculate(UInt64 currentCounter, uint duration, uint inDuration, uint outDuration)
{
UInt64 curTime;
double ret;
//should check that inDuration + outDuration <= duration
curTime = currentCounter % duration; //this wrapping should really be handled by the caller
if (curTime < inDuration)
{
ret = 0.5 * (1.0 - Math.Cos(2.0 * Math.PI * (inDuration - curTime)/(2.0 * inDuration)));
}
else if (curTime >= (duration - outDuration))
{
ret = 0.5 * (1.0 - Math.Cos(2.0 * Math.PI * (outDuration + duration - curTime)/(2.0 * outDuration)));
}
else
{
ret = 1.0;
}
return ret;
}
다음은 샘플 그래프입니다. 이것은 루프
for (ctr = 0; ctr < 10000; ctr++)
Calculate(ctr, 10000, 2500, 3000);
Graph with duration = 10000, in = 2500, out = 3000 http://img269.imageshack.us/img269/2969/oscfnxn.png
함수는 inDuration
에 인덱스 0
에서 1.0 0 가져갈 생성 지수 duration-outDuration
는 다음 인덱스 duration
에서 1.0으로 상승 할 때까지 0으로 유지되므로 정확히하였습니다 'duration'샘플에서 주기적입니다.
"귀하의 의견을 이해하지 못했습니다. 시간이 지나면 1 시가됩니다." 대기 시간을 지정하는 데 다른 매개 변수가 필요하지 않습니까?
함수는'inDuration'과 ('Duration' -'outDuration') 사이에 어떻게 정의되어 있습니까? 그것이 0이거나 정의되지 않았습니까? –
inDuration 및 outDuration 동안의 진동 기능은 무엇입니까? (선형입니까, X^2, sin (X) ...?) – Elisha
'currentCounter' 매개 변수가'double' 또는'float'이 아니어야합니까? –