将原始PCM数据转换为double []

时间:2019-04-14 16:41:16

标签: java android audio-recording pcm

我正在尝试使音频录音更生动。我用来将原始PCM数据转换为double []的方法。但是我得到的都是0。

public double[] readPCM()
   {
       double[] result = null;
       try
       {
           File file = new File(ThePCMFile);
           InputStream in = new FileInputStream(file);
           int bufferSize = (int) (file.length()/2);

           result = new double[bufferSize];

           DataInputStream is = new DataInputStream(in);

           for (int i = 0; i < bufferSize; i++) 
           {
               result[i] = is.readShort() / 32768.0;
           }
       }
       catch (IOException e) 
       {
           e.printStackTrace();
       }        
       return result;
   }

0 个答案:

没有答案