Nov 8, 2013 Replies: 9 This is a wrapper for the org.apache.http.util.ByteArrayBuffer class. It allows the resizing of the buffer which is useful for buffering very large amounts of data without the buffer continually growing (i.e. audio streaming). SLByteArrayBuffer Author: Steve Laming Version: 1 SLByteArrayBuffer Methods: AppendByte (b() As Byte, off As Int, len As Int) Appends len bytes to this buffer from the given source array starting at index off. AppendChar (b() As Char, off As Int, len As Int) Appends len chars to this buffer from the given source array starting at index off. AppendInt (b As Int) Appends b byte to this buffer. Buffer As Byte[] Returns reference to the underlying byte array. ByteAt (i As Int) As Int Returns the byte value in this buffer at the specified index. Capacity As Int Returns the current capacity. Clear Clears content of the buffer. Initialize (capacity As Int) ByteArrayBuffer(int capacity) Initialize the ByteArrayBuffer to the given capacity. IsEmpty As Boolean Returns true if this buffer is empty, that is, its length() is equal to 0. IsFull As Boolean Returns true if this buffer is full, that is, its length() is equal to its capacity(). SetLength (len As Int) Sets the length of the buffer. ToByteArray As Byte[] Converts the content of this buffer to an array of bytes. length As Int Returns the length of the buffer (byte count). Xml Document converted with warwounds B4A library reference generator V1.0 attached unzip the .jar and .xml files to you additional libraries folder. Attachments SLByteArrayBuffer.zip SLByteArrayBuffer.zip 2.7 KB · Views: 1,633 Click to expand...
This is a wrapper for the org.apache.http.util.ByteArrayBuffer class. It allows the resizing of the buffer which is useful for buffering very large amounts of data without the buffer continually growing (i.e. audio streaming). SLByteArrayBuffer Author: Steve Laming Version: 1 SLByteArrayBuffer Methods: AppendByte (b() As Byte, off As Int, len As Int) Appends len bytes to this buffer from the given source array starting at index off. AppendChar (b() As Char, off As Int, len As Int) Appends len chars to this buffer from the given source array starting at index off. AppendInt (b As Int) Appends b byte to this buffer. Buffer As Byte[] Returns reference to the underlying byte array. ByteAt (i As Int) As Int Returns the byte value in this buffer at the specified index. Capacity As Int Returns the current capacity. Clear Clears content of the buffer. Initialize (capacity As Int) ByteArrayBuffer(int capacity) Initialize the ByteArrayBuffer to the given capacity. IsEmpty As Boolean Returns true if this buffer is empty, that is, its length() is equal to 0. IsFull As Boolean Returns true if this buffer is full, that is, its length() is equal to its capacity(). SetLength (len As Int) Sets the length of the buffer. ToByteArray As Byte[] Converts the content of this buffer to an array of bytes. length As Int Returns the length of the buffer (byte count). Xml Document converted with warwounds B4A library reference generator V1.0 attached unzip the .jar and .xml files to you additional libraries folder.
D doncx Active Member Licensed User Longtime User Apr 16, 2014 #2 Steve - Great library idea! I'm having trouble appending the SLByteArrayBuffer from serial data received. I get a NullPointerException at line 45 in your library when I attempt AppendByte in the (selectively pasted) code below. I'm trying to build a combined byte array from incoming bluetooth traffic for later processing. Can you tell me what I'm doing wrong? Thanks, - Don B4X: Expand Collapse Copy Sub Process_Globals Dim BigBuffer As SLByteArrayBuffer End Sub Sub AStreams_NewData (Buffer() As Byte) LogBytes( Buffer ) End Sub Sub LogBytes( Msg() As Byte ) BigBuffer.AppendByte( Msg, 0, Msg.Length ) End Sub
Steve - Great library idea! I'm having trouble appending the SLByteArrayBuffer from serial data received. I get a NullPointerException at line 45 in your library when I attempt AppendByte in the (selectively pasted) code below. I'm trying to build a combined byte array from incoming bluetooth traffic for later processing. Can you tell me what I'm doing wrong? Thanks, - Don B4X: Expand Collapse Copy Sub Process_Globals Dim BigBuffer As SLByteArrayBuffer End Sub Sub AStreams_NewData (Buffer() As Byte) LogBytes( Buffer ) End Sub Sub LogBytes( Msg() As Byte ) BigBuffer.AppendByte( Msg, 0, Msg.Length ) End Sub
D doncx Active Member Licensed User Longtime User Apr 16, 2014 #3 doncx said: Steve - Great library idea! I'm having trouble appending the SLByteArrayBuffer from serial data received. I get a NullPointerException at line 45 in your library when I attempt AppendByte in the (selectively pasted) code below. I'm trying to build a combined byte array from incoming bluetooth traffic for later processing. Can you tell me what I'm doing wrong? Thanks, - Don B4X: Expand Collapse Copy Sub Process_Globals Dim BigBuffer As SLByteArrayBuffer End Sub Sub AStreams_NewData (Buffer() As Byte) LogBytes( Buffer ) End Sub Sub LogBytes( Msg() As Byte ) BigBuffer.AppendByte( Msg, 0, Msg.Length ) End Sub Click to expand... Nevermind! I neglected to initialize the SLByteArrayBuffer. Sheesh. Sorry to bother you.
doncx said: Steve - Great library idea! I'm having trouble appending the SLByteArrayBuffer from serial data received. I get a NullPointerException at line 45 in your library when I attempt AppendByte in the (selectively pasted) code below. I'm trying to build a combined byte array from incoming bluetooth traffic for later processing. Can you tell me what I'm doing wrong? Thanks, - Don B4X: Expand Collapse Copy Sub Process_Globals Dim BigBuffer As SLByteArrayBuffer End Sub Sub AStreams_NewData (Buffer() As Byte) LogBytes( Buffer ) End Sub Sub LogBytes( Msg() As Byte ) BigBuffer.AppendByte( Msg, 0, Msg.Length ) End Sub Click to expand... Nevermind! I neglected to initialize the SLByteArrayBuffer. Sheesh. Sorry to bother you.
stevel05 Expert Licensed User Longtime User Apr 16, 2014 #4 Nevermind! I neglected to initialize the SLByteArrayBuffer. Click to expand... Easy done, glad you found it.
Nevermind! I neglected to initialize the SLByteArrayBuffer. Click to expand... Easy done, glad you found it.
freedom2000 Well-Known Member Licensed User Longtime User Jan 10, 2015 #5 @stevel05 : First of all Thank you for this great library I am trying to use this lib to avoid memory overflow while processing audiostream. Thus I have a streamer which output buffers whose size is 3584 B4X: Expand Collapse Copy Sub streamer_RecordBuffer (Buffer() As Byte) 'collect the recording data Buffers.Add(Buffer) BuffersSize = BuffersSize + Buffer.Length Log(Buffer.length) '3584 End Sub I can easily empty these buffers into a ByteArrayBuffer with AppendByte B4X: Expand Collapse Copy BigBuffer.AppendByte( Buffer, 0, Buffer.Length ) However I need to process the data from the BigBuffer every 4096 bytes to perform a FFT. What would be nice would be to "resize" the bigbuffer any time I read 4096 bytes in order to decrease its size. Is there a way to do it ? - streamer happends at the end of BigBuffer - I read from the beginning 4096 bytes - BigBuffer start pointer is moved 4096 bytes headed Thanks
@stevel05 : First of all Thank you for this great library I am trying to use this lib to avoid memory overflow while processing audiostream. Thus I have a streamer which output buffers whose size is 3584 B4X: Expand Collapse Copy Sub streamer_RecordBuffer (Buffer() As Byte) 'collect the recording data Buffers.Add(Buffer) BuffersSize = BuffersSize + Buffer.Length Log(Buffer.length) '3584 End Sub I can easily empty these buffers into a ByteArrayBuffer with AppendByte B4X: Expand Collapse Copy BigBuffer.AppendByte( Buffer, 0, Buffer.Length ) However I need to process the data from the BigBuffer every 4096 bytes to perform a FFT. What would be nice would be to "resize" the bigbuffer any time I read 4096 bytes in order to decrease its size. Is there a way to do it ? - streamer happends at the end of BigBuffer - I read from the beginning 4096 bytes - BigBuffer start pointer is moved 4096 bytes headed Thanks
stevel05 Expert Licensed User Longtime User Jan 10, 2015 #6 To remove from the front of the buffer, you would have to set up a second buffer, append the data you want to keep to that then set the original to point to the new buffer. I'm not sure how quick it would be as you're processing Audio, but worth a try.
To remove from the front of the buffer, you would have to set up a second buffer, append the data you want to keep to that then set the original to point to the new buffer. I'm not sure how quick it would be as you're processing Audio, but worth a try.
freedom2000 Well-Known Member Licensed User Longtime User Jan 10, 2015 #7 Thank you, I will try it BTW, the FFT proccess is not very fast so I have to wait somewhere !
S sunish Member Licensed User Longtime User Sep 27, 2015 #8 Is there a direct method to add or assign a string to a SLByteArrayBuffer ?
stevel05 Expert Licensed User Longtime User Sep 27, 2015 #9 You could use the GetBytes method of the String. B4X: Expand Collapse Copy bb.append(str.GetBytes("UTF8"),0,str.Length)
You could use the GetBytes method of the String. B4X: Expand Collapse Copy bb.append(str.GetBytes("UTF8"),0,str.Length)
S sunish Member Licensed User Longtime User Sep 27, 2015 #10 stevel05 said: You could use the GetBytes method of the String. B4X: Expand Collapse Copy bb.append(str.GetBytes("UTF8"),0,str.Length) Click to expand... Thanks, I just realized I had already written the code long back 'RxBuff.AppendByte(SerData.GetBytes("UTF8"),0,SerData.Length) and nice to know its the right way. Last edited: Sep 27, 2015
stevel05 said: You could use the GetBytes method of the String. B4X: Expand Collapse Copy bb.append(str.GetBytes("UTF8"),0,str.Length) Click to expand... Thanks, I just realized I had already written the code long back 'RxBuff.AppendByte(SerData.GetBytes("UTF8"),0,SerData.Length) and nice to know its the right way.