MCPcopy Create free account
hub / github.com/360Controller/360Controller / Calc

Method Calc

Feedback360/Feedback360Effect.cpp:60–129  ·  view source on GitHub ↗

---------------------------------------------------------------------------------------------- Calc ----------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

58// Calc
59//----------------------------------------------------------------------------------------------
60LONG Feedback360Effect::Calc(LONG *LeftLevel, LONG *RightLevel)
61{
62 CFTimeInterval Duration = 0;
63 if(DiEffect.dwDuration != FF_INFINITE) {
64 Duration = max(1., DiEffect.dwDuration / 1000.) / 1000.;
65 } else {
66 Duration = DBL_MAX;
67 }
68 double BeginTime = StartTime + ( DiEffect.dwStartDelay / 1000. / 1000.);
69 double EndTime = DBL_MAX;
70 if (PlayCount != -1)
71 {
72 EndTime = BeginTime + Duration * PlayCount;
73 }
74 double CurrentTime = CurrentTimeUsingMach();
75
76 if (Status == FFEGES_PLAYING && BeginTime <= CurrentTime && CurrentTime <= EndTime)
77 {
78 // Used for force calculation
79 LONG NormalLevel;
80 LONG WorkLeftLevel;
81 LONG WorkRightLevel;
82
83 // Used for envelope calculation
84 LONG NormalRate;
85 LONG AttackLevel;
86 LONG FadeLevel;
87
88 CalcEnvelope((ULONG)(Duration*1000)
89 ,(ULONG)(fmod(CurrentTime - BeginTime, Duration)*1000)
90 ,&NormalRate
91 ,&AttackLevel
92 ,&FadeLevel);
93
94 // CustomForce allows setting each channel separately
95 if(CFEqual(Type, kFFEffectType_CustomForce_ID)) {
96 if((CurrentTimeUsingMach() - LastTime)*1000*1000 < DiCustomForce.dwSamplePeriod) {
97 return -1;
98 }
99 else {
100 WorkLeftLevel = ((DiCustomForce.rglForceData[2*Index] * NormalRate + AttackLevel + FadeLevel) / 100) * DiEffect.dwGain / 10000;
101 WorkRightLevel = ((DiCustomForce.rglForceData[2*Index + 1] * NormalRate + AttackLevel + FadeLevel) / 100) * DiEffect.dwGain / 10000;
102 //fprintf(stderr, "L:%d; R:%d\n", WorkLeftLevel, WorkRightLevel);
103 Index = (Index + 1) % (DiCustomForce.cSamples/2);
104 LastTime = CurrentTimeUsingMach();
105 }
106 }
107 // Regular commands treat controller as a single output (both channels are together as one)
108 else {
109 CalcForce(
110 (ULONG)(Duration*1000)
111 ,(ULONG)(fmod(CurrentTime - BeginTime, Duration)*1000)
112 ,NormalRate
113 ,AttackLevel
114 ,FadeLevel
115 ,&NormalLevel );
116 //fprintf(stderr, "DeltaT %f\n", CurrentTime - BeginTime);
117 //fprintf(stderr, "Duration %f; NormalRate: %d; AttackLevel: %d; FadeLevel: %d\n", Duration, NormalRate, AttackLevel, FadeLevel);

Callers 1

EffectProcMethod · 0.45

Calls 1

CurrentTimeUsingMachFunction · 0.70

Tested by

no test coverage detected