Asterisk - The Open Source Telephony Project  18.5.0
Macros | Typedefs | Enumerations | Functions
speex_resampler.h File Reference
#include "speex/speex_types.h"
Include dependency graph for speex_resampler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SPEEX_RESAMPLER_QUALITY_DEFAULT   4
 
#define SPEEX_RESAMPLER_QUALITY_DESKTOP   5
 
#define SPEEX_RESAMPLER_QUALITY_MAX   10
 
#define SPEEX_RESAMPLER_QUALITY_MIN   0
 
#define SPEEX_RESAMPLER_QUALITY_VOIP   3
 

Typedefs

typedef struct SpeexResamplerState_ SpeexResamplerState
 

Enumerations

enum  {
  RESAMPLER_ERR_SUCCESS = 0, RESAMPLER_ERR_ALLOC_FAILED = 1, RESAMPLER_ERR_BAD_STATE = 2, RESAMPLER_ERR_INVALID_ARG = 3,
  RESAMPLER_ERR_PTR_OVERLAP = 4, RESAMPLER_ERR_MAX_ERROR
}
 

Functions

void speex_resampler_destroy (SpeexResamplerState *st)
 
int speex_resampler_get_input_latency (SpeexResamplerState *st)
 
void speex_resampler_get_input_stride (SpeexResamplerState *st, spx_uint32_t *stride)
 
int speex_resampler_get_output_latency (SpeexResamplerState *st)
 
void speex_resampler_get_output_stride (SpeexResamplerState *st, spx_uint32_t *stride)
 
void speex_resampler_get_quality (SpeexResamplerState *st, int *quality)
 
void speex_resampler_get_rate (SpeexResamplerState *st, spx_uint32_t *in_rate, spx_uint32_t *out_rate)
 
void speex_resampler_get_ratio (SpeexResamplerState *st, spx_uint32_t *ratio_num, spx_uint32_t *ratio_den)
 
SpeexResamplerStatespeex_resampler_init (spx_uint32_t nb_channels, spx_uint32_t in_rate, spx_uint32_t out_rate, int quality, int *err)
 Create a new resampler with integer input and output rates. More...
 
SpeexResamplerStatespeex_resampler_init_frac (spx_uint32_t nb_channels, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate, int quality, int *err)
 
int speex_resampler_process_float (SpeexResamplerState *st, spx_uint32_t channel_index, const float *in, spx_uint32_t *in_len, float *out, spx_uint32_t *out_len)
 
int speex_resampler_process_int (SpeexResamplerState *st, spx_uint32_t channel_index, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, spx_uint32_t *out_len)
 
int speex_resampler_process_interleaved_float (SpeexResamplerState *st, const float *in, spx_uint32_t *in_len, float *out, spx_uint32_t *out_len)
 
int speex_resampler_process_interleaved_int (SpeexResamplerState *st, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, spx_uint32_t *out_len)
 
int speex_resampler_reset_mem (SpeexResamplerState *st)
 
void speex_resampler_set_input_stride (SpeexResamplerState *st, spx_uint32_t stride)
 
void speex_resampler_set_output_stride (SpeexResamplerState *st, spx_uint32_t stride)
 
int speex_resampler_set_quality (SpeexResamplerState *st, int quality)
 
int speex_resampler_set_rate (SpeexResamplerState *st, spx_uint32_t in_rate, spx_uint32_t out_rate)
 
int speex_resampler_set_rate_frac (SpeexResamplerState *st, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate)
 
int speex_resampler_skip_zeros (SpeexResamplerState *st)
 
const char * speex_resampler_strerror (int err)
 

Macro Definition Documentation

◆ SPEEX_RESAMPLER_QUALITY_DEFAULT

#define SPEEX_RESAMPLER_QUALITY_DEFAULT   4

Definition at line 97 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_DESKTOP

#define SPEEX_RESAMPLER_QUALITY_DESKTOP   5

Definition at line 99 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_MAX

#define SPEEX_RESAMPLER_QUALITY_MAX   10

Definition at line 95 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_MIN

#define SPEEX_RESAMPLER_QUALITY_MIN   0

Definition at line 96 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_VOIP

#define SPEEX_RESAMPLER_QUALITY_VOIP   3

Definition at line 98 of file speex_resampler.h.

Typedef Documentation

◆ SpeexResamplerState

Definition at line 112 of file speex_resampler.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RESAMPLER_ERR_SUCCESS 
RESAMPLER_ERR_ALLOC_FAILED 
RESAMPLER_ERR_BAD_STATE 
RESAMPLER_ERR_INVALID_ARG 
RESAMPLER_ERR_PTR_OVERLAP 
RESAMPLER_ERR_MAX_ERROR 

