Try doing the AudioTrack write in another thread that doesn't have to wait 
on the audio processing.  I'm thinking producer/consumer kind of 
relationship.  That way, the producer can be making more audio for the 
consumer to write without having to wait on the write to complete.  I've 
solved problems this way before when having to deal with larger buffers of 
audio.

Doug

On Friday, April 27, 2012 2:25:14 AM UTC-7, piezo wrote:
>
> Hello 
>
>
> I have a music (sequencer/synth) app in Android Market. One of its 
> strengths is that it uses very little resources and plays smoothly 
> even on the oldest and cheapest devices and only requires Android 
> version 1.6. 
>
> However, since the arrival of ICS, I get more and more complaints 
> about stuttering playback and a sluggish interface, mainly on Galaxy 
> Nexus. The app hasn't changed and still works fine on earlier versions 
> of Android. 
>
> I wonder what may have changed. 
>
> My app does the audio processing in native code and I suspect the way 
> data are passed between java and native might be the problem (I still 
> use AudioTrack to maintain 1.6 compatibility and because it always 
> worked fine): 
>
> public class PlayThread extends Thread 
> { 
>         public void run() 
>         { 
>                 ByteBuffer byteBuffer = 
> ByteBuffer.allocateDirect(minSize); 
>                 byte[] byteArray = new byte[minSize]; 
>
>          
> android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
>  
>
>                 int minSize =AudioTrack.getMinBufferSize( 44100, 
> AudioFormat.CHANNEL_CONFIGURATION_STEREO, 
> AudioFormat.ENCODING_PCM_16BIT ); 
>                       myTrack = new AudioTrack( AudioManager.STREAM_MUSIC, 
> 44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO, 
>                                         AudioFormat.ENCODING_PCM_16BIT, 
> minSize, AudioTrack.MODE_STREAM); 
>
>                 myTrack.play(); 
>
>                 while(1) 
>                 { 
>                         byteBuffer.position(0); 
>                         processNativeAudio(byteBuffer, minSize); 
>                         byteBuffer.position(0); 
>                         byteBuffer.get(byteArray, 0, minSize); 
>                         myTrack.write( puff, 0, minSize ); 
>                 } 
>         } 
> } 
>
> In the main activity, a new PlayThread is created on startup. The 
> native function looks like this: 
>
> void Java_com_myapp_ processNativeAudio( JNIEnv *  env, jobject this, 
> jobject buffer , jint buflng) 
> { 
>         jbyte *jbuffer = (*env)->GetDirectBufferAddress(env, buffer); 
>         short *shortBuffer= (short*)(jbuffer); 
>
>         // processing audio here and writing to shortBuffer 
> } 
>
>
> Anyone has similar problems or even knows a workaround? 
>
> Thank you.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to