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

Method Calc

XBOBTFF/FeedbackXBOEffect.cpp:44–133  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

42// Calc
43//----------------------------------------------------------------------------------------------
44LONG FeedbackXBOEffect::Calc(LONG *LeftLevel, LONG *RightLevel, LONG *ltLevel, LONG *rtLevel)
45{
46 CFTimeInterval Duration = 0;
47 if(DiEffect.dwDuration != FF_INFINITE) {
48 Duration = max(1., DiEffect.dwDuration / 1000.) / 1000.;
49 } else {
50 Duration = DBL_MAX;
51 }
52 double BeginTime = StartTime + ( DiEffect.dwStartDelay / 1000. / 1000.);
53 double EndTime = DBL_MAX;
54 if (PlayCount != -1)
55 {
56 EndTime = BeginTime + Duration * PlayCount;
57 }
58 double CurrentTime = CurrentTimeUsingMach();
59
60 if (Status == FFEGES_PLAYING && BeginTime <= CurrentTime && CurrentTime <= EndTime)
61 {
62 // Used for force calculation
63 LONG NormalLevel;
64 LONG WorkLeftLevel;
65 LONG WorkRightLevel;
66 LONG WorkLTLevel;
67 LONG WorkRTLevel;
68
69 // Used for envelope calculation
70 LONG NormalRate;
71 LONG AttackLevel;
72 LONG FadeLevel;
73
74 CalcEnvelope((ULONG)(Duration*1000)
75 ,(ULONG)(fmod(CurrentTime - BeginTime, Duration)*1000)
76 ,&NormalRate
77 ,&AttackLevel
78 ,&FadeLevel);
79
80 // CustomForce allows setting each channel separately
81 if(CFEqual(Type, kFFEffectType_CustomForce_ID)) {
82 if((CurrentTimeUsingMach() - LastTime)*1000*1000 < DiCustomForce.dwSamplePeriod) {
83 return -1;
84 }
85 else {
86 if (DiCustomForce.cChannels == 2) {
87 WorkLeftLevel = ((DiCustomForce.rglForceData[2*Index] * NormalRate + AttackLevel + FadeLevel) / 100) * DiEffect.dwGain / 10000;
88 WorkRightLevel = ((DiCustomForce.rglForceData[2*Index + 1] * NormalRate + AttackLevel + FadeLevel) / 100) * DiEffect.dwGain / 10000;
89 WorkLTLevel = 0;
90 WorkRTLevel = 0;
91 //fprintf(stderr, "L:%d; R:%d\n", WorkLeftLevel, WorkRightLevel);
92 Index = (Index + 1) % (DiCustomForce.cSamples/2);
93 LastTime = CurrentTimeUsingMach();
94 } else {
95 WorkLeftLevel = ((DiCustomForce.rglForceData[4*Index] * NormalRate + AttackLevel + FadeLevel) / 100) * DiEffect.dwGain / 10000;
96 WorkRightLevel = ((DiCustomForce.rglForceData[4*Index + 1] * NormalRate + AttackLevel + FadeLevel) / 100) * DiEffect.dwGain / 10000;
97 WorkLTLevel = ((DiCustomForce.rglForceData[4*Index + 2] * NormalRate + AttackLevel + FadeLevel) / 100) * DiEffect.dwGain / 10000;
98 WorkRTLevel = ((DiCustomForce.rglForceData[4*Index + 3] * NormalRate + AttackLevel + FadeLevel) / 100) * DiEffect.dwGain / 10000;
99 //fprintf(stderr, "L:%d; R:%d\n", WorkLeftLevel, WorkRightLevel);
100 Index = (Index + 1) % (DiCustomForce.cSamples/4);
101 LastTime = CurrentTimeUsingMach();

Callers 1

EffectProcMethod · 0.45

Calls 1

CurrentTimeUsingMachFunction · 0.70

Tested by

no test coverage detected