<commit_before>//  
// Copyright (C) 2007-2008 SIPfoundry Inc. 
// Licensed by SIPfoundry under the LGPL license. 
//  
// Copyright (C) 2007-2008 SIPez LLC. 
// Licensed to SIPfoundry under a Contributor Agreement. 
//  
// $$ 
////////////////////////////////////////////////////////////////////////////// 

// Author: <NAME> <Alexander DOT Chemeris AT SIPez DOT com>

#ifdef HAVE_SPEEX

// WIN32: Add libspeex to linker input.
#ifdef WIN32 // [
#   pragma comment(lib, "libspeex.lib")
#endif // WIN32 ]

// SYSTEM INCLUDES
#include <assert.h>

// APPLICATION INCLUDES
#include <mp/MpResamplerSpeex.h>
#include <speex/speex_resampler.h>

// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// TYPEDEFS
// DEFINES
// MACROS
// STATIC VARIABLE INITIALIZATIONS

/* //////////////////////////////// PUBLIC //////////////////////////////// */

/* =============================== CREATORS =============================== */

MpResamplerSpeex::MpResamplerSpeex(uint32_t numChannels, 
                                   uint32_t inputRate, uint32_t outputRate, 
                                   int32_t quality)
: MpResamplerBase(numChannels, inputRate, outputRate,
                  quality >= 0 ? quality : SPEEX_RESAMPLER_QUALITY_VOIP)
{
   // Call speex init.
   int speexErr = 0;
   mpState = speex_resampler_init(mNumChannels, mInputRate, mOutputRate, 
                                  mQuality, &speexErr);

   assert(speexErr == RESAMPLER_ERR_SUCCESS);
}

MpResamplerSpeex::~MpResamplerSpeex()
{
   // Destroy speex state object
   speex_resampler_destroy(mpState);
   mpState = NULL;
}

/* ============================= MANIPULATORS ============================= */

OsStatus MpResamplerSpeex::resetStream()
{
   return speexErrToOsStatus(speex_resampler_reset_mem(mpState));
}

// Single-channel resampling.
OsStatus MpResamplerSpeex::resample(uint32_t channelIndex,
                                    const MpAudioSample* pInBuf, uint32_t inBufLength, 
                                    uint32_t& inSamplesProcessed, 
                                    MpAudioSample* pOutBuf, uint32_t outBufLength, 
                                    uint32_t& outSamplesWritten)
{
   OsStatus ret = OS_FAILED;
   if(channelIndex >= mNumChannels)
   {
      // Specified a channel number that was outside the defined number of channels!
      return OS_INVALID_ARGUMENT;
   }

   inSamplesProcessed = inBufLength;
   outSamplesWritten = outBufLength;
   int speexErr = speex_resampler_process_int(mpState, channelIndex, 
                                              pInBuf, &inSamplesProcessed, 
                                              pOutBuf, &outSamplesWritten);
   return speexErrToOsStatus(speexErr);
}

// Interleaved stereo resampling.
OsStatus MpResamplerSpeex::resampleInterleavedStereo(const MpAudioSample* pInBuf, 
                                                     uint32_t inBufLength,
                                                     uint32_t& inSamplesProcessed,
                                                     MpAudioSample* pOutBuf, 
                                                     uint32_t outBufLength,
                                                     uint32_t& outSamplesWritten)
{
   if(mNumChannels != 2)
   {
      // Cannot do interleaved stereo resampling when internal state does not 
      // indicate we have 2 channels.
      return OS_INVALID_STATE;
   }
<commit_msg>Remove unused variable from MpResamplerSpeex.cpp<commit_after>//  
// Copyright (C) 2007-2008 SIPfoundry Inc. 
// Licensed by SIPfoundry under the LGPL license. 
//  
// Copyright (C) 2007-2008 SIPez LLC. 
// Licensed to SIPfoundry under a Contributor Agreement. 
//  
// $$ 
////////////////////////////////////////////////////////////////////////////// 

// Author: <NAME> <<EMAIL>>

#ifdef HAVE_SPEEX

// WIN32: Add libspeex to linker input.
#ifdef WIN32 // [
#   pragma comment(lib, "libspeex.lib")
#endif // WIN32 ]

// SYSTEM INCLUDES
#include <assert.h>

// APPLICATION INCLUDES
#include <mp/MpResamplerSpeex.h>
#include <speex/speex_resampler.h>

// EXTERNAL FUNCTIONS
// EXTERNAL VARIABLES
// CONSTANTS
// TYPEDEFS
// DEFINES
// MACROS
// STATIC VARIABLE INITIALIZATIONS

/* //////////////////////////////// PUBLIC //////////////////////////////// */

/* =============================== CREATORS =============================== */

MpResamplerSpeex::MpResamplerSpeex(uint32_t numChannels, 
                                   uint32_t inputRate, uint32_t outputRate, 
                                   int32_t quality)
: MpResamplerBase(numChannels, inputRate, outputRate,
                  quality >= 0 ? quality : SPEEX_RESAMPLER_QUALITY_VOIP)
{
   // Call speex init.
   int speexErr = 0;
   mpState = speex_resampler_init(mNumChannels, mInputRate, mOutputRate, 
                                  mQuality, &speexErr);

   assert(speexErr == RESAMPLER_ERR_SUCCESS);
}

MpResamplerSpeex::~MpResamplerSpeex()
{
   // Destroy speex state object
   speex_resampler_destroy(mpState);
   mpState = NULL;
}

/* ============================= MANIPULATORS ============================= */

OsStatus MpResamplerSpeex::resetStream()
{
   return speexErrToOsStatus(speex_resampler_reset_mem(mpState));
}

// Single-channel resampling.
OsStatus MpResamplerSpeex::resample(uint32_t channelIndex,
                                    const MpAudioSample* pInBuf, uint32_t inBufLength, 
                                    uint32_t& inSamplesProcessed, 
                                    MpAudioSample* pOutBuf, uint32_t outBufLength, 
                                    uint32_t& outSamplesWritten)
{
   if(channelIndex >= mNumChannels)
   {
      // Specified a channel number that was outside the defined number of channels!
      return OS_INVALID_ARGUMENT;
   }

   inSamplesProcessed = inBufLength;
   outSamplesWritten = outBufLength;
   int speexErr = speex_resampler_process_int(mpState, channelIndex, 
                                              pInBuf, &inSamplesProcessed, 
                                              pOutBuf, &outSamplesWritten);
   return speexErrToOsStatus(speexErr);
}

// Interleaved stereo resampling.
OsStatus MpResamplerSpeex::resampleInterleavedStereo(const MpAudioSample* pInBuf, 
                                                     uint32_t inBufLength,
                                                     uint32_t& inSamplesProcessed,
                                                     MpAudioSample* pOutBuf, 
                                                     uint32_t outBufLength,
                                                     uint32_t& outSamplesWritten)
{
   if(mNumChannels != 2)
   {
      // Cannot do interleaved stereo resampling when internal state does not 
      // indicate we have 2 channels.
      return OS_INVALID_STATE;
   }

{'fraction_non_alphanumeric': 0.14835969537199767, 'fraction_numerical': 0.015231400117164616, 'mean_word_length': 1.7503020539669754, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1998079', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1876, 'n_words': 399}