gpt4 book ai didi

c++ - 将JNI代码移植到java并理解jdouble * 用法

转载 作者:行者123 更新时间:2023-11-30 16:11:02 25 4
gpt4 key购买 nike

我无法理解 jdouble * 的用法。我看到它用作数组和 double 。你能向我解释一下 InitiateBuffer 的作用以及 State->X = State->Buffer + OFFSET_X; 的结果是什么吗?

#undef OFFSET_X
#define OFFSET_X 0L
#undef OFFSET_Y
#define OFFSET_Y 500L
#undef OFFSET_Z
#define OFFSET_Z 1000L

typedef struct {
jdoubleArray BufferArray;
jdouble *Buffer;
jdouble *X;
jdouble *Y;
jdouble *Z;
jint Position;
} StateStructure;

void InitiateBuffer(StateStructure *State) {
JNIEnv *JNI = State->JNI;
State->BufferArray = (*JNI)->NewGlobalRef(JNI, (*JNI)->NewDoubleArray(JNI, SIZE_BUFFER));
State->Buffer = (*JNI)->GetDoubleArrayElements(JNI, State->BufferArray, NULL);
Fill(State->Buffer, 0, SIZE_BUFFER, FP_NAN);
(*JNI)->ReleaseDoubleArrayElements(JNI, State->BufferArray, State->Buffer, JNI_COMMIT);
State->TimeoutImpact = -1;
State->TimeoutFalling = -1;
State->Position = 0;
}

void InitiateSamples(StateStructure *State) {
State->X = State->Buffer + OFFSET_X;
State->Y = State->Buffer + OFFSET_Y;
State->Z = State->Buffer + OFFSET_Z;
}

jdouble LPF(jdouble Value, jdouble *XV, jdouble *YV) {
XV[0] = XV[1];
XV[1] = XV[2];
XV[2] = Value / FILTER_LPF_GAIN;
YV[0] = YV[1];
YV[1] = YV[2];
YV[2] = (XV[0] + XV[2]) + 2 * XV[1] + (FILTER_FACTOR_0 * YV[0]) + (FILTER_FACTOR_1 * YV[1]);
return YV[2];
}

void Process() {
jint At = State->Position;
State->TimeoutFalling = EXPIRE(State->TimeoutFalling);
State->TimeoutImpact = EXPIRE(State->TimeoutImpact);
State->X_LPF[At] = LPF(State->X[At], State->XLPFXV, State->XLPFYV);
}

最佳答案

您发布的整体架构尝试将一个数组分为三个(或更多?)部分并单独访问它们。

您没有向我们展示所有代码(例如 XLPFXVX_LPF ),但从您粘贴的内容我可以推断出以下关于 InitiateBuffer 的信息:

  • State->BufferArray是一个新的Java double大小数组 SIZE_BUFFER
  • State->Buffer是此数组的 C++ 友好别名
  • 之后InitiateBuffer ,Java 数组填充了 NaN 值。

InitiateSamplesState->Buffer内设置三个指针,X指针从Buffer[0]开始,Y 指针指向 Buffer[500] ,Z 指针位于 Buffer[1000] 。然后可以使用它们进一步索引数组(例如 State->Y[42] 引用 State->Buffer[500+42] )。

希望有帮助。

关于c++ - 将JNI代码移植到java并理解jdouble * 用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58745223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com