Definition at line 101 of file speex_resampler.h.

Function Documentation

◆ speex_resampler_destroy()

void speex_resampler_destroy ( SpeexResamplerState st)

Destroy a resampler state.

Parameters
stResampler state

Definition at line 849 of file resample.c.

References SpeexResamplerState_::last_sample, SpeexResamplerState_::magic_samples, SpeexResamplerState_::mem, SpeexResamplerState_::samp_frac_num, and SpeexResamplerState_::sinc_table.

Referenced by resamp_destroy(), and speex_resampler_init_frac().

850 {
851  speex_free(st->mem);
852  speex_free(st->sinc_table);
853  speex_free(st->last_sample);
854  speex_free(st->magic_samples);
855  speex_free(st->samp_frac_num);
856  speex_free(st);
857 }
spx_uint32_t * samp_frac_num
Definition: resample.c:136
spx_word16_t * mem
Definition: resample.c:139
spx_int32_t * last_sample
Definition: resample.c:135
spx_word16_t * sinc_table
Definition: resample.c:140
spx_uint32_t * magic_samples
Definition: resample.c:137

◆ speex_resampler_get_input_latency()

int speex_resampler_get_input_latency ( SpeexResamplerState st)

Get the latency in input samples introduced by the resampler.

Parameters
stResampler state

Definition at line 1159 of file resample.c.

References SpeexResamplerState_::filt_len.

1160 {
1161  return st->filt_len / 2;
1162 }
spx_uint32_t filt_len
Definition: resample.c:124

◆ speex_resampler_get_input_stride()

void speex_resampler_get_input_stride ( SpeexResamplerState st,
spx_uint32_t *  stride 
)

Get the input stride.

Parameters
stResampler state
strideInput stride copied

Definition at line 1144 of file resample.c.

References SpeexResamplerState_::in_stride.

1145 {
1146  *stride = st->in_stride;
1147 }

◆ speex_resampler_get_output_latency()

int speex_resampler_get_output_latency ( SpeexResamplerState st)

Get the latency in output samples introduced by the resampler.

Parameters
stResampler state

Definition at line 1164 of file resample.c.

References SpeexResamplerState_::den_rate, SpeexResamplerState_::filt_len, and SpeexResamplerState_::num_rate.

1165 {
1166  return ((st->filt_len / 2) * st->den_rate + (st->num_rate >> 1)) / st->num_rate;
1167 }
spx_uint32_t filt_len
Definition: resample.c:124
spx_uint32_t num_rate
Definition: resample.c:119
spx_uint32_t den_rate
Definition: resample.c:120

◆ speex_resampler_get_output_stride()

void speex_resampler_get_output_stride ( SpeexResamplerState st,
spx_uint32_t *  stride 
)

Get the output stride.

Parameters
stResampler state copied
strideOutput stride

Definition at line 1154 of file resample.c.

References SpeexResamplerState_::out_stride.

1155 {
1156  *stride = st->out_stride;
1157 }

◆ speex_resampler_get_quality()

void speex_resampler_get_quality ( SpeexResamplerState st,
int *  quality 
)

Get the conversion quality.

Parameters
stResampler state
qualityResampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality.

Definition at line 1134 of file resample.c.

References SpeexResamplerState_::quality.

1135 {
1136  *quality = st->quality;
1137 }
static int quality
Definition: codec_speex.c:62

◆ speex_resampler_get_rate()

void speex_resampler_get_rate ( SpeexResamplerState st,
spx_uint32_t *  in_rate,
spx_uint32_t *  out_rate 
)

Get the current input/output sampling rates (integer value).

Parameters
stResampler state
in_rateInput sampling rate (integer number of Hz) copied.
out_rateOutput sampling rate (integer number of Hz) copied.

Definition at line 1071 of file resample.c.

References SpeexResamplerState_::in_rate, and SpeexResamplerState_::out_rate.

1072 {
1073  *in_rate = st->in_rate;
1074  *out_rate = st->out_rate;
1075 }
spx_uint32_t in_rate
Definition: resample.c:117
spx_uint32_t out_rate
Definition: resample.c:118

◆ speex_resampler_get_ratio()

void speex_resampler_get_ratio ( SpeexResamplerState st,
spx_uint32_t *  ratio_num,
spx_uint32_t *  ratio_den 
)

Get the current resampling ratio. This will be reduced to the least common denominator.

Parameters
stResampler state
ratio_numNumerator of the sampling rate ratio copied
ratio_denDenominator of the sampling rate ratio copied

Definition at line 1116 of file resample.c.

References SpeexResamplerState_::den_rate, and SpeexResamplerState_::num_rate.

