diff options
author | Andrew Comminos <andrewcomminos@gmail.com> | 2014-01-28 07:17:33 +0400 |
---|---|---|
committer | Andrew Comminos <andrewcomminos@gmail.com> | 2014-01-28 07:17:33 +0400 |
commit | 4d39c8409fdf2868cf669c7d2d0273576cc99477 (patch) | |
tree | bae07c23e22d9414b1b57ae4caa90f4d2d4f8210 /src/main/java | |
parent | 61d32f5d49978169452214944892600be8d46d07 (diff) |
Be less demanding on the audio output user instance, reducing gaps in
speech.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/morlunk/jumble/audio/AudioOutput.java | 10 | ||||
-rw-r--r-- | src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java | 14 |
2 files changed, 13 insertions, 11 deletions
diff --git a/src/main/java/com/morlunk/jumble/audio/AudioOutput.java b/src/main/java/com/morlunk/jumble/audio/AudioOutput.java index 7855cdc..578d7ca 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioOutput.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioOutput.java @@ -51,6 +51,7 @@ public class AudioOutput extends ProtocolHandler implements Runnable, AudioOutpu private ConcurrentHashMap<Integer, AudioOutputSpeech> mAudioOutputs = new ConcurrentHashMap<Integer, AudioOutputSpeech>(); private AudioTrack mAudioTrack; + private int mBufferSize; private Thread mThread; private Object mInactiveLock = new Object(); // Lock that the audio thread waits on when there's no audio to play. Wake when we get a frame. private boolean mRunning = false; @@ -69,14 +70,15 @@ public class AudioOutput extends ProtocolHandler implements Runnable, AudioOutpu return; int minBufferSize = AudioTrack.getMinBufferSize(Audio.SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT); - int bufferSize = Math.max(minBufferSize, Audio.FRAME_SIZE * 12 * 2); // Make the buffer size a multiple of the largest possible frame. - Log.v(Constants.TAG, "Using buffer size "+bufferSize+", system's min buffer size: "+minBufferSize); + mBufferSize = minBufferSize; +// mBufferSize = Math.max(minBufferSize, Audio.FRAME_SIZE * 12); // Make the buffer size a multiple of the largest possible frame. + Log.v(Constants.TAG, "Using buffer size "+mBufferSize+", system's min buffer size: "+minBufferSize); mAudioTrack = new AudioTrack(scoEnabled ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC, Audio.SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, - bufferSize, + mBufferSize, AudioTrack.MODE_STREAM); mThread = new Thread(this); @@ -116,7 +118,7 @@ public class AudioOutput extends ProtocolHandler implements Runnable, AudioOutpu mRunning = true; mAudioTrack.play(); - final short[] mix = new short[Audio.FRAME_SIZE*12]; + final short[] mix = new short[Audio.FRAME_SIZE]; while(mRunning) { Arrays.fill(mix, (short)0); diff --git a/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java b/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java index 0f2cd13..beedaf6 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java @@ -46,6 +46,7 @@ public class AudioOutputSpeech { private Speex.SpeexBits mSpeexBits; private Pointer mSpeexDecoder; private Speex.JitterBuffer mJitterBuffer; + private final Object mJitterLock = new Object(); private int mSession; private JumbleUDPMessageType mCodec; @@ -139,10 +140,9 @@ public class AudioOutputSpeech { if(pds.isValid()) { Speex.JitterBufferPacket packet = new Speex.JitterBufferPacket(data, data.length, Audio.FRAME_SIZE * seq, samples, 0); - synchronized (mJitterBuffer) { + synchronized (mJitterLock) { mJitterBuffer.put(packet); } - packet.deallocate(); } } @@ -168,7 +168,7 @@ public class AudioOutputSpeech { avail.put(0); int ts; - synchronized (mJitterBuffer) { + synchronized (mJitterLock) { ts = mJitterBuffer.getPointerTimestamp(); mJitterBuffer.control(Speex.JitterBuffer.JITTER_BUFFER_GET_AVAILABLE_COUNT, avail); } @@ -191,7 +191,7 @@ public class AudioOutputSpeech { Speex.JitterBufferPacket jbp = new Speex.JitterBufferPacket(null, 4096, 0, 0, 0); int result; - synchronized (mJitterBuffer) { + synchronized (mJitterLock) { result = mJitterBuffer.get(jbp, null); } @@ -228,7 +228,7 @@ public class AudioOutputSpeech { mAverageAvailable *= 0.99f; } else { - synchronized (mJitterBuffer) { + synchronized (mJitterLock) { mJitterBuffer.updateDelay(jbp, null); } @@ -267,7 +267,7 @@ public class AudioOutputSpeech { } if(mFrames.isEmpty()) - synchronized (mJitterBuffer) { + synchronized (mJitterLock) { mJitterBuffer.updateDelay(null, new IntPointer(1)); } @@ -297,7 +297,7 @@ public class AudioOutputSpeech { } } - synchronized (mJitterBuffer) { + synchronized (mJitterLock) { for(int i = decodedSamples / Audio.FRAME_SIZE; i > 0; i--) mJitterBuffer.tick(); } |