SAF
Loading...
Searching...
No Matches
speex_resampler.h File Reference

Main header file for the Speex resampler. More...

Go to the source code of this file.

Macros

#define OUTSIDE_SPEEX
 
#define RANDOM_PREFIX   speex_
 
#define CAT_PREFIX2(a, b)   a ## b
 
#define CAT_PREFIX(a, b)   CAT_PREFIX2(a, b)
 
#define speex_resampler_init   CAT_PREFIX(RANDOM_PREFIX,_resampler_init)
 
#define speex_resampler_init_frac   CAT_PREFIX(RANDOM_PREFIX,_resampler_init_frac)
 
#define speex_resampler_destroy   CAT_PREFIX(RANDOM_PREFIX,_resampler_destroy)
 
#define speex_resampler_process_float   CAT_PREFIX(RANDOM_PREFIX,_resampler_process_float)
 
#define speex_resampler_process_int   CAT_PREFIX(RANDOM_PREFIX,_resampler_process_int)
 
#define speex_resampler_process_interleaved_float   CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_float)
 
#define speex_resampler_process_interleaved_int   CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_int)
 
#define speex_resampler_set_rate   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate)
 
#define speex_resampler_get_rate   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_rate)
 
#define speex_resampler_set_rate_frac   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate_frac)
 
#define speex_resampler_get_ratio   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_ratio)
 
#define speex_resampler_set_quality   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_quality)
 
#define speex_resampler_get_quality   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality)
 
#define speex_resampler_set_input_stride   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride)
 
#define speex_resampler_get_input_stride   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride)
 
#define speex_resampler_set_output_stride   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride)
 
#define speex_resampler_get_output_stride   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride)
 
#define speex_resampler_get_input_latency   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency)
 
#define speex_resampler_get_output_latency   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency)
 
#define speex_resampler_skip_zeros   CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
 
#define speex_resampler_reset_mem   CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
 
#define speex_resampler_strerror   CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
 
#define spx_int16_t   short
 
#define spx_int32_t   int
 
#define spx_uint16_t   unsigned short
 
#define spx_uint32_t   unsigned int
 
#define speex_assert(cond)
 
#define SPEEX_RESAMPLER_QUALITY_MAX   10
 
#define SPEEX_RESAMPLER_QUALITY_MIN   0
 
#define SPEEX_RESAMPLER_QUALITY_DEFAULT   4
 
#define SPEEX_RESAMPLER_QUALITY_VOIP   3
 
#define SPEEX_RESAMPLER_QUALITY_DESKTOP   5
 

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_OVERFLOW = 5 , RESAMPLER_ERR_MAX_ERROR
}
 

Functions

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.
 
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.
 
void speex_resampler_destroy (SpeexResamplerState *st)
 Destroy a resampler state.
 
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.
 
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.
 
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.
 
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.
 
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).
 
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).
 
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).
 
void speex_resampler_get_ratio (SpeexResamplerState *st, spx_uint32_t *ratio_num, spx_uint32_t *ratio_den)
 Get the current resampling ratio.
 
int speex_resampler_set_quality (SpeexResamplerState *st, int quality)
 Set (change) the conversion quality.
 
void speex_resampler_get_quality (SpeexResamplerState *st, int *quality)
 Get the conversion quality.
 
void speex_resampler_set_input_stride (SpeexResamplerState *st, spx_uint32_t stride)
 Set (change) the input stride.
 
void speex_resampler_get_input_stride (SpeexResamplerState *st, spx_uint32_t *stride)
 Get the input stride.
 
void speex_resampler_set_output_stride (SpeexResamplerState *st, spx_uint32_t stride)
 Set (change) the output stride.
 
void speex_resampler_get_output_stride (SpeexResamplerState *st, spx_uint32_t *stride)
 Get the output stride.
 
int speex_resampler_get_input_latency (SpeexResamplerState *st)
 Get the latency introduced by the resampler measured in input samples.
 
int speex_resampler_get_output_latency (SpeexResamplerState *st)
 Get the latency introduced by the resampler measured in output samples.
 
int speex_resampler_skip_zeros (SpeexResamplerState *st)
 Make sure that the first samples to go out of the resamplers don't have leading zeros.
 
int speex_resampler_reset_mem (SpeexResamplerState *st)
 Reset a resampler so a new (unrelated) stream can be processed.
 
const char * speex_resampler_strerror (int err)
 Returns the English meaning for an error code.
 

Detailed Description

Main header file for the Speex resampler.

License
BSD 3-Clause

Definition in file speex_resampler.h.

Macro Definition Documentation

◆ CAT_PREFIX

#define CAT_PREFIX ( a,
b )   CAT_PREFIX2(a, b)

Definition at line 63 of file speex_resampler.h.

◆ CAT_PREFIX2

#define CAT_PREFIX2 ( a,
b )   a ## b

Definition at line 62 of file speex_resampler.h.

◆ OUTSIDE_SPEEX

#define OUTSIDE_SPEEX

Definition at line 47 of file speex_resampler.h.

◆ RANDOM_PREFIX

#define RANDOM_PREFIX   speex_

Definition at line 48 of file speex_resampler.h.

◆ speex_assert

#define speex_assert ( cond)

Definition at line 93 of file speex_resampler.h.

◆ speex_resampler_destroy

#define speex_resampler_destroy   CAT_PREFIX(RANDOM_PREFIX,_resampler_destroy)

Definition at line 67 of file speex_resampler.h.

◆ speex_resampler_get_input_latency

#define speex_resampler_get_input_latency   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency)

Definition at line 82 of file speex_resampler.h.

◆ speex_resampler_get_input_stride

