|
SAF
|
Main source file for the Speex resampler. More...
#include "saf_externals.h"#include "speex_resampler.h"#include "arch.h"#include "os_support.h"#include <math.h>#include <limits.h>Go to the source code of this file.
Data Structures | |
| struct | SpeexResamplerState |
| struct | FuncDef |
| struct | QualityMapping |
Macros | |
| #define | SPEEX_USE_CBLAS |
| #define | EXPORT |
| #define | M_PI 3.14159265358979323846 |
| #define | IMAX(a, b) |
| #define | IMIN(a, b) |
| #define | NULL 0 |
| #define | UINT32_MAX 4294967295U |
| #define | FIXED_STACK_ALLOC 1024 |
| #define | KAISER12 (&kaiser12_funcdef) |
| #define | KAISER10 (&kaiser10_funcdef) |
| #define | KAISER8 (&kaiser8_funcdef) |
| #define | KAISER6 (&kaiser6_funcdef) |
Typedefs | |
| typedef int(* | resampler_basic_func) (SpeexResamplerState *, spx_uint32_t, const spx_word16_t *, spx_uint32_t *, spx_word16_t *, spx_uint32_t *) |
Functions | |
| static double | compute_func (float x, const struct FuncDef *func) |
| static spx_word16_t | sinc (float cutoff, float x, int N, const struct FuncDef *window_func) |
| static void | cubic_coef (spx_word16_t frac, spx_word16_t interp[4]) |
| static int | resampler_basic_direct_single (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) |
| static int | resampler_basic_direct_double (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) |
| static int | resampler_basic_interpolate_single (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) |
| static int | resampler_basic_interpolate_double (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) |
| 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) |
| static int | multiply_frac (spx_uint32_t *result, spx_uint32_t value, spx_uint32_t num, spx_uint32_t den) |
| static int | update_filter (SpeexResamplerState *st) |
| EXPORT 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. | |
| 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) |
| Create a new resampler with fractional input/output rates. | |
| EXPORT void | speex_resampler_destroy (SpeexResamplerState *st) |
| Destroy a resampler state. | |
| 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) |
| static int | speex_resampler_magic (SpeexResamplerState *st, spx_uint32_t channel_index, spx_word16_t **out, spx_uint32_t out_len) |
| 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) |
| Resample a float array. | |
| 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) |
| Resample an int array. | |
| EXPORT 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. | |
| EXPORT 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. | |
| EXPORT 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). | |
| EXPORT 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). | |
| static spx_uint32_t | compute_gcd (spx_uint32_t a, spx_uint32_t b) |
| 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) |
| Set (change) the input/output sampling rates and resampling ratio (fractional values in Hz supported). | |
| EXPORT void | speex_resampler_get_ratio (SpeexResamplerState *st, spx_uint32_t *ratio_num, spx_uint32_t *ratio_den) |
| Get the current resampling ratio. | |
| EXPORT int | speex_resampler_set_quality (SpeexResamplerState *st, int quality) |
| Set (change) the conversion quality. | |
| EXPORT void | speex_resampler_get_quality (SpeexResamplerState *st, int *quality) |
| Get the conversion quality. | |
| EXPORT void | speex_resampler_set_input_stride (SpeexResamplerState *st, spx_uint32_t stride) |
| Set (change) the input stride. | |
| EXPORT void | speex_resampler_get_input_stride (SpeexResamplerState *st, spx_uint32_t *stride) |
| Get the input stride. | |
| EXPORT void | speex_resampler_set_output_stride (SpeexResamplerState *st, spx_uint32_t stride) |
| Set (change) the output stride. | |
| EXPORT void | speex_resampler_get_output_stride (SpeexResamplerState *st, spx_uint32_t *stride) |
| Get the output stride. | |
| EXPORT int | speex_resampler_get_input_latency (SpeexResamplerState *st) |
| Get the latency introduced by the resampler measured in input samples. | |
| EXPORT int | speex_resampler_get_output_latency (SpeexResamplerState *st) |
| Get the latency introduced by the resampler measured in output samples. | |
| EXPORT int | speex_resampler_skip_zeros (SpeexResamplerState *st) |
| Make sure that the first samples to go out of the resamplers don't have leading zeros. | |
| EXPORT int | speex_resampler_reset_mem (SpeexResamplerState *st) |
| Reset a resampler so a new (unrelated) stream can be processed. | |
| EXPORT const char * | speex_resampler_strerror (int err) |
| Returns the English meaning for an error code. | |
Variables | |
| static const double | kaiser12_table [68] |
| static const double | kaiser10_table [36] |
| static const double | kaiser8_table [36] |
| static const double | kaiser6_table [36] |
| static const struct FuncDef | kaiser12_funcdef = {kaiser12_table, 64} |
| static const struct FuncDef | kaiser10_funcdef = {kaiser10_table, 32} |
| static const struct FuncDef | kaiser8_funcdef = {kaiser8_table, 32} |
| static const struct FuncDef | kaiser6_funcdef = {kaiser6_table, 32} |
| static const struct QualityMapping | quality_map [11] |
| #define EXPORT |
Definition at line 93 of file resample.c.
| #define FIXED_STACK_ALLOC 1024 |
Definition at line 122 of file resample.c.
| #define IMAX | ( | a, | |
| b ) |
Definition at line 99 of file resample.c.
| #define IMIN | ( | a, | |
| b ) |
Definition at line 100 of file resample.c.
| #define KAISER10 (&kaiser10_funcdef) |
Definition at line 213 of file resample.c.
| #define KAISER12 (&kaiser12_funcdef) |
Definition at line 211 of file resample.c.
| #define KAISER6 (&kaiser6_funcdef) |
Definition at line 217 of file resample.c.
| #define KAISER8 (&kaiser8_funcdef) |
Definition at line 215 of file resample.c.
| #define M_PI 3.14159265358979323846 |
Definition at line 96 of file resample.c.
| #define NULL 0 |
Definition at line 103 of file resample.c.
| #define SPEEX_USE_CBLAS |
Definition at line 64 of file resample.c.
| #define UINT32_MAX 4294967295U |
Definition at line 107 of file resample.c.
| typedef int(* resampler_basic_func) (SpeexResamplerState *, spx_uint32_t, const spx_word16_t *, spx_uint32_t *, spx_word16_t *, spx_uint32_t *) |
Definition at line 125 of file resample.c.
|
static |
Definition at line 251 of file resample.c.
|
inlinestatic |
Definition at line 1115 of file resample.c.
|
static |
Definition at line 329 of file resample.c.
|
static |
Definition at line 613 of file resample.c.
|
static |
Definition at line 405 of file resample.c.
|
static |
Definition at line 342 of file resample.c.
|
static |
Definition at line 521 of file resample.c.
|
static |
Definition at line 458 of file resample.c.
|
static |
Definition at line 585 of file resample.c.
|
static |
Definition at line 299 of file resample.c.
| EXPORT void speex_resampler_destroy | ( | SpeexResamplerState * | st | ) |
| EXPORT int speex_resampler_get_input_latency | ( | SpeexResamplerState * | st | ) |
Get the latency introduced by the resampler measured in input samples.
| st | Resampler state |
Definition at line 1210 of file resample.c.
| EXPORT void speex_resampler_get_input_stride | ( | SpeexResamplerState * | st, |
| spx_uint32_t * | stride ) |
Get the input stride.
| st | Resampler state |
| stride | Input stride copied |
Definition at line 1195 of file resample.c.
| EXPORT int speex_resampler_get_output_latency | ( | SpeexResamplerState * | st | ) |
Get the latency introduced by the resampler measured in output samples.
| st | Resampler state |
Definition at line 1215 of file resample.c.
| EXPORT void speex_resampler_get_output_stride | ( | SpeexResamplerState * | st, |
| spx_uint32_t * | stride ) |
Get the output stride.
| st | Resampler state copied |
| stride | Output stride |
Definition at line 1205 of file resample.c.
| EXPORT void speex_resampler_get_quality | ( | SpeexResamplerState * | st, |
| int * | quality ) |
Get the conversion quality.
| st | Resampler state |
| quality | Resampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality. |
Definition at line 1185 of file resample.c.
| EXPORT 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).
| st | Resampler state |
| in_rate | Input sampling rate (integer number of Hz) copied. |
| out_rate | Output sampling rate (integer number of Hz) copied. |
Definition at line 1109 of file resample.c.
| EXPORT 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.
| st | Resampler state |
| ratio_num | Numerator of the sampling rate ratio copied |
| ratio_den | Denominator of the sampling rate ratio copied |
Definition at line 1167 of file resample.c.
| EXPORT 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.
| nb_channels | Number of channels to be processed |
| in_rate | Input sampling rate (integer number of Hz). |
| out_rate | Output sampling rate (integer number of Hz). |
| quality | Resampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality. |
| NULL | Error: not enough memory |
Definition at line 814 of file resample.c.
| 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 ) |
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.
| nb_channels | Number of channels to be processed |
| ratio_num | Numerator of the sampling rate ratio |
| ratio_den | Denominator of the sampling rate ratio |
| in_rate | Input sampling rate rounded to the nearest integer (in Hz). |
| out_rate | Output sampling rate rounded to the nearest integer (in Hz). |
| quality | Resampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality. |
| NULL | Error: not enough memory |
Definition at line 819 of file resample.c.
|
static |
Definition at line 924 of file resample.c.
| 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 ) |
Resample a float array.
The input and output buffers must not overlap.
| st | Resampler state |
| channel_index | Index of the channel to process for the multi-channel base (0 otherwise) |
| in | Input buffer |
| in_len | Number of input samples in the input buffer. Returns the number of samples processed |
| out | Output buffer |
| out_len | Size of the output buffer. Returns the number of samples written |
Definition at line 947 of file resample.c.
| 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 ) |
Resample an int array.
The input and output buffers must not overlap.
| st | Resampler state |
| channel_index | Index of the channel to process for the multi-channel base (0 otherwise) |
| in | Input buffer |
| in_len | Number of input samples in the input buffer. Returns the number of samples processed |
| out | Output buffer |
| out_len | Size of the output buffer. Returns the number of samples written |
Definition at line 988 of file resample.c.
| EXPORT 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.
| st | Resampler state |
| in | Input buffer |
| in_len | Number of input samples in the input buffer. Returns the number of samples processed. This is all per-channel. |
| out | Output buffer |
| out_len | Size of the output buffer. Returns the number of samples written. This is all per-channel. |
Definition at line 1058 of file resample.c.
| EXPORT 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.
| st | Resampler state |
| in | Input buffer |
| in_len | Number of input samples in the input buffer. Returns the number of samples processed. This is all per-channel. |
| out | Output buffer |
| out_len | Size of the output buffer. Returns the number of samples written. This is all per-channel. |
Definition at line 1081 of file resample.c.
|
static |
Definition at line 898 of file resample.c.
| EXPORT int speex_resampler_reset_mem | ( | SpeexResamplerState * | st | ) |
Reset a resampler so a new (unrelated) stream can be processed.
| st | Resampler state |
Definition at line 1228 of file resample.c.
| EXPORT void speex_resampler_set_input_stride | ( | SpeexResamplerState * | st, |
| spx_uint32_t | stride ) |
Set (change) the input stride.
| st | Resampler state |
| stride | Input stride |
Definition at line 1190 of file resample.c.
| EXPORT void speex_resampler_set_output_stride | ( | SpeexResamplerState * | st, |
| spx_uint32_t | stride ) |
Set (change) the output stride.
| st | Resampler state |
| stride | Output stride |
Definition at line 1200 of file resample.c.
| EXPORT int speex_resampler_set_quality | ( | SpeexResamplerState * | st, |
| int | quality ) |
Set (change) the conversion quality.
| st | Resampler state |
| quality | Resampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality. |
Definition at line 1173 of file resample.c.
| EXPORT 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).
| st | Resampler state |
| in_rate | Input sampling rate (integer number of Hz). |
| out_rate | Output sampling rate (integer number of Hz). |
Definition at line 1104 of file resample.c.
| 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 ) |
Set (change) the input/output sampling rates and resampling ratio (fractional values in Hz supported).
| st | Resampler state |
| ratio_num | Numerator of the sampling rate ratio |
| ratio_den | Denominator of the sampling rate ratio |
| in_rate | Input sampling rate rounded to the nearest integer (in Hz). |
| out_rate | Output sampling rate rounded to the nearest integer (in Hz). |
Definition at line 1127 of file resample.c.
| EXPORT 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).
| st | Resampler state |
Definition at line 1220 of file resample.c.
| EXPORT const char * speex_resampler_strerror | ( | int | err | ) |
Returns the English meaning for an error code.
| err | Error code |
Definition at line 1242 of file resample.c.
|
static |
Definition at line 625 of file resample.c.
|
static |
Definition at line 212 of file resample.c.
|
static |
Definition at line 181 of file resample.c.
|
static |
Definition at line 210 of file resample.c.
|
static |
Definition at line 159 of file resample.c.
|
static |
Definition at line 216 of file resample.c.
|
static |
Definition at line 197 of file resample.c.
|
static |
Definition at line 214 of file resample.c.
|
static |
Definition at line 189 of file resample.c.
|
static |
Definition at line 237 of file resample.c.