FreeSWITCH API Documentation  1.7.0
Macros | Functions
switch_resample.c File Reference
#include <switch.h>
#include <switch_resample.h>
#include <switch_private.h>
#include <speex/speex_resampler.h>
+ Include dependency graph for switch_resample.c:

Go to the source code of this file.

Macros

#define NORMFACT   (float)0x8000
 
#define MAXSAMPLE   (float)0x7FFF
 
#define MAXSAMPLEC   (char)0x7F
 
#define QUALITY   0
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define resample_buffer(a, b, c)   a > b ? ((a / 1000) / 2) * c : ((b / 1000) / 2) * c
 

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. More...
 
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. More...
 
void switch_resample_destroy (switch_audio_resampler_t **resampler)
 Destroy an existing resampler handle. More...
 
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. More...
 
int switch_char_to_float (char *c, float *f, int len)
 Convert an array of chars to an array of floats. More...
 
int switch_float_to_char (float *f, char *c, int len)
 Convert an array of floats to an array of chars. More...
 
int switch_short_to_float (short *s, float *f, int len)
 Convert an array of shorts to an array of floats. More...
 
void switch_swap_linear (int16_t *buf, int len)
 Perform a byteswap on a buffer of 16 bit samples. More...
 
void switch_generate_sln_silence (int16_t *data, uint32_t samples, uint32_t channels, uint32_t divisor)
 Generate static noise. More...
 
uint32_t switch_merge_sln (int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples, int channels)
 
uint32_t switch_unmerge_sln (int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples, int channels)
 
void switch_mux_channels (int16_t *data, switch_size_t samples, uint32_t orig_channels, uint32_t channels)
 
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. More...
 
void switch_change_sln_volume (int16_t *data, uint32_t samples, int32_t vol)
 Change the volume of a signed linear audio frame. More...
 

Macro Definition Documentation

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

Definition at line 50 of file switch_resample.c.

#define MAXSAMPLE   (float)0x7FFF

Definition at line 41 of file switch_resample.c.

Referenced by switch_char_to_float(), and switch_float_to_short().

#define MAXSAMPLEC   (char)0x7F

Definition at line 42 of file switch_resample.c.

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 46 of file switch_resample.c.

#define NORMFACT   (float)0x8000
#define QUALITY   0

Definition at line 43 of file switch_resample.c.

#define resample_buffer (   a,
  b,
 
)    a > b ? ((a / 1000) / 2) * c : ((b / 1000) / 2) * c

Definition at line 53 of file switch_resample.c.

Function Documentation

uint32_t switch_merge_sln ( int16_t *  data,
uint32_t  samples,
int16_t *  other_data,
uint32_t  other_samples,
int  channels 
)

Definition at line 231 of file switch_resample.c.

References switch_normalize_to_16bit.

Referenced by eavesdrop_callback().

232 {
233  int i;
234  int32_t x, z;
235 
236  if (channels == 0) channels = 1;
237 
238  if (samples > other_samples) {
239  x = other_samples;
240  } else {
241  x = samples;
242  }
243 
244  for (i = 0; i < x * channels; i++) {
245  z = data[i] + other_data[i];
247  data[i] = (int16_t) z;
248  }
249 
250  return x;
251 }
#define switch_normalize_to_16bit(n)
Definition: switch_utils.h:261
void switch_mux_channels ( int16_t *  data,
switch_size_t  samples,
uint32_t  orig_channels,
uint32_t  channels 
)

Definition at line 274 of file switch_resample.c.

References switch_assert, switch_normalize_to_16bit, and switch_zmalloc.

Referenced by switch_core_file_read(), switch_core_session_read_frame(), switch_core_session_write_frame(), switch_core_speech_read_tts(), switch_ivr_eavesdrop_session(), and teletone_handler().

275 {
276  switch_size_t i = 0;
277  uint32_t j = 0;
278 
279  switch_assert(channels < 11);
280 
281  if (orig_channels > channels) {
282  for (i = 0; i < samples; i++) {
283  int32_t z = 0;
284  for (j = 0; j < orig_channels; j++) {
285  z += data[i * orig_channels + j];
287  data[i] = (int16_t) z;
288  }
289  }
290  } else if (orig_channels < channels) {
291 
292  /* interesting problem... take a give buffer and double up every sample in the buffer without using any other buffer.....
293  This way beats the other i think bacause there is no malloc but I do have to copy the data twice */
294 #if 1
295  uint32_t k = 0, len = samples * orig_channels;
296 
297  for (i = 0; i < len; i++) {
298  data[i+len] = data[i];
299  }
300 
301  for (i = 0; i < samples; i++) {
302  for (j = 0; j < channels; j++) {
303  data[k++] = data[i + samples];
304  }
305  }
306 
307 #else
308  uint32_t k = 0, len = samples * 2 * orig_channels;
309  int16_t *orig = NULL;
310 
311  switch_zmalloc(orig, len);
312  memcpy(orig, data, len);
313 
314  for (i = 0; i < samples; i++) {
315  for (j = 0; j < channels; j++) {
316  data[k++] = orig[i];
317  }
318  }
319 
320  free(orig);
321 #endif
322 
323  }
324 }
#define switch_zmalloc(ptr, len)
uintptr_t switch_size_t
#define switch_normalize_to_16bit(n)
Definition: switch_utils.h:261
#define switch_assert(expr)
uint32_t switch_unmerge_sln ( int16_t *  data,
uint32_t  samples,
int16_t *  other_data,
uint32_t  other_samples,
int  channels 
)

Definition at line 254 of file switch_resample.c.

Referenced by switch_core_session_read_frame().

255 {
256  int i;
257  int32_t x;
258 
259  if (channels == 0) channels = 1;
260 
261  if (samples > other_samples) {
262  x = other_samples;
263  } else {
264  x = samples;
265  }
266 
267  for (i = 0; i < x * channels; i++) {
268  data[i] -= other_data[i];
269  }
270 
271  return x;
272 }