#define speex_resampler_get_input_stride   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride)

Definition at line 79 of file speex_resampler.h.

◆ speex_resampler_get_output_latency

#define speex_resampler_get_output_latency   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency)

Definition at line 83 of file speex_resampler.h.

◆ speex_resampler_get_output_stride

#define speex_resampler_get_output_stride   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride)

Definition at line 81 of file speex_resampler.h.

◆ speex_resampler_get_quality

#define speex_resampler_get_quality   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality)

Definition at line 77 of file speex_resampler.h.

◆ speex_resampler_get_rate

#define speex_resampler_get_rate   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_rate)

Definition at line 73 of file speex_resampler.h.

◆ speex_resampler_get_ratio

#define speex_resampler_get_ratio   CAT_PREFIX(RANDOM_PREFIX,_resampler_get_ratio)

Definition at line 75 of file speex_resampler.h.

◆ speex_resampler_init

#define speex_resampler_init   CAT_PREFIX(RANDOM_PREFIX,_resampler_init)

Definition at line 65 of file speex_resampler.h.

◆ speex_resampler_init_frac

#define speex_resampler_init_frac   CAT_PREFIX(RANDOM_PREFIX,_resampler_init_frac)

Definition at line 66 of file speex_resampler.h.

◆ speex_resampler_process_float

#define speex_resampler_process_float   CAT_PREFIX(RANDOM_PREFIX,_resampler_process_float)

Definition at line 68 of file speex_resampler.h.

◆ speex_resampler_process_int

#define speex_resampler_process_int   CAT_PREFIX(RANDOM_PREFIX,_resampler_process_int)

Definition at line 69 of file speex_resampler.h.

◆ speex_resampler_process_interleaved_float

#define speex_resampler_process_interleaved_float   CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_float)

Definition at line 70 of file speex_resampler.h.

◆ speex_resampler_process_interleaved_int

#define speex_resampler_process_interleaved_int   CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_int)

Definition at line 71 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_DEFAULT

#define SPEEX_RESAMPLER_QUALITY_DEFAULT   4

Definition at line 107 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_DESKTOP

#define SPEEX_RESAMPLER_QUALITY_DESKTOP   5

Definition at line 109 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_MAX

#define SPEEX_RESAMPLER_QUALITY_MAX   10

Definition at line 105 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_MIN

#define SPEEX_RESAMPLER_QUALITY_MIN   0

Definition at line 106 of file speex_resampler.h.

◆ SPEEX_RESAMPLER_QUALITY_VOIP

#define SPEEX_RESAMPLER_QUALITY_VOIP   3

Definition at line 108 of file speex_resampler.h.

◆ speex_resampler_reset_mem

#define speex_resampler_reset_mem   CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)

Definition at line 85 of file speex_resampler.h.

◆ speex_resampler_set_input_stride

#define speex_resampler_set_input_stride   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride)

Definition at line 78 of file speex_resampler.h.

◆ speex_resampler_set_output_stride

#define speex_resampler_set_output_stride   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride)

Definition at line 80 of file speex_resampler.h.

◆ speex_resampler_set_quality

#define speex_resampler_set_quality   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_quality)

Definition at line 76 of file speex_resampler.h.

◆ speex_resampler_set_rate

#define speex_resampler_set_rate   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate)

Definition at line 72 of file speex_resampler.h.

◆ speex_resampler_set_rate_frac

#define speex_resampler_set_rate_frac   CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate_frac)

Definition at line 74 of file speex_resampler.h.

◆ speex_resampler_skip_zeros

#define speex_resampler_skip_zeros   CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)

Definition at line 84 of file speex_resampler.h.

◆ speex_resampler_strerror

#define speex_resampler_strerror   CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)

Definition at line 86 of file speex_resampler.h.

◆ spx_int16_t

#define spx_int16_t   short

Definition at line 88 of file speex_resampler.h.

◆ spx_int32_t

#define spx_int32_t   int

Definition at line 89 of file speex_resampler.h.

◆ spx_uint16_t

#define spx_uint16_t   unsigned short

Definition at line 90 of file speex_resampler.h.

◆ spx_uint32_t

#define spx_uint32_t   unsigned int

Definition at line 91 of file speex_resampler.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Definition at line 111 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 888 of file resample.c.

◆ speex_resampler_get_input_latency()

int speex_resampler_get_input_latency ( SpeexResamplerState * st)

Get the latency introduced by the resampler measured in input samples.

Parameters
stResampler state

Definition at line 1210 of file resample.c.

◆ 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 1195 of file resample.c.

◆ speex_resampler_get_output_latency()

int speex_resampler_get_output_latency ( SpeexResamplerState * st)

Get the latency introduced by the resampler measured in output samples.

Parameters
stResampler state

Definition at line 1215 of file resample.c.

◆ 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 1205 of file resample.c.

◆ 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 1185 of file resample.c.

◆ 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 1109 of file resample.c.

◆ 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 1167 of file resample.c.

◆ 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.
Returns
Newly created resampler state
Return values
NULLError: not enough memory

Definition at line 814 of file resample.c.

◆ 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.
Returns
Newly created resampler state
Return values
NULLError: not enough memory

Definition at line 819 of file resample.c.

◆ 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.

◆ 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 988 of file resample.c.

◆ 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 1058 of file resample.c.

◆ 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 1081 of file resample.c.

◆ 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 1228 of file resample.c.

◆ 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 1190 of file resample.c.

◆ 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 1200 of file resample.c.

◆ 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 1173 of file resample.c.

◆ 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 1104 of file resample.c.

◆ 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 1127 of file resample.c.

◆ 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 1220 of file resample.c.

◆ 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 1242 of file resample.c.