<commit_before>/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "modules/audio_coding/codecs/opus/interface/opus_interface.h"

#include <stdlib.h>
#include <string.h>

#include "opus.h"

#include "common_audio/signal_processing/resample_by_2_internal.h"
#include "common_audio/signal_processing/include/signal_processing_library.h"

enum {
  /* We always produce 20ms frames. */
  kWebRtcOpusMaxEncodeFrameSizeMs = 20,

  /* The format allows up to 120ms frames. Since we
   * don't control the other side, we must allow
   * for packets that large. NetEq is currently
   * limited to 60 ms on the receive side.
   */
  kWebRtcOpusMaxDecodeFrameSizeMs = 120,

  /* Sample count is 48 kHz * samples per frame * stereo. */
  kWebRtcOpusMaxFrameSize = 48 * kWebRtcOpusMaxDecodeFrameSizeMs * 2,
};

struct WebRtcOpusEncInst {
  OpusEncoder* encoder;
};

int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst, int32_t channels) {
  OpusEncInst* state;
  state = (OpusEncInst*) calloc(1, sizeof(OpusEncInst));
  if (state) {
    int error;
    state->encoder = opus_encoder_create(48000, channels, OPUS_APPLICATION_VOIP,
                                         &error);
    if (error == OPUS_OK || state->encoder != NULL ) {
      *inst = state;
      return 0;
    }
    free(state);
  }
  return -1;
}

int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst) {
  opus_encoder_destroy(inst->encoder);
  free(inst);
  return 0;<commit_msg>Adding AUDIO application as default for Opus stereo<commit_after>/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "modules/audio_coding/codecs/opus/interface/opus_interface.h"

#include <stdlib.h>
#include <string.h>

#include "opus.h"

#include "common_audio/signal_processing/resample_by_2_internal.h"
#include "common_audio/signal_processing/include/signal_processing_library.h"

enum {
  /* We always produce 20ms frames. */
  kWebRtcOpusMaxEncodeFrameSizeMs = 20,

  /* The format allows up to 120ms frames. Since we
   * don't control the other side, we must allow
   * for packets that large. NetEq is currently
   * limited to 60 ms on the receive side.
   */
  kWebRtcOpusMaxDecodeFrameSizeMs = 120,

  /* Sample count is 48 kHz * samples per frame * stereo. */
  kWebRtcOpusMaxFrameSize = 48 * kWebRtcOpusMaxDecodeFrameSizeMs * 2,
};

struct WebRtcOpusEncInst {
  OpusEncoder* encoder;
};

int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst, int32_t channels) {
  OpusEncInst* state;
  state = (OpusEncInst*) calloc(1, sizeof(OpusEncInst));
  if (state) {
    int error;
    // Default to VoIP application for mono, and AUDIO for stereo.
    int application = (channels == 1) ?
        OPUS_APPLICATION_VOIP : OPUS_APPLICATION_AUDIO;

    state->encoder = opus_encoder_create(48000, channels, application, &error);
    if (error == OPUS_OK || state->encoder != NULL ) {
      *inst = state;
      return 0;
    }
    free(state);
  }
  return -1;
}

int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst) {
  opus_encoder_destroy(inst->encoder);
  free(inst);
  return 0;
{'fraction_non_alphanumeric': 0.09064249533457745, 'fraction_numerical': 0.01999466808850973, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5625690', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1198, 'n_words': 378}