我有一些问题可能对其他人也有帮助.
内置的Unity着色器支持将32位RGBA值编码和解码为32位浮点的技术。这可以通过简单地将每个通道与其之前的通道的最高可能值相乘来完成。由于将其存储在浮点中,因此可能会降低精度。
着色器显然具有一些我想了解的优化。
UnityCG.cginc代码中的着色器如下所示:
// Encoding/decoding [0..1) floats into 8 bit/channel RGBA. Note that 1.0 will not be encoded properly.
inline float4 EncodeFloatRGBA( float v )
{
float4 kEncodeMul = float4(1.0, 255.0, 65025.0, 16581375.0);
float kEncodeBit = 1.0/255.0;
float4 enc = kEncodeMul * v;
enc = frac (enc);
enc -= enc.yzww * kEncodeBit;
return enc;
}
inline float DecodeFloatRGBA( float4 enc )
{
float4 kDecodeDot = float4(1.0, 1/255.0, 1/65025.0, 1/16581375.0);
return dot( enc, kDecodeDot );
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:
我有一个字节数组,我想通过Int32指针访问(不安全的上下文).我这样做
byte[] bgImageBytes = new byte[1000];
unsafe
{
fixed (byte* bgImgPtr = bgImageBytes)
{
// I have a byte pointer ... How can I get an Int32 pointer?
}
}
Run Code Online (Sandbox Code Playgroud)
我已经将从kernel32.dll返回的指针作为Byte和Int32指针访问,没有任何问题.但是当我尝试在托管字节数组上创建一个Int32指针(上面的示例)时,它似乎抱怨它是托管代码,所以它不起作用.
简单地UInt32* bgImgIntPtr = (UInt32*)bgImgPtr;在MDA FatalExecutionEngineError中执行结果:CLR已被致命损坏.这通常是由数据损坏引起的,数据损坏可能是由许多问题引起的,例如调用格式错误的平台调用函数以及将无效数据传递给CLR.
我的目标:将UInt32和Byte指针都指向一个bytearray,这样我就可以将Kinect"热图"作为整数和单独颜色读取.我知道我可以轻松地在类型之间进行转换,但由于我正在使用不同格式的多个数组,如果我可以直接访问它们而不必一直在它们之间进行转换会更好.有很多简单的复制正在进行,所以它只会增加开销以保持转换.
我做了一个应用程序,实时绘制FFT到屏幕(从麦克风).x轴上的时间,y轴上的频率和像素的颜色表示幅度(几乎是一个vanilla FFT频谱图).
我的问题是,虽然我可以从音乐中看到一个模式,但也有很多噪音.谷歌搜索它我看到人们对振幅应用对数计算.我应该这样做吗?如果是这样,公式会是什么样子?(我正在使用C#,但我可以将数学翻译成代码,所以任何样本都可以.)
我可以通过将显示较低值的颜色方案应用为较暗的颜色来绕过此问题.我只是不确定音频是否正确表示而没有对数计算.
我正在尝试使用P/Invoke为本机c ++ .dll创建一个包装器.
.dll的源代码具有以下指定的入口点:
// .h-file
CHROMAPRINT_API ChromaprintContext *chromaprint_new(int algorithm);Run Code Online (Sandbox Code Playgroud)
方法实现:
// .cpp-file
ChromaprintContext *chromaprint_new(int algorithm)
{
ChromaprintContextPrivate *ctx = new ChromaprintContextPrivate();
ctx->algorithm = algorithm;
ctx->fingerprinter = new Fingerprinter(CreateFingerprinterConfiguration(algorithm));
return (ChromaprintContext *)ctx;
}Run Code Online (Sandbox Code Playgroud)
ChromaprintContextPrivate类型是一个结构:
>// .cpp-file
struct ChromaprintContextPrivate {
int algorithm;
Fingerprinter *fingerprinter;
vector<int32_t> fingerprint;
};Run Code Online (Sandbox Code Playgroud)
我的C#包装器代码:
// .cs-file
[System.Runtime.InteropServices.DllImportAttribute(
"libchromaprint.dll",
EntryPoint = "chromaprint_new")]
private static extern System.IntPtr chromaprint_new(int algorithm);
public static IntPtr Chromaprint_New(ChromaprintAlgorithm algorithm)
{
// Hardcoded parameter for testing
return chromaprint_new(0); // (int)algorithm
}Run Code Online (Sandbox Code Playgroud)
调用IntPtr ptr = …
我正在改变现有解决方案中的一些Perl脚本.由于升级(Windows)服务器时发生了一些变化,我将它们从运行ISAPI切换到CGI.这意味着我现在必须手动发送Content-Type,否则它将失败.
所以我需要启用输出缓冲(print语句,所以STDOUT),发送Content-Type:text/html,但是在它是重定向的情况下我需要清除输出缓冲区并发送新的标题.
我怎么做?
或者还有另一种方式吗?请注意,该脚本已print用于输出HTML,我无法更改.(它写于90年代初期.)
select(STDOUT);
$| = 0;
print "Content-Type: text/html\n\n";
# somehow clear output
print "Location: login.pl\n\n";
Run Code Online (Sandbox Code Playgroud)