bytearray

Efficiently convert audio bytes - byte[] to short[]

折月煮酒 提交于 2020-01-14 00:34:26
问题 I'm trying to use the XNA microphone to capture audio and pass it to an API I have that analyses the data for display purposes. However, the API requires the audio data in an array of 16 bit integers. So my question is fairly straight forward; what's the most efficient way to convert the byte array into a short array? private void _microphone_BufferReady(object sender, System.EventArgs e) { _microphone.GetData(_buffer); short[] shorts; //Convert and pass the 16 bit samples ProcessData(shorts)

C# Reading Byte Array

馋奶兔 提交于 2020-01-13 17:56:20
问题 Okay so I am building server <-> client application. Basically server receives a packet that contains header[2bytes], cryptokeys[2bytes],and data I was thinking about building class to load whole packet (byte[]) into it and then process the packet with inside class methods. Now to the question. What would be best approach to this? I need to be able to read Int16 Int32 String(int lenght) and probably float Edit: Kinda like binaryreader but for byte[] as an input 回答1: I would say BinaryReader

NetStream.appendBytes

谁都会走 提交于 2020-01-13 11:17:07
问题 I have a netConnection connected to a Flash Media Server. I am trying to use the new appendBytes function from Flash Player 10.1 to stream a local FLV file to FMS. I'm having issues however... Documentation I get online function playFile(data:ByteArray):void { // data is bytearray data from an already loaded FileReference object netStream.play(null); netStream.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN); netStream.appendBytes(data); } However, I'm getting an error with the

Perl pack/unpack and length of binary string

天涯浪子 提交于 2020-01-13 05:09:09
问题 Consider this short example: $a = pack("d",255); print length($a)."\n"; # Prints 8 $aa = pack("ddddd", 255,123,0,45,123); print length($aa)."\n"; # Prints 40 @unparray = unpack("d "x5, $aa); print scalar(@unparray)."\n"; # Prints 5 print length($unparray[0])."\n" # Prints 3 printf "%d\n", $unparray[0] ' # Prints 255 # As a one-liner: # perl -e '$a = pack("d",255); print length($a)."\n"; $aa = pack("dd", 255,123,0,45,123); print length($aa)."\n"; @unparray = unpack("d "x5, $aa); print scalar(

sbyte[] can be magically cast to byte[]

◇◆丶佛笑我妖孽 提交于 2020-01-12 12:53:41
问题 I'm not sure whether this is a .NET bug but I find it really interesting. As expected, I cannot do this: sbyte[] sbytes = { 1, 2, 3 }; byte[] bytes = sbytes; // fails: cannot convert source type 'sbyte[]' to taget type 'byte[]' However, if the type of sbytes is object , this works: object obj = new sbyte[]{ 1, 2, 3 }; byte[] bytes = obj as byte[]; Assert.IsNull(bytes, "WTF??") Remark 1 : The same issue occurs for int[] - uint[] and the other primitive types as well. Remark 2 : Though the code

sbyte[] can be magically cast to byte[]

一曲冷凌霜 提交于 2020-01-12 12:53:15
问题 I'm not sure whether this is a .NET bug but I find it really interesting. As expected, I cannot do this: sbyte[] sbytes = { 1, 2, 3 }; byte[] bytes = sbytes; // fails: cannot convert source type 'sbyte[]' to taget type 'byte[]' However, if the type of sbytes is object , this works: object obj = new sbyte[]{ 1, 2, 3 }; byte[] bytes = obj as byte[]; Assert.IsNull(bytes, "WTF??") Remark 1 : The same issue occurs for int[] - uint[] and the other primitive types as well. Remark 2 : Though the code

sbyte[] can be magically cast to byte[]

独自空忆成欢 提交于 2020-01-12 12:51:50
问题 I'm not sure whether this is a .NET bug but I find it really interesting. As expected, I cannot do this: sbyte[] sbytes = { 1, 2, 3 }; byte[] bytes = sbytes; // fails: cannot convert source type 'sbyte[]' to taget type 'byte[]' However, if the type of sbytes is object , this works: object obj = new sbyte[]{ 1, 2, 3 }; byte[] bytes = obj as byte[]; Assert.IsNull(bytes, "WTF??") Remark 1 : The same issue occurs for int[] - uint[] and the other primitive types as well. Remark 2 : Though the code

How to convert a byte array to a string, and string to a byte array with GWT?

别来无恙 提交于 2020-01-12 09:16:58
问题 The String(byte[] bytes) constructor and String.getBytes() method are not implemented by GWT JRE emulation String class. Does anybody know of an implementation? I do not want to use char[] , But it seems like there is no other solution. 回答1: If you create large arrays in Chrome, you might run into a Uncaught RangeError: Maximum call stack size exceeded exception. The code from LINEMAN78 can be modified to use a StringBuilder, which avoids this issue. public static String getString(byte[]

How to convert string to base64 byte array, would this be valid?

自作多情 提交于 2020-01-11 21:53:26
问题 I'm trying to write a function that converts a string to a base64 byte array. I've tried with this approach: public byte[] stringToBase64ByteArray(String input) { byte[] ret = System.Text.Encoding.Unicode.GetBytes(input); string s = Convert.ToBase64String(input); ret = System.Text.Encoding.Unicode.GetBytes(s); return ret; } Would this function produce a valid result (provided that the string is in unicode)? Thanks! 回答1: Looks okay, although the approach is strange. But use Encoding.ASCII

Bitmap too big as3

强颜欢笑 提交于 2020-01-11 13:30:12
问题 In AS3, I am loading a png from a zip file (nochump's zip library through ByteArray to Loader). The png can be up to 45k pixels wide but only 120 tall. This creates a problem in flash, as images can only be ~8000 pixels wide. A possible solution would be to split the images into 6 columns somehow. This would probably need to be done in the ByteArray state, because the limitation is in Bitmap and Loader. Would this even be possible? 回答1: I believe you should use Alchemy to decode such a large