Convert G711 alaw or G711 ulaw byte array to audio file [.wav or .au ]

1.1k Views Asked by At

I'm developing an application for recording , so I'm trying to decode trafic rtp using library Jnetpcap . The codec provided have in general two types : G711 alaw or G711 ulaw . I convert the payload and save it as a wav file but i can't listen the voice recorded . I use this code to convert byte array to a wav file :

     byte[] pcm_data= rtp.getPayload();
     pcm_data= new byte[44100*2];
     double L1      = 44100.0/440.0;
     double L2      = 44100.0/455.0;
     for(int i=0;i<pcm_data.length;i++){
        pcm_data[i]=  (byte)(55*Math.sin((i/L1)*Math.PI*2));
        pcm_data[i]+= (byte)(55*Math.sin((i/L2)*Math.PI*2));
        }

     AudioFormat      frmt= new AudioFormat(44100,8,1,true,false);
     AudioInputStream ais = new AudioInputStream(
                new ByteArrayInputStream(pcm_data)
               ,frmt
               ,pcm_data.length);

     AudioSystem.write(
                ais
               ,AudioFileFormat.Type.WAVE
               ,new File("test.wav"));
0

There are 0 best solutions below