#include <switch.h>
Include dependency graph for switch_resample.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Data Structures | |
| struct | switch_audio_resampler_t |
| An audio resampling handle. More... | |
Defines | |
| #define | switch_normalize_volume(x) if (x > 4) x = 4; if (x < -4) x = -4; |
| #define | switch_normalize_volume_granular(x) if (x > 12) x = 12; if (x < -12) x = -12; |
| #define | SWITCH_RESAMPLE_QUALITY 2 |
| #define | switch_resample_create(_n, _fr, _tr, _ts, _q, _c) switch_resample_perform_create(_n, _fr, _tr, _ts, _q, _c, __FILE__, __SWITCH_FUNC__, __LINE__) |
Functions | |
| switch_status_t | switch_resample_perform_create (switch_audio_resampler_t **new_resampler, uint32_t from_rate, uint32_t to_rate, uint32_t to_size, int quality, uint32_t channels, const char *file, const char *func, int line) |
| Prepare a new resampler handle. | |
| void | switch_resample_destroy (switch_audio_resampler_t **resampler) |
| Destroy an existing resampler handle. | |
| uint32_t | switch_resample_process (switch_audio_resampler_t *resampler, int16_t *src, uint32_t srclen) |
| Resample one float buffer into another using specifications of a given handle. | |
| switch_size_t | switch_float_to_short (float *f, short *s, switch_size_t len) |
| Convert an array of floats to an array of shorts. | |
| int | switch_char_to_float (char *c, float *f, int len) |
| Convert an array of chars to an array of floats. | |
| int | switch_float_to_char (float *f, char *c, int len) |
| Convert an array of floats to an array of chars. | |
| int | switch_short_to_float (short *s, float *f, int len) |
| Convert an array of shorts to an array of floats. | |
| void | switch_swap_linear (int16_t *buf, int len) |
| Perform a byteswap on a buffer of 16 bit samples. | |
| void | switch_generate_sln_silence (int16_t *data, uint32_t samples, uint32_t divisor) |
| Generate static noise. | |
| void | switch_change_sln_volume (int16_t *data, uint32_t samples, int32_t vol) |
| Change the volume of a signed linear audio frame. | |
| void | switch_change_sln_volume_granular (int16_t *data, uint32_t samples, int32_t vol) |
| Change the volume of a signed linear audio frame with more granularity. | |
| uint32_t | switch_merge_sln (int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples) |
| uint32_t | switch_unmerge_sln (int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples) |
| void | switch_mux_channels (int16_t *data, switch_size_t samples, uint32_t channels) |
This module implements a generic interface for doing audio resampling it currently uses libresample but can be ported to any resample library with a little effort. I decided against making this interface pluggable because there are not many options in terms of resample libraries so it seemed like a waste but I did opt to frontend the interface in case a better way comes along some day. =D
Definition in file switch_resample.h.
| #define switch_normalize_volume | ( | x | ) | if (x > 4) x = 4; if (x < -4) x = -4; |
Definition at line 41 of file switch_resample.h.
Referenced by switch_change_sln_volume(), and switch_ivr_process_fh().
| #define switch_normalize_volume_granular | ( | x | ) | if (x > 12) x = 12; if (x < -12) x = -12; |
| #define SWITCH_RESAMPLE_QUALITY 2 |
Definition at line 46 of file switch_resample.h.
Referenced by switch_core_file_read(), switch_core_file_write(), switch_core_session_write_frame(), and switch_core_speech_read_tts().
| uint32_t switch_merge_sln | ( | int16_t * | data, | |
| uint32_t | samples, | |||
| int16_t * | other_data, | |||
| uint32_t | other_samples | |||
| ) |
Definition at line 235 of file switch_resample.c.
References switch_normalize_to_16bit.
Referenced by eavesdrop_callback().
00236 { 00237 int i; 00238 int32_t x, z; 00239 00240 if (samples > other_samples) { 00241 x = other_samples; 00242 } else { 00243 x = samples; 00244 } 00245 00246 for (i = 0; i < x; i++) { 00247 z = data[i] + other_data[i]; 00248 switch_normalize_to_16bit(z); 00249 data[i] = (int16_t) z; 00250 } 00251 00252 return x; 00253 }
| void switch_mux_channels | ( | int16_t * | data, | |
| switch_size_t | samples, | |||
| uint32_t | channels | |||
| ) |
Definition at line 274 of file switch_resample.c.
References buf, switch_normalize_to_16bit, and switch_zmalloc.
Referenced by switch_core_file_read().
00275 { 00276 int16_t *buf; 00277 switch_size_t len = samples * sizeof(int16_t); 00278 switch_size_t i = 0; 00279 uint32_t j = 0, k = 0; 00280 00281 switch_zmalloc(buf, len); 00282 00283 for (i = 0; i < samples; i++) { 00284 for (j = 0; j < channels; j++) { 00285 int32_t z = buf[i] + data[k++]; 00286 switch_normalize_to_16bit(z); 00287 buf[i] = (int16_t) z; 00288 } 00289 } 00290 00291 memcpy(data, buf, len); 00292 free(buf); 00293 00294 }
| uint32_t switch_unmerge_sln | ( | int16_t * | data, | |
| uint32_t | samples, | |||
| int16_t * | other_data, | |||
| uint32_t | other_samples | |||
| ) |
Definition at line 256 of file switch_resample.c.
00257 { 00258 int i; 00259 int32_t x; 00260 00261 if (samples > other_samples) { 00262 x = other_samples; 00263 } else { 00264 x = samples; 00265 } 00266 00267 for (i = 0; i < x; i++) { 00268 data[i] -= other_data[i]; 00269 } 00270 00271 return x; 00272 }
1.4.7