<commit_before>/*
 * Copyright © 2014 Mozilla Foundation
 *
 * This program is made available under an ISC-style license.  See the
 * accompanying file LICENSE for details.
 */
#include <cmath>
#include <cassert>
#include <cstring>
#include <cstddef>
#include <cstdio>
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include "cubeb_resampler.h"
#include "cubeb-speex-resampler.h"
#include "cubeb_resampler_internal.h"
#include "cubeb_utils.h"

int
to_speex_quality(cubeb_resampler_quality q)
{
  switch(q) {
  case CUBEB_RESAMPLER_QUALITY_VOIP:
    return SPEEX_RESAMPLER_QUALITY_VOIP;
  case CUBEB_RESAMPLER_QUALITY_DEFAULT:
    return SPEEX_RESAMPLER_QUALITY_DEFAULT;
  case CUBEB_RESAMPLER_QUALITY_DESKTOP:
    return SPEEX_RESAMPLER_QUALITY_DESKTOP;
  default:
    assert(false);
    return 0XFFFFFFFF;
  }
}

template<typename T>
cubeb_resampler_speex_one_way<T>::cubeb_resampler_speex_one_way(uint32_t channels,
                                                                uint32_t source_rate,
                                                                uint32_t target_rate,
                                                                int quality)
  : processor(channels)
  , resampling_ratio(static_cast<float>(source_rate) / target_rate)
  , additional_latency(0)
{
  int r;
  speex_resampler = speex_resampler_init(channels, source_rate,
                                         target_rate, quality, &r);
  assert(r == RESAMPLER_ERR_SUCCESS && "resampler allocation failure");
}

template<typename T>
cubeb_resampler_speex_one_way<T>::~cubeb_resampler_speex_one_way()
{
  speex_resampler_destroy(speex_resampler);
}

long noop_resampler::fill(void * input_buffer, long * input_frames_count,
                          void * output_buffer, long output_frames)
{
  assert(input_buffer && output_buffer &&
         *input_frames_count >= output_frames ||
         !input_buffer && input_frames_count == 0 ||
         !output_buffer && output_frames== 0);

  if (*input_frames_count != output_frames) {
    assert(*input_frames_count > output_frames);
    *input_frames_count = output_frames;
  }

  return data_callback(stream, user_ptr,
                       input_buffer, output_buffer, output_frames);<commit_msg>Make the noop_resampler work in output-only mode, by null-checking the pointers.<commit_after>/*
 * Copyright © 2014 Mozilla Foundation
 *
 * This program is made available under an ISC-style license.  See the
 * accompanying file LICENSE for details.
 */
#include <cmath>
#include <cassert>
#include <cstring>
#include <cstddef>
#include <cstdio>
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include "cubeb_resampler.h"
#include "cubeb-speex-resampler.h"
#include "cubeb_resampler_internal.h"
#include "cubeb_utils.h"

int
to_speex_quality(cubeb_resampler_quality q)
{
  switch(q) {
  case CUBEB_RESAMPLER_QUALITY_VOIP:
    return SPEEX_RESAMPLER_QUALITY_VOIP;
  case CUBEB_RESAMPLER_QUALITY_DEFAULT:
    return SPEEX_RESAMPLER_QUALITY_DEFAULT;
  case CUBEB_RESAMPLER_QUALITY_DESKTOP:
    return SPEEX_RESAMPLER_QUALITY_DESKTOP;
  default:
    assert(false);
    return 0XFFFFFFFF;
  }
}

template<typename T>
cubeb_resampler_speex_one_way<T>::cubeb_resampler_speex_one_way(uint32_t channels,
                                                                uint32_t source_rate,
                                                                uint32_t target_rate,
                                                                int quality)
  : processor(channels)
  , resampling_ratio(static_cast<float>(source_rate) / target_rate)
  , additional_latency(0)
{
  int r;
  speex_resampler = speex_resampler_init(channels, source_rate,
                                         target_rate, quality, &r);
  assert(r == RESAMPLER_ERR_SUCCESS && "resampler allocation failure");
}

template<typename T>
cubeb_resampler_speex_one_way<T>::~cubeb_resampler_speex_one_way()
{
  speex_resampler_destroy(speex_resampler);
}

long noop_resampler::fill(void * input_buffer, long * input_frames_count,
                          void * output_buffer, long output_frames)
{
  assert(input_buffer && output_buffer &&
         *input_frames_count >= output_frames ||
         !input_buffer && !input_frames_count ||
         !output_buffer && output_frames == 0);

  if (output_buffer == nullptr) {
    output_frames = *input_frames_count;
  }

  if (input_buffer && *input_frames_count != output_frames) {
    assert(*input_frames_count > output_frames);
    *input_frames_count = output_frames;
  }

  return data_callback(stream, user_ptr,
                       input_buffer, output_buffer, output_frames);
{'fraction_non_alphanumeric': 0.08562822719449226, 'fraction_numerical': 0.00580895008605852, 'mean_word_length': 3.0320901994796183, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '736578', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1501, 'n_words': 270}