Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 初学者:将byte()转换/复制为single()的最快方法_Vb.net_Byte_Casting_Ctype - Fatal编程技术网

Vb.net 初学者:将byte()转换/复制为single()的最快方法

Vb.net 初学者:将byte()转换/复制为single()的最快方法,vb.net,byte,casting,ctype,Vb.net,Byte,Casting,Ctype,我得到了一个作为directx声音捕获结果返回的字节数组,但对于程序的其他部分,我希望将结果视为单个。逐项滚动数组是最快的方法还是有一种聪明的方法 得到它的代码是 CType(Me._applicationBuffer.Read(Me._nextCaptureOffset, GetType(Byte), LockFlag.None, LockSize), Byte()) 哪个创建了字节数组,Ctype可以处理单字节数组吗?注意,我想不出一个办法 试试看 float f = BitConvert

我得到了一个作为directx声音捕获结果返回的字节数组,但对于程序的其他部分,我希望将结果视为单个。逐项滚动数组是最快的方法还是有一种聪明的方法

得到它的代码是

CType(Me._applicationBuffer.Read(Me._nextCaptureOffset, GetType(Byte), LockFlag.None, LockSize), Byte())
哪个创建了字节数组,Ctype可以处理单字节数组吗?注意,我想不出一个办法

试试看

float f = BitConverter.ToSingle(bytearray, 0);
在VB中,我认为:

Dim single s;
s = BitConverter.ToSingle(bytearray, 0);

就性能而言,相对于编写所需的时间而言,最快的方法可能是使用API调用。

可能需要添加一个检查以确保bytearray。长度%4==0?他的字节数组来自音频数据,因此长度通常不会是4的倍数。我刚刚想到,如果他的数据是立体声,那么它可能永远是4的倍数。这不是他所要求的。另外,VB不使用分号!每当我被迫触摸VB时,我就会犯那个错误-
public float[] ByteArrayToFloatArray(byte[] byteArray)
{
    float[] floatArray = new float[byteArray.Length / 4];
    for (int i = 0; i < floatArray.Length; i++)
    {
        floatArray[i] = BitConverter.ToSingle(byteArray, i * 4);
    }
    return floatArray;
}