Adam,

You can use any primitive array type (or a wrapper, which basically boils down to the same thing - like a ShortBuffer, etc.).

Implementing FIFO semantics only requires two indices: one for the head, one for the tail, or better yet, head or tail and currently used size, so it's easier to handle wraparound. There is another technique for this too (having one extra slot that's never used).

http://en.wikipedia.org/wiki/Circular_buffer

Sometimes when reading you will get your data in two chunks, if the read happens to straddle the end of the underlying array. If this is a problem, you can make your buffer size be a multiple of read block size (in your example, 5000).

-- Kostya

24.02.2011 23:54, Serdel пишет:
I am trying to find an efficient fifo queue for primitive types. I
need this for processing recorded samples with AudioRecord class. My
problem is that I need to process the samples in excactly 5000 chunks.
But the buffer size gained by getMinBufferSize is different on each
devices and more over the amounts of samples read are also different
in each while iteration. For example on my phone the buffer size is
sth over 8000 but one time the samples are read in a about 2500
package, another time it's 6000 and another it's  almost 8000. So I am
putting my samples in a ConcurrentLinkedQueue fifo queue and if I
cross 5000 I take the first chunk and do the processing. However this
queue class can only accept non primitive type (so I must use Short
not short). And this is a major problem, because when I looked at
traceview I saw that a huge amount of time is taken by functions like
'ValueOf' (well if I have 5000 elements it's nothing surprising...).
In fact this is slowing down so much that, my recording process is
corrupted and the sound is broken.

Can any one advice some other fifo container I can use for working
with primitive types? I was thinking about ShortBuffer but this is
more like a lifo queue, and I need the samples in exact fifo order.



--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to