1

I am working on my final project, hence I need to read wav file - I succeed to do it.

When I run the code in java it is take less then 1 sec, but when I try to run the code on Nexus 5, it is take almost 1 minute!!

It is take a lot of time to copy the (sb.get(i)) to original_signal[i].

for (int i = 0; i < 1710080; i++) {

     original_signal[i] = (sb.get(i));

}

Please, need help, Thanks!!!

        public static void jjjj(){

            String filepath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ilia.wav";
            Wave wave = new Wave(filepath);
            byte[] arr = wave.getBytes();
            System.out.println();
            wave.length();

            ByteBuffer bb = ByteBuffer.wrap(arr);
            System.out.println(bb.capacity());
            bb.order(ByteOrder.LITTLE_ENDIAN);
            ShortBuffer sb = bb.asShortBuffer();




            original_signal = new double[1710080];
            // double firstSample;

                           //THIS FOR LOOP TAKE A LOF OF TIME

            for (int i = 0; i < 1710080; i++) {

                     original_signal[i] = (sb.get(i));

            }

            System.out.println("sss");



        }

I solved the issue

    Wave wave = new Wave(filepath);

    double[] original_signal = wave.getNormalizedAmplitudes();

    System.out.println(wave.getWaveHeader());
    Parameters.Fs = wave.getWaveHeader().getSampleRate();
    return original_signal;
Florian Brucker
  • 9,621
  • 3
  • 48
  • 81
Android0077
  • 401
  • 1
  • 6
  • 12
  • I am curious. Why 1710080? – Ken Wolf Apr 17 '14 at 08:30
  • It is the FrameLength() in the file, I wrote on this way in order to show you the Length of the frame. – Android0077 Apr 17 '14 at 08:33
  • I guess the convertion from byte array to short arrays is a common problem with Android. Did you check this answer? http://stackoverflow.com/questions/11930385/how-can-i-get-short-from-a-bytebuffer – Wintermute Apr 17 '14 at 09:26
  • Thanks @Wintermute for your replay,I sucssed to convert from byte array to short array - it is take less than 1 sec. The problem is to copy from short array to double array(It is take 40 sec), Do you have any idea? Thanks – Android0077 Apr 17 '14 at 09:51
  • @Android0077: Please post your solution as an answer and accept it so that others see that this question has been solved. – Florian Brucker Apr 17 '14 at 11:46

0 Answers0