<commit_before>package cn.jackq.messenger.audio;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.util.Log;

import java.nio.ByteBuffer;

/**
 * Created on: 4/24/17.
 * Creator: <NAME> <<EMAIL>>
 */

public class MessengerAudioOutput {
    private static final String TAG = "MessengerAudioOutput";

    private AudioTrack mTrack;
    private OpusCodec.Decoder mDecoder;

    private int sampleRateInHz = 8000;
    private int channelOutMono = AudioFormat.CHANNEL_OUT_MONO;
    private int encodingPcm16bit = AudioFormat.ENCODING_PCM_16BIT;
    private int minSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelOutMono, encodingPcm16bit);

    private boolean isMuted = true;

    public MessengerAudioOutput() {
    }

    public void init() {
        if (mTrack == null)
            mTrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                    sampleRateInHz, channelOutMono, encodingPcm16bit, minSize, AudioTrack.MODE_STREAM);
        if (mDecoder == null)
            try {
                Log.d(TAG, "init: create decoder");
                mDecoder = new OpusCodec.Decoder(sampleRateInHz, 1);
            } catch (NativeAudioException e) {
                e.printStackTrace();
            }
    }

    public void start() {
        // first clean all of the pending audio data that was recorded during the pause
        mTrack.flush();
        mTrack.play();
        isMuted = false;
    }

    public void bufferPacket(byte[] buffer, int offset, int size) {
        // ignore packet when current mode is muted
        if(isMuted)
            return;

        // use decode short to create 16bit sample
        short[] decoderBuffer = new short[320];
        int decodeSize;
        try {
            Log.d(TAG, "bufferPacket: decode packet of size " + size);
            decodeSize = mDecoder.decodeShort(ByteBuffer.wrap(buffer, offset, size), size, decoderBuffer, 320);
            Log.d(TAG, "bufferPacket: write decoded packet to audio track with size " + decodeSize);
            mTrack.write(decoderBuffer, 0, decodeSize);
        } catch (NativeAudioException e) {
            e.printStackTrace();
        } catch (NullPointerException e){
            Log.e(TAG, "bufferPacket: Threads un-synchronized and null pointer exception occurred", e);
        }
    }

    public void stop() {<commit_msg>remove extra log output<commit_after>package cn.jackq.messenger.audio;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.util.Log;

import java.nio.ByteBuffer;

/**
 * Created on: 4/24/17.
 * Creator: <NAME> <<EMAIL>>
 */

public class MessengerAudioOutput {
    private static final String TAG = "MessengerAudioOutput";

    private AudioTrack mTrack;
    private OpusCodec.Decoder mDecoder;

    private int sampleRateInHz = 8000;
    private int channelOutMono = AudioFormat.CHANNEL_OUT_MONO;
    private int encodingPcm16bit = AudioFormat.ENCODING_PCM_16BIT;
    private int minSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelOutMono, encodingPcm16bit);

    private boolean isMuted = true;

    public MessengerAudioOutput() {
    }

    public void init() {
        if (mTrack == null)
            mTrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                    sampleRateInHz, channelOutMono, encodingPcm16bit, minSize, AudioTrack.MODE_STREAM);
        if (mDecoder == null)
            try {
                Log.d(TAG, "init: create decoder");
                mDecoder = new OpusCodec.Decoder(sampleRateInHz, 1);
            } catch (NativeAudioException e) {
                e.printStackTrace();
            }
    }

    public void start() {
        // first clean all of the pending audio data that was recorded during the pause
        mTrack.flush();
        mTrack.play();
        isMuted = false;
    }

    public void bufferPacket(byte[] buffer, int offset, int size) {
        // ignore packet when current mode is muted
        if(isMuted)
            return;

        // use decode short to create 16bit sample
        short[] decoderBuffer = new short[320];
        int decodeSize;
        try {
            decodeSize = mDecoder.decodeShort(ByteBuffer.wrap(buffer, offset, size), size, decoderBuffer, 320);
            mTrack.write(decoderBuffer, 0, decodeSize);
        } catch (NativeAudioException e) {
            e.printStackTrace();
        } catch (NullPointerException e){
            Log.e(TAG, "bufferPacket: Threads un-synchronized and null pointer exception occurred", e);
        }
    }

    public void stop() {
{'fraction_non_alphanumeric': 0.0901250539025442, 'fraction_numerical': 0.01164294954721863, 'mean_word_length': 2.5466360856269112, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1795528', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1258, 'n_words': 359}