On Thu, Oct 6, 2016 at 5:40 PM, Jérémy Béjanin <jeremy.beja...@gmail.com> 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