1117 {
1118  *ratio_num = st->num_rate;
1119  *ratio_den = st->den_rate;
1120 }
spx_uint32_t num_rate
Definition: resample.c:119
spx_uint32_t den_rate
Definition: resample.c:120

◆ speex_resampler_init()

SpeexResamplerState* speex_resampler_init ( spx_uint32_t  nb_channels,
spx_uint32_t  in_rate,
spx_uint32_t  out_rate,
int  quality,
int *  err 
)

Create a new resampler with integer input and output rates.

Parameters
nb_channelsNumber of channels to be processed
in_rateInput sampling rate (integer number of Hz).
out_rateOutput sampling rate (integer number of Hz).
qualityResampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality.
err
Returns
Newly created resampler state
Return values
NULLError: not enough memory

Definition at line 783 of file resample.c.

References speex_resampler_init_frac().

Referenced by resamp_new().

784 {
785  return speex_resampler_init_frac(nb_channels, in_rate, out_rate, in_rate, out_rate, quality, err);
786 }
static int quality
Definition: codec_speex.c:62
EXPORT SpeexResamplerState * speex_resampler_init_frac(spx_uint32_t nb_channels, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate, int quality, int *err)
Definition: resample.c:788

◆ speex_resampler_init_frac()

SpeexResamplerState* speex_resampler_init_frac ( spx_uint32_t  nb_channels,
spx_uint32_t  ratio_num,
spx_uint32_t  ratio_den,
spx_uint32_t  in_rate,
spx_uint32_t  out_rate,
int  quality,
int *  err 
)

Create a new resampler with fractional input/output rates. The sampling rate ratio is an arbitrary rational number with both the numerator and denominator being 32-bit integers.

Parameters
nb_channelsNumber of channels to be processed
ratio_numNumerator of the sampling rate ratio
ratio_denDenominator of the sampling rate ratio
in_rateInput sampling rate rounded to the nearest integer (in Hz).
out_rateOutput sampling rate rounded to the nearest integer (in Hz).
qualityResampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality.
err
Returns
Newly created resampler state
Return values
NULLError: not enough memory

Definition at line 788 of file resample.c.

References SpeexResamplerState_::buffer_size, SpeexResamplerState_::cutoff, SpeexResamplerState_::den_rate, SpeexResamplerState_::filt_len, SpeexResamplerState_::in_rate, SpeexResamplerState_::in_stride, SpeexResamplerState_::initialised, SpeexResamplerState_::last_sample, SpeexResamplerState_::magic_samples, SpeexResamplerState_::mem, SpeexResamplerState_::mem_alloc_size, SpeexResamplerState_::nb_channels, NULL, SpeexResamplerState_::num_rate, SpeexResamplerState_::out_rate, SpeexResamplerState_::out_stride, SpeexResamplerState_::quality, RESAMPLER_ERR_INVALID_ARG, RESAMPLER_ERR_SUCCESS, SpeexResamplerState_::resampler_ptr, SpeexResamplerState_::samp_frac_num, SpeexResamplerState_::sinc_table_length, speex_resampler_destroy(), speex_resampler_set_quality(), speex_resampler_set_rate_frac(), SpeexResamplerState_::started, and update_filter().

Referenced by speex_resampler_init().

