The format is fairly complicated, but I need to take 4 bytes from that 
buffer and extract two 12-bit numbers from that 32-bit string (along with 
some reversing operations, as you can see in the function). I cannot seem 
to find bit operations that address/concatenate individual bits without 
going through a string format and parsing. Would you have any guidance as 
to where in the manual I should look?

On Thursday, October 6, 2016 at 8:15:41 PM UTC-4, Yichao Yu wrote:
>
> On Thu, Oct 6, 2016 at 5:40 PM, Jérémy Béjanin <jeremy....@gmail.com 
> <javascript:>> wrote: 
> > Thanks! this works perfectly. 
> > 
> > The pointer_to_array() function seems to be deprecated, however, do you 
> know 
> > how to use the suggested replacement, unsafe_wrap()? 
>
> Yes. 
>
> > 
> > And if it's not too much to ask, I am wondering how I can do the 
> conversion 
> > from this UInt8 buffer more efficiently. This is what I am currently 
> doing, 
> > where blocks is the buffer: 
> > 
> > # We now have all the blocks in the blocks array, we need to extract the 
> > # 12-bit samples from that array. The data in the blocks is organized in 
> 4 
> > # bytes / 32-bit words, and each word contains two 12-bit samples. 
> > # Calculate the number of 32-bit words in the blocks array 
> > numwords = div(numblocks*DIG_BLOCK_SIZE,4) 
> > # Initialize array to store the samples 
> > data = Array{Int32}(2*numwords) 
> > for n=1:numwords 
> >     # Convert next four bytes to 32-bit string 
> >     s = 
> > 
> reverse(bits(blocks[(n-1)*4+1]))*reverse(bits(blocks[(n-1)*4+2]))*reverse(bits(blocks[(n-1)*4+3]))*reverse(bits(blocks[(n-1)*4+4]))
>  
>
> >     # Parse the first 12 bits as the first sample and the 12 bits 4 bits 
> > later as the second sample 
> >     data[(n-1)*2+1] = parse(Int,reverse(s[1:12]),2) 
> >     data[(n-1)*2+2] = parse(Int,reverse(s[17:28]),2) 
> > end 
> > 
> > This is pretty slow, I assume due to the translation between numbers and 
> > strings. Is there a better way to do this? 
>
> I don't know what exactly the format is but you should not go though 
> string and you should be able to do what you want with simple 
> interger/bits operations. 
>
> > 
> > Thanks, 
> > Jeremy 
> > 
>

Reply via email to