[sip-comm-dev] gsoc - wideband codec - CELT


#1

Hi Lubo, Jean, Emil,

I talked with Lubo yesterday by IM, and what he said reminds me of two of my
problems with my code (I didn't realize that until today), which I want to
ask.

1. The cpx structure {float r, float i} in c, which contains two float
members, is translated to class cpx in java. The variables of this type is
offen refered as arrays(or pointers in c). Some functions/methods who have
this kind of pointers/arrays as arguments are called to deal with float
arrays. In c it is simple, e.g., for float* fin, just be forced converted by
(*cpx)fin, and can be called as e.g. fft(..., (*cpx)fin, ...). But in java
this is a little tricky. What I did is creating another array: cpx[]
fin_cpx, and copy the content of float[] fin like:
for(int i=0; i < fin.length / 2; i++)
{ fin_cpx[i].r = fin[2*i]; fin_cpx[i].i = fin[2*i+1]; }
then call fft(..., fin_cpx, ..), and copy the content back to fin[] after
calling the method, which produces a lot of garbages and will probably be
fatal for the performance. --Thanks to Lubo's reminding of a similar
problem.

2. Object array initialization. Take the cpx class for example, I inicialize
it in this way:
cpx[] asd = new cpx[n];
for(int i=0; i<n; i++)
    asd[i] = new cpx();
which I think may be inefficient because of the for loop.

Any suggestions on these two questions?

BTW, my translation work of CELT is nearly finished, I've successfully
passed all the tests except for the one for entile codec. I've seen Emil's
foward message about the combination of CELT and SILK, which is also
interesting to me. Hope my code will do some help soon :slight_smile:

Cheers,
Jing


#2

1. The cpx structure {float r, float i} in c, which contains two float
members, is translated to class cpx in java. The variables of this type is
offen refered as arrays(or pointers in c). Some functions/methods who have
this kind of pointers/arrays as arguments are called to deal with float
arrays. In c it is simple, e.g., for float* fin, just be forced converted by
(*cpx)fin, and can be called as e.g. fft(..., (*cpx)fin, ...). But in java
this is a little tricky. What I did is creating another array: cpx[]
fin_cpx, and copy the content of float[] fin like:
for(int i=0; i < fin.length / 2; i++)
{ fin_cpx[i].r = fin[2*i]; fin_cpx[i].i = fin[2*i+1]; }
then call fft(..., fin_cpx, ..), and copy the content back to fin[] after
calling the method, which produces a lot of garbages and will probably be
fatal for the performance.

If the usage suggests that the code is often executed (which seems to
be the case as far as I understand from your description) and thus
poses a threat to performance, one could, for example, convert the cpx
structure to class cpx { static final int CPX_R = 0; static final int
CPX_I = 1; final float[] cpx = new float[2]; }.

2. Object array initialization. Take the cpx class for example, I inicialize
it in this way:
cpx[] asd = new cpx[n];
for(int i=0; i<n; i++)
asd[i] = new cpx();
which I think may be inefficient because of the for loop.

If the loop alone seems to be the cause for the concern and the line
of thought leads to loop unwinding, I wouldn't bother.

···

On Thu, Jul 8, 2010 at 6:52 AM, Dai Jing <daijing09@gmail.com> wrote:

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#3

For the record, I and Jing had an offline conversation in which Jing
alerted me that I'd missed in my previous e-mail that whole cpx[] are
being treated as float[] and we settled on allocating the float
storage for a whole cpx[] in one go and then allocating the cpx
instances on top it using r and i indices in it. We'll see how far it
will go but it should be more optimal than allocating and copying
temporary arrays before and after function calls.

···

On Thu, Jul 8, 2010 at 10:30 AM, Lubomir Marinov <lubo@sip-communicator.org> wrote:

On Thu, Jul 8, 2010 at 6:52 AM, Dai Jing <daijing09@gmail.com> wrote:

1. The cpx structure {float r, float i} in c, which contains two float
members, is translated to class cpx in java. The variables of this type is
offen refered as arrays(or pointers in c). Some functions/methods who have
this kind of pointers/arrays as arguments are called to deal with float
arrays. In c it is simple, e.g., for float* fin, just be forced converted by
(*cpx)fin, and can be called as e.g. fft(..., (*cpx)fin, ...). But in java
this is a little tricky. What I did is creating another array: cpx[]
fin_cpx, and copy the content of float[] fin like:
for(int i=0; i < fin.length / 2; i++)
{ fin_cpx[i].r = fin[2*i]; fin_cpx[i].i = fin[2*i+1]; }
then call fft(..., fin_cpx, ..), and copy the content back to fin[] after
calling the method, which produces a lot of garbages and will probably be
fatal for the performance.

If the usage suggests that the code is often executed (which seems to
be the case as far as I understand from your description) and thus
poses a threat to performance, one could, for example, convert the cpx
structure to class cpx { static final int CPX_R = 0; static final int
CPX_I = 1; final float[] cpx = new float[2]; }.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net