789 {
790  spx_uint32_t i;
792  int filter_err;
793 
794  if (quality > 10 || quality < 0)
795  {
796  if (err)
798  return NULL;
799  }
800  st = (SpeexResamplerState *)speex_alloc(sizeof(SpeexResamplerState));
801  st->initialised = 0;
802  st->started = 0;
803  st->in_rate = 0;
804  st->out_rate = 0;
805  st->num_rate = 0;
806  st->den_rate = 0;
807  st->quality = -1;
808  st->sinc_table_length = 0;
809  st->mem_alloc_size = 0;
810  st->filt_len = 0;
811  st->mem = 0;
812  st->resampler_ptr = 0;
813 
814  st->cutoff = 1.f;
815  st->nb_channels = nb_channels;
816  st->in_stride = 1;
817  st->out_stride = 1;
818 
819  st->buffer_size = 160;
820 
821  /* Per channel data */
822  st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t));
823  st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
824  st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
825  for (i=0;i<nb_channels;i++)
826  {
827  st->last_sample[i] = 0;
828  st->magic_samples[i] = 0;
829  st->samp_frac_num[i] = 0;
830  }
831 
833  speex_resampler_set_rate_frac(st, ratio_num, ratio_den, in_rate, out_rate);
834 
835  filter_err = update_filter(st);
836  if (filter_err == RESAMPLER_ERR_SUCCESS)
837  {
838  st->initialised = 1;
839  } else {
841  st = NULL;
842  }
843  if (err)
844  *err = filter_err;
845 
846  return st;
847 }
spx_uint32_t filt_len
Definition: resample.c:124
spx_uint32_t * samp_frac_num
Definition: resample.c:136
static int quality
Definition: codec_speex.c:62
EXPORT int speex_resampler_set_quality(SpeexResamplerState *st, int quality)
Definition: resample.c:1122
static int update_filter(SpeexResamplerState *st)
Definition: resample.c:594
#define NULL
Definition: resample.c:96
spx_uint32_t buffer_size
Definition: resample.c:126
spx_uint32_t nb_channels
Definition: resample.c:123
resampler_basic_func resampler_ptr
Definition: resample.c:142
spx_word16_t * mem
Definition: resample.c:139
spx_uint32_t in_rate
Definition: resample.c:117
spx_int32_t * last_sample
Definition: resample.c:135
spx_uint32_t out_rate
Definition: resample.c:118
spx_uint32_t mem_alloc_size
Definition: resample.c:125
spx_uint32_t * magic_samples
Definition: resample.c:137
spx_uint32_t sinc_table_length
Definition: resample.c:141
spx_uint32_t num_rate
Definition: resample.c:119
EXPORT void speex_resampler_destroy(SpeexResamplerState *st)
Definition: resample.c:849
EXPORT int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate)
Definition: resample.c:1077
spx_uint32_t den_rate
Definition: resample.c:120

◆ speex_resampler_process_float()

int speex_resampler_process_float ( SpeexResamplerState st,
spx_uint32_t  channel_index,
const float *  in,
spx_uint32_t *  in_len,
float *  out,
spx_uint32_t *  out_len 
)

Resample a float array. The input and output buffers must not overlap.

Parameters
stResampler state
channel_indexIndex of the channel to process for the multi-channel base (0 otherwise)
inInput buffer
in_lenNumber of input samples in the input buffer. Returns the number of samples processed
outOutput buffer
out_lenSize of the output buffer. Returns the number of samples written

Definition at line 947 of file resample.c.

References ALLOC, SpeexResamplerState_::filt_len, FIXED_POINT, FIXED_STACK_ALLOC, SpeexResamplerState_::in_stride, SpeexResamplerState_::magic_samples, SpeexResamplerState_::mem, SpeexResamplerState_::mem_alloc_size, SpeexResamplerState_::out_stride, resampler_basic_zero(), RESAMPLER_ERR_ALLOC_FAILED, RESAMPLER_ERR_SUCCESS, SpeexResamplerState_::resampler_ptr, speex_resampler_magic(), speex_resampler_process_native(), VARDECL, and WORD2INT.

Referenced by speex_resampler_process_interleaved_float().

