diff options
author | Andrew Comminos <andrewcomminos@gmail.com> | 2014-01-12 05:47:30 +0400 |
---|---|---|
committer | Andrew Comminos <andrewcomminos@gmail.com> | 2014-01-12 05:47:30 +0400 |
commit | b5ac8e75ba933eefb266b9abdb04f08d57659406 (patch) | |
tree | 30fb139934c9daafd346bb7a09843c51190acb9c /src/main/java | |
parent | 541ea5895fffa140ed73a6f067c30e04ca284543 (diff) |
Use large audio output buffer size for smoother playback.
Diffstat (limited to 'src/main/java')
3 files changed, 16 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 10641bb..ce91ecb 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioOutput.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioOutput.java @@ -60,16 +60,20 @@ public class AudioOutput extends ProtocolHandler implements Runnable, AudioOutpu private long mLastPacket; // Time that the last packet was received, in nanoseconds private List<AudioOutputSpeech> mMixBuffer = new ArrayList<AudioOutputSpeech>(); private List<AudioOutputSpeech> mDelBuffer = new ArrayList<AudioOutputSpeech>(); + private Handler mMainHandler; public AudioOutput(JumbleService service) { super(service); + mMainHandler = new Handler(Looper.getMainLooper()); } public void startPlaying(boolean scoEnabled) { if(mRunning) return; - int bufferSize = AudioTrack.getMinBufferSize(Audio.SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) * 2; + 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); mAudioTrack = new AudioTrack(scoEnabled ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC, Audio.SAMPLE_RATE, @@ -212,8 +216,7 @@ public class AudioOutput extends ProtocolHandler implements Runnable, AudioOutpu final User user = getService().getUserHandler().getUser(session); if(user != null && user.getTalkState() != state) { user.setTalkState(state); - Handler handler = new Handler(Looper.getMainLooper()); - handler.post(new Runnable() { + mMainHandler.post(new Runnable() { @Override public void run() { getService().notifyObservers(new JumbleService.ObserverRunnable() { diff --git a/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java b/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java index cea4692..25d6fd0 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioOutputSpeech.java @@ -183,8 +183,8 @@ public class AudioOutputSpeech { // if (avail.get() < want) { // mMissCount++; // if(mMissCount < 20) { -// out.fill(0); -// out.get(mBuffer, mBufferFilled, decodedSamples); +// Arrays.fill(mOut, 0); +// System.arraycopy(mOut, 0, mBuffer, mBufferFilled, decodedSamples); // mBufferFilled += decodedSamples; // continue; // } @@ -313,8 +313,7 @@ public class AudioOutputSpeech { mBufferFilled += decodedSamples; } - if(!nextAlive) - ucFlags = 0xFF; + if(!nextAlive) ucFlags = 0xFF; User.TalkState talkState; switch (ucFlags) { diff --git a/src/main/java/com/morlunk/jumble/net/JumbleConnection.java b/src/main/java/com/morlunk/jumble/net/JumbleConnection.java index 9cfdc8a..96bbe70 100644 --- a/src/main/java/com/morlunk/jumble/net/JumbleConnection.java +++ b/src/main/java/com/morlunk/jumble/net/JumbleConnection.java @@ -41,6 +41,7 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -909,8 +910,6 @@ public class JumbleConnection { while(mConnected) { try { mUDPSocket.receive(packet); - // Decrypt UDP packet using OCB-AES128 - final byte[] decryptedData = mCryptState.decrypt(packet.getData(), packet.getLength()); /* if (decryptedData == null && mCryptState.getLastGoodElapsed() > 5000000 && @@ -921,11 +920,15 @@ public class JumbleConnection { mTCP.sendMessage(csb.build(), JumbleTCPMessageType.CryptSetup); } */ + // Decrypt UDP packet using OCB-AES128 + final byte[] data = packet.getData(); + final int length = packet.getLength(); + final byte[] decryptedData = mCryptState.decrypt(data, length); + mMainHandler.post(new Runnable() { @Override public void run() { - if(decryptedData != null) - handleUDPMessage(decryptedData); + if (decryptedData != null) handleUDPMessage(decryptedData); } }); } catch (IOException e) { |