C表达式:
#define EFX_REVERB_PRESET_GENERIC \
{ 1.0000f, 1.0000f, 0.3162f, 0.8913f, 1.0000f, 1.4900f, 0.8300f, 1.0000f, 0.0500f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }我想在.pxd文件中定义这个表达式。
我必须将这个表达式作为参数传递给一些C函数。所以我不将它用于Python。
来源:OpenAL-Soft:https://github.com/kcat/openal-soft/blob/master/include/AL/efx-presets.h#L37
发布于 2020-08-14 08:01:04
值得注意的是,并非所有的东西都有从C到Cython的直接翻译。在这种情况下,不能真正使用类型来定义EFX_REVERB_PRESET_GENERIC,因为它不是类型--它只是括号和数字的集合。这些括号和数字只在少数地方有效:
void other_func(WhateverTheStructIsCalled s);
void func() {
WhateverTheStructIsCalled s = EFX_REVERB_PRESET_GENERIC; // OK
s = EFX_REVERB_PRESET_GENERIC; // wrong - not an initialization
other_func(EFX_REVERB_PRESET_GENERIC); // also doesn't work
}因此,它并不真正适合Cython的模型,因此不能直接包装它。
我要做的就是自己写一个小的C包装器。您可以使用Cython的“内联C代码”函数来完成这一任务:
cdef extern from *:
"""
WhateverTheStructIsCalled get_EFX_REVERB_PRESET_GENERIC(void) {
WhateverTheStructIsCalled s = EFX_REVERB_PRESET_GENERIC;
return s;
}
"""
WhateverTheStructIsCalled get_EFX_REVERB_PRESET_GENERIC()然后使用get_EFX_REVERB_PRESET_GENERIC()调用该函数,得到相应的初始化结构。
https://stackoverflow.com/questions/63397901
复制相似问题