951 {
952  int j;
953  const int istride_save = st->in_stride;
954  const int ostride_save = st->out_stride;
955  spx_uint32_t ilen = *in_len;
956  spx_uint32_t olen = *out_len;
957  spx_word16_t *x = st->mem + channel_index * st->mem_alloc_size;
958  const spx_uint32_t xlen = st->mem_alloc_size - (st->filt_len - 1);
959 #ifdef VAR_ARRAYS
960  const unsigned int ylen = (olen < FIXED_STACK_ALLOC) ? olen : FIXED_STACK_ALLOC;
961  VARDECL(spx_word16_t *ystack);
962  ALLOC(ystack, ylen, spx_word16_t);
963 #else
964  const unsigned int ylen = FIXED_STACK_ALLOC;
966 #endif
967 
968  st->out_stride = 1;
969 
970  while (ilen && olen) {
971  spx_word16_t *y = ystack;
972  spx_uint32_t ichunk = (ilen > xlen) ? xlen : ilen;
973  spx_uint32_t ochunk = (olen > ylen) ? ylen : olen;
974  spx_uint32_t omagic = 0;
975 
976  if (st->magic_samples[channel_index]) {
977  omagic = speex_resampler_magic(st, channel_index, &y, ochunk);
978  ochunk -= omagic;
979  olen -= omagic;
980  }
981  if (! st->magic_samples[channel_index]) {
982  if (in) {
983  for(j=0;j<ichunk;++j)
984 #ifdef FIXED_POINT
985  x[j+st->filt_len-1]=WORD2INT(in[j*istride_save]);
986 #else
987  x[j+st->filt_len-1]=in[j*istride_save];
988 #endif
989  } else {
990  for(j=0;j<ichunk;++j)
991  x[j+st->filt_len-1]=0;
992  }
993 
994  speex_resampler_process_native(st, channel_index, &ichunk, y, &ochunk);
995  } else {
996  ichunk = 0;
997  ochunk = 0;
998  }
999 
1000  for (j=0;j<ochunk+omagic;++j)
1001 #ifdef FIXED_POINT
1002  out[j*ostride_save] = ystack[j];
1003 #else
1004  out[j*ostride_save] = WORD2INT(ystack[j]);
1005 #endif
1006 
1007  ilen -= ichunk;
1008  olen -= ochunk;
1009  out += (ochunk+omagic) * ostride_save;
1010  if (in)
1011  in += ichunk * istride_save;
1012  }
1013  st->out_stride = ostride_save;
1014  *in_len -= ilen;
1015  *out_len -= olen;
1016 
1018 }
#define FIXED_STACK_ALLOC
Definition: resample.c:111
spx_uint32_t filt_len
Definition: resample.c:124
resampler_basic_func resampler_ptr
Definition: resample.c:142
static int speex_resampler_magic(SpeexResamplerState *st, spx_uint32_t channel_index, spx_word16_t **out, spx_uint32_t out_len)
Definition: resample.c:885
spx_word16_t * mem
Definition: resample.c:139
FILE * in
Definition: utils/frame.c:33
#define ALLOC(var, size, type)
Definition: stack_alloc.h:111
spx_uint32_t mem_alloc_size
Definition: resample.c:125
spx_uint32_t * magic_samples
Definition: resample.c:137
#define FIXED_POINT
Definition: arch.h:38
spx_int16_t spx_word16_t
Definition: arch.h:85
#define VARDECL(var)
Definition: stack_alloc.h:110
#define WORD2INT(x)
Definition: resample.c:87
static int speex_resampler_process_native(SpeexResamplerState *st, spx_uint32_t channel_index, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
Definition: resample.c:859
FILE * out
Definition: utils/frame.c:33
static int resampler_basic_zero(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
Definition: resample.c:567

◆ speex_resampler_process_int()

int speex_resampler_process_int ( SpeexResamplerState st,
spx_uint32_t  channel_index,
const spx_int16_t *  in,
spx_uint32_t *  in_len,
spx_int16_t *  out,
spx_uint32_t *  out_len 
)

Resample an int array. The input and output buffers must not overlap.

Parameters
stResampler state
channel_indexIndex of the channel to process for the multi-channel base (0 otherwise)
inInput buffer
in_lenNumber of input samples in the input buffer. Returns the number of samples processed
outOutput buffer
out_lenSize of the output buffer. Returns the number of samples written

Definition at line 906 of file resample.c.

References SpeexResamplerState_::filt_len, SpeexResamplerState_::in_stride, SpeexResamplerState_::magic_samples, SpeexResamplerState_::mem, SpeexResamplerState_::mem_alloc_size, SpeexResamplerState_::out_stride, resampler_basic_zero(), RESAMPLER_ERR_ALLOC_FAILED, RESAMPLER_ERR_SUCCESS, SpeexResamplerState_::resampler_ptr, speex_resampler_magic(), and speex_resampler_process_native().

Referenced by resamp_framein(), and speex_resampler_process_interleaved_int().

910 {
911  int j;
912  spx_uint32_t ilen = *in_len;
913  spx_uint32_t olen = *out_len;
914  spx_word16_t *x = st->mem + channel_index * st->mem_alloc_size;
915  const int filt_offs = st->filt_len - 1;
916  const spx_uint32_t xlen = st->mem_alloc_size - filt_offs;
917  const int istride = st->in_stride;
918 
919  if (st->magic_samples[channel_index])
920  olen -= speex_resampler_magic(st, channel_index, &out, olen);
921  if (! st->magic_samples[channel_index]) {
922  while (ilen && olen) {
923  spx_uint32_t ichunk = (ilen > xlen) ? xlen : ilen;
924  spx_uint32_t ochunk = olen;
925 
926  if (in) {
927  for(j=0;j<ichunk;++j)
928  x[j+filt_offs]=in[j*istride];
929  } else {
930  for(j=0;j<ichunk;++j)
931  x[j+filt_offs]=0;
932  }
933  speex_resampler_process_native(st, channel_index, &ichunk, out, &ochunk);
934  ilen -= ichunk;
935  olen -= ochunk;
936  out += ochunk * st->out_stride;
937  if (in)
938  in += ichunk * istride;
939  }
940  }
941  *in_len -= ilen;
942  *out_len -= olen;
944 }
spx_uint32_t filt_len
Definition: resample.c:124
resampler_basic_func resampler_ptr
Definition: resample.c:142
static int speex_resampler_magic(SpeexResamplerState *st, spx_uint32_t channel_index, spx_word16_t **out, spx_uint32_t out_len)
Definition: resample.c:885
spx_word16_t * mem
Definition: resample.c:139
FILE * in
Definition: utils/frame.c:33
spx_uint32_t mem_alloc_size
Definition: resample.c:125
spx_uint32_t * magic_samples
Definition: resample.c:137
spx_int16_t spx_word16_t
Definition: arch.h:85
static int speex_resampler_process_native(SpeexResamplerState *st, spx_uint32_t channel_index, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
Definition: resample.c:859
FILE * out
Definition: utils/frame.c:33
static int resampler_basic_zero(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
Definition: resample.c:567

◆ speex_resampler_process_interleaved_float()

int speex_resampler_process_interleaved_float ( SpeexResamplerState st,
const float *  in,
spx_uint32_t *  in_len,
float *  out,
spx_uint32_t *  out_len 
)

Resample an interleaved float array. The input and output buffers must not overlap.

Parameters
stResampler state
inInput buffer
in_lenNumber of input samples in the input buffer. Returns the number of samples processed. This is all per-channel.
outOutput buffer
out_lenSize of the output buffer. Returns the number of samples written. This is all per-channel.

Definition at line 1020 of file resample.c.

References SpeexResamplerState_::in_stride, SpeexResamplerState_::nb_channels, NULL, SpeexResamplerState_::out_stride, resampler_basic_zero(), RESAMPLER_ERR_ALLOC_FAILED, RESAMPLER_ERR_SUCCESS, SpeexResamplerState_::resampler_ptr, and speex_resampler_process_float().

1021 {
1022  spx_uint32_t i;
1023  int istride_save, ostride_save;
1024  spx_uint32_t bak_out_len = *out_len;
1025  spx_uint32_t bak_in_len = *in_len;
1026  istride_save = st->in_stride;
1027  ostride_save = st->out_stride;
1028  st->in_stride = st->out_stride = st->nb_channels;
1029  for (i=0;i<st->nb_channels;i++)
1030  {
1031  *out_len = bak_out_len;
1032  *in_len = bak_in_len;
1033  if (in != NULL)
1034  speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len);
1035  else
1036  speex_resampler_process_float(st, i, NULL, in_len, out+i, out_len);
1037  }
1038  st->in_stride = istride_save;
1039  st->out_stride = ostride_save;
1041 }
EXPORT int speex_resampler_process_float(SpeexResamplerState *st, spx_uint32_t channel_index, const float *in, spx_uint32_t *in_len, float *out, spx_uint32_t *out_len)
Definition: resample.c:947
#define NULL
Definition: resample.c:96
spx_uint32_t nb_channels
Definition: resample.c:123
resampler_basic_func resampler_ptr
Definition: resample.c:142
FILE * in
Definition: utils/frame.c:33
FILE * out
Definition: utils/frame.c:33
static int resampler_basic_zero(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
Definition: resample.c:567

◆ speex_resampler_process_interleaved_int()

int speex_resampler_process_interleaved_int ( SpeexResamplerState st,
const spx_int16_t *  in,
spx_uint32_t *  in_len,
spx_int16_t *  out,
spx_uint32_t *  out_len 
)

Resample an interleaved int array. The input and output buffers must not overlap.

Parameters
stResampler state
inInput buffer
in_lenNumber of input samples in the input buffer. Returns the number of samples processed. This is all per-channel.
outOutput buffer
out_lenSize of the output buffer. Returns the number of samples written. This is all per-channel.

Definition at line 1043 of file resample.c.

References SpeexResamplerState_::in_stride, SpeexResamplerState_::nb_channels, NULL, SpeexResamplerState_::out_stride, resampler_basic_zero(), RESAMPLER_ERR_ALLOC_FAILED, RESAMPLER_ERR_SUCCESS, SpeexResamplerState_::resampler_ptr, and speex_resampler_process_int().

1044 {
1045  spx_uint32_t i;
1046  int istride_save, ostride_save;
1047  spx_uint32_t bak_out_len = *out_len;
1048  spx_uint32_t bak_in_len = *in_len;
1049  istride_save = st->in_stride;
1050  ostride_save = st->out_stride;
1051  st->in_stride = st->out_stride = st->nb_channels;
1052  for (i=0;i<st->nb_channels;i++)
1053  {
1054  *out_len = bak_out_len;
1055  *in_len = bak_in_len;
1056  if (in != NULL)
1057  speex_resampler_process_int(st, i, in+i, in_len, out+i, out_len);
1058  else
1059  speex_resampler_process_int(st, i, NULL, in_len, out+i, out_len);
1060  }
1061  st->in_stride = istride_save;
1062  st->out_stride = ostride_save;
1064 }
#define NULL
Definition: resample.c:96
spx_uint32_t nb_channels
Definition: resample.c:123
resampler_basic_func resampler_ptr
Definition: resample.c:142
FILE * in
Definition: utils/frame.c:33
FILE * out
Definition: utils/frame.c:33
static int resampler_basic_zero(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_word16_t *in, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
Definition: resample.c:567
EXPORT int speex_resampler_process_int(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, spx_uint32_t *out_len)
Definition: resample.c:906

◆ speex_resampler_reset_mem()

int speex_resampler_reset_mem ( SpeexResamplerState st)

Reset a resampler so a new (unrelated) stream can be processed.

Parameters
stResampler state

Definition at line 1177 of file resample.c.

References SpeexResamplerState_::filt_len, SpeexResamplerState_::last_sample, SpeexResamplerState_::magic_samples, SpeexResamplerState_::mem, SpeexResamplerState_::nb_channels, RESAMPLER_ERR_SUCCESS, and SpeexResamplerState_::samp_frac_num.

1178 {
1179  spx_uint32_t i;
1180  for (i=0;i<st->nb_channels;i++)
1181  {
1182  st->last_sample[i] = 0;
1183  st->magic_samples[i] = 0;
1184  st->samp_frac_num[i] = 0;
1185  }
1186  for (i=0;i<st->nb_channels*(st->filt_len-1);i++)
1187  st->mem[i] = 0;
1188  return RESAMPLER_ERR_SUCCESS;
1189 }
spx_uint32_t filt_len
Definition: resample.c:124
spx_uint32_t * samp_frac_num
Definition: resample.c:136
spx_uint32_t nb_channels
Definition: resample.c:123
spx_word16_t * mem
Definition: resample.c:139
spx_int32_t * last_sample
Definition: resample.c:135
spx_uint32_t * magic_samples
Definition: resample.c:137

◆ speex_resampler_set_input_stride()

void speex_resampler_set_input_stride ( SpeexResamplerState st,
spx_uint32_t  stride 
)

Set (change) the input stride.

Parameters
stResampler state
strideInput stride

Definition at line 1139 of file resample.c.

References SpeexResamplerState_::in_stride.

1140 {
1141  st->in_stride = stride;
1142 }

◆ speex_resampler_set_output_stride()

void speex_resampler_set_output_stride ( SpeexResamplerState st,
spx_uint32_t  stride 
)

Set (change) the output stride.

Parameters
stResampler state
strideOutput stride

Definition at line 1149 of file resample.c.

References SpeexResamplerState_::out_stride.

1150 {
1151  st->out_stride = stride;
1152 }

◆ speex_resampler_set_quality()

int speex_resampler_set_quality ( SpeexResamplerState st,
int  quality 
)

Set (change) the conversion quality.

Parameters
stResampler state
qualityResampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality.

Definition at line 1122 of file resample.c.

References SpeexResamplerState_::initialised, SpeexResamplerState_::quality, RESAMPLER_ERR_INVALID_ARG, RESAMPLER_ERR_SUCCESS, and update_filter().

Referenced by speex_resampler_init_frac().

1123 {
1124  if (quality > 10 || quality < 0)
1126  if (st->quality == quality)
1127  return RESAMPLER_ERR_SUCCESS;
1128  st->quality = quality;
1129  if (st->initialised)
1130  return update_filter(st);
1131  return RESAMPLER_ERR_SUCCESS;
1132 }
static int quality
Definition: codec_speex.c:62
static int update_filter(SpeexResamplerState *st)
Definition: resample.c:594

◆ speex_resampler_set_rate()

int speex_resampler_set_rate ( SpeexResamplerState st,
spx_uint32_t  in_rate,
spx_uint32_t  out_rate 
)

Set (change) the input/output sampling rates (integer value).

Parameters
stResampler state
in_rateInput sampling rate (integer number of Hz).
out_rateOutput sampling rate (integer number of Hz).

Definition at line 1066 of file resample.c.

References speex_resampler_set_rate_frac().

1067 {
1068  return speex_resampler_set_rate_frac(st, in_rate, out_rate, in_rate, out_rate);
1069 }
EXPORT int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate)
Definition: resample.c:1077

◆ speex_resampler_set_rate_frac()

int speex_resampler_set_rate_frac ( SpeexResamplerState st,
spx_uint32_t  ratio_num,
spx_uint32_t  ratio_den,
spx_uint32_t  in_rate,
spx_uint32_t  out_rate 
)

Set (change) the input/output sampling rates and resampling ratio (fractional values in Hz supported).

Parameters
stResampler state
ratio_numNumerator of the sampling rate ratio
ratio_denDenominator of the sampling rate ratio
in_rateInput sampling rate rounded to the nearest integer (in Hz).
out_rateOutput sampling rate rounded to the nearest integer (in Hz).

Definition at line 1077 of file resample.c.

References SpeexResamplerState_::den_rate, IMIN, SpeexResamplerState_::in_rate, SpeexResamplerState_::initialised, SpeexResamplerState_::nb_channels, SpeexResamplerState_::num_rate, SpeexResamplerState_::out_rate, RESAMPLER_ERR_SUCCESS, SpeexResamplerState_::samp_frac_num, and update_filter().

Referenced by speex_resampler_init_frac(), and speex_resampler_set_rate().

1078 {
1079  spx_uint32_t fact;
1080  spx_uint32_t old_den;
1081  spx_uint32_t i;
1082  if (st->in_rate == in_rate && st->out_rate == out_rate && st->num_rate == ratio_num && st->den_rate == ratio_den)
1083  return RESAMPLER_ERR_SUCCESS;
1084 
1085  old_den = st->den_rate;
1086  st->in_rate = in_rate;
1087  st->out_rate = out_rate;
1088  st->num_rate = ratio_num;
1089  st->den_rate = ratio_den;
1090  /* FIXME: This is terribly inefficient, but who cares (at least for now)? */
1091  for (fact=2;fact<=IMIN(st->num_rate, st->den_rate);fact++)
1092  {
1093  while ((st->num_rate % fact == 0) && (st->den_rate % fact == 0))
1094  {
1095  st->num_rate /= fact;
1096  st->den_rate /= fact;
1097  }
1098  }
1099 
1100  if (old_den > 0)
1101  {
1102  for (i=0;i<st->nb_channels;i++)
1103  {
1104  st->samp_frac_num[i]=st->samp_frac_num[i]*st->den_rate/old_den;
1105  /* Safety net */
1106  if (st->samp_frac_num[i] >= st->den_rate)
1107  st->samp_frac_num[i] = st->den_rate-1;
1108  }
1109  }
1110 
1111  if (st->initialised)
1112  return update_filter(st);
1113  return RESAMPLER_ERR_SUCCESS;
1114 }
spx_uint32_t * samp_frac_num
Definition: resample.c:136
static int update_filter(SpeexResamplerState *st)
Definition: resample.c:594
spx_uint32_t nb_channels
Definition: resample.c:123
spx_uint32_t in_rate
Definition: resample.c:117
spx_uint32_t out_rate
Definition: resample.c:118
#define IMIN(a, b)
Definition: resample.c:93
spx_uint32_t num_rate
Definition: resample.c:119
spx_uint32_t den_rate
Definition: resample.c:120

◆ speex_resampler_skip_zeros()

int speex_resampler_skip_zeros ( SpeexResamplerState st)

Make sure that the first samples to go out of the resamplers don't have leading zeros. This is only useful before starting to use a newly created resampler. It is recommended to use that when resampling an audio file, as it will generate a file with the same length. For real-time processing, it is probably easier not to use this call (so that the output duration is the same for the first frame).

Parameters
stResampler state

Definition at line 1169 of file resample.c.

References SpeexResamplerState_::filt_len, SpeexResamplerState_::last_sample, SpeexResamplerState_::nb_channels, and RESAMPLER_ERR_SUCCESS.

1170 {
1171  spx_uint32_t i;
1172  for (i=0;i<st->nb_channels;i++)
1173  st->last_sample[i] = st->filt_len/2;
1174  return RESAMPLER_ERR_SUCCESS;
1175 }
spx_uint32_t filt_len
Definition: resample.c:124
spx_uint32_t nb_channels
Definition: resample.c:123
spx_int32_t * last_sample
Definition: resample.c:135

◆ speex_resampler_strerror()

const char* speex_resampler_strerror ( int  err)

Returns the English meaning for an error code

Parameters
errError code
Returns
English string

Definition at line 1191 of file resample.c.

References RESAMPLER_ERR_ALLOC_FAILED, RESAMPLER_ERR_BAD_STATE, RESAMPLER_ERR_INVALID_ARG, RESAMPLER_ERR_PTR_OVERLAP, and RESAMPLER_ERR_SUCCESS.

1192 {
1193  switch (err)
1194  {
1195  case RESAMPLER_ERR_SUCCESS:
1196  return "Success.";
1198  return "Memory allocation failed.";
1200  return "Bad resampler state.";
1202  return "Invalid argument.";
1204  return "Input and output buffers overlap.";
1205  default:
1206  return "Unknown error. Bad error code or strange version mismatch.";
1207  }
1208 }