Android sound recorder bad performance
===

            //constructor
                android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
            /////////////
            
            //thread run() method
                int N = AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_16BIT);
                AudioRecord recorder = new AudioRecord(AudioSource.MIC, 8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, N*10);
                            recorder.startRecording();
        
        while(!stopped)
                    { 
        	    	try {
                               //if not paused upload audio
        		       if (uploadAudio == true) {
        
        		               short[][] buffers  = new short[256][160];
        		               int ix = 0;
        		                 	
        		            	//allocate buffer for audio data
        		                short[] buffer = buffers[ix++ % buffers.length];
        		                
                                   //write audio data to track
        		               N = recorder.read(buffer,0,buffer.length);
        		                    
        		               //create bytes big enough to hold audio data
        		               byte[] bytes2 = new byte[buffer.length * 2];
        		     
                                       //convert audio data from short[][] to byte[]
    
    ByteBuffer.wrap(bytes2).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(buffer);
        
        
        				    //encode audio data for ulaw
        		                    read(bytes2, 0, bytes2.length);
See [here][1] for ulaw encoder code.  Im using the read, maxAbsPcm and encode methods
        
        		                    //send audio data
        		                    //os.write(bytes2,0,bytes2.length);
        						}
        	            	} finally {
        	    		}
                    }
                    os.close();
                }
                catch(Throwable x)
                { 
                    Log.w("AudioWorker", "Error reading voice AudioWorker", x);
                }
                finally
                { 
                    recorder.stop();
                    recorder.release();
                }
        
            ///////////


So this works ok.  The audio is sent in the proper format to the server and played at the opposite end.  However the audio skips often.  Example: saying 1,2,3,4 will play back with the 4 cut off.  
I believe it to be a performance issue because I have timed some of these methods and when they take 0 or less seconds everything works but they quite often take a couple seconds.  With the converting of bytes and encoding taking the most.  
Any idea how I can optimize this code to get better performance?  Or maybe a way to deal with lag (possibly build a cache)?

  [1]: http://www.devdaily.com/java/jwarehouse/android/core/java/android/speech/srec/UlawEncoderInputStream.java.shtml