#include "asterisk.h"
#include <values.h>
#include <limits.h>
#include <libresample.h>
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "slin_resample_ex.h"
Go to the source code of this file.
Data Structures | |
struct | slin16_to_slin8_pvt |
struct | slin8_to_slin16_pvt |
Defines | |
#define | OUTBUF_SIZE 8096 |
#define | RESAMPLER_QUALITY 1 |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | load_module (void) |
static int | resample_frame (struct ast_trans_pvt *pvt, void *resampler, float resample_factor, struct ast_frame *f) |
static void | slin16_to_slin8_destroy (struct ast_trans_pvt *pvt) |
static int | slin16_to_slin8_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
static int | slin16_to_slin8_new (struct ast_trans_pvt *pvt) |
static struct ast_frame * | slin16_to_slin8_sample (void) |
static void | slin8_to_slin16_destroy (struct ast_trans_pvt *pvt) |
static int | slin8_to_slin16_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
static int | slin8_to_slin16_new (struct ast_trans_pvt *pvt) |
static struct ast_frame * | slin8_to_slin16_sample (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "SLIN Resampling Codec" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_translator | slin16_to_slin8 |
static struct ast_translator | slin8_to_slin16 |
$ svn co http://svn.digium.com/svn/thirdparty/libresample/trunk
Definition in file codec_resample.c.
#define OUTBUF_SIZE 8096 |
Definition at line 56 of file codec_resample.c.
#define RESAMPLER_QUALITY 1 |
Definition at line 54 of file codec_resample.c.
Referenced by slin16_to_slin8_new(), and slin8_to_slin16_new().
static void __reg_module | ( | void | ) | [static] |
Definition at line 245 of file codec_resample.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 245 of file codec_resample.c.
static int load_module | ( | void | ) | [static] |
Definition at line 235 of file codec_resample.c.
References AST_MODULE_LOAD_SUCCESS, ast_register_translator, slin16_to_slin8, and slin8_to_slin16.
00236 { 00237 int res = 0; 00238 00239 res |= ast_register_translator(&slin16_to_slin8); 00240 res |= ast_register_translator(&slin8_to_slin16); 00241 00242 return AST_MODULE_LOAD_SUCCESS; 00243 }
static int resample_frame | ( | struct ast_trans_pvt * | pvt, | |
void * | resampler, | |||
float | resample_factor, | |||
struct ast_frame * | f | |||
) | [static] |
Definition at line 108 of file codec_resample.c.
References ARRAY_LEN, ast_log(), ast_trans_pvt::datalen, f, ast_trans_pvt::i16, LOG_ERROR, ast_trans_pvt::outbuf, and ast_trans_pvt::samples.
Referenced by slin16_to_slin8_framein(), and slin8_to_slin16_framein().
00110 { 00111 int total_in_buf_used = 0; 00112 int total_out_buf_used = 0; 00113 int16_t *in_buf = (int16_t *) f->data.ptr; 00114 int16_t *out_buf = pvt->outbuf.i16 + pvt->samples; 00115 float in_buf_f[f->samples]; 00116 float out_buf_f[2048]; 00117 int res = 0; 00118 int i; 00119 00120 for (i = 0; i < f->samples; i++) 00121 in_buf_f[i] = in_buf[i] * (FLT_MAX / SHRT_MAX); 00122 00123 while (total_in_buf_used < f->samples) { 00124 int in_buf_used, out_buf_used; 00125 00126 out_buf_used = resample_process(resampler, resample_factor, 00127 &in_buf_f[total_in_buf_used], f->samples - total_in_buf_used, 00128 0, &in_buf_used, 00129 &out_buf_f[total_out_buf_used], ARRAY_LEN(out_buf_f) - total_out_buf_used); 00130 00131 if (out_buf_used < 0) 00132 break; 00133 00134 total_out_buf_used += out_buf_used; 00135 total_in_buf_used += in_buf_used; 00136 00137 if (total_out_buf_used == ARRAY_LEN(out_buf_f)) { 00138 ast_log(LOG_ERROR, "Output buffer filled ... need to increase its size\n"); 00139 res = -1; 00140 break; 00141 } 00142 } 00143 00144 for (i = 0; i < total_out_buf_used; i++) 00145 out_buf[i] = out_buf_f[i] * (SHRT_MAX / FLT_MAX); 00146 00147 pvt->samples += total_out_buf_used; 00148 pvt->datalen += (total_out_buf_used * sizeof(int16_t)); 00149 00150 return res; 00151 }
static void slin16_to_slin8_destroy | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 92 of file codec_resample.c.
References ast_trans_pvt::pvt, and slin16_to_slin8_pvt::resampler.
00093 { 00094 struct slin16_to_slin8_pvt *resamp_pvt = pvt->pvt; 00095 00096 if (resamp_pvt->resampler) 00097 resample_close(resamp_pvt->resampler); 00098 }
static int slin16_to_slin8_framein | ( | struct ast_trans_pvt * | pvt, | |
struct ast_frame * | f | |||
) | [static] |
Definition at line 153 of file codec_resample.c.
References f, ast_trans_pvt::pvt, slin16_to_slin8_pvt::resample_factor, resample_frame(), and slin16_to_slin8_pvt::resampler.
00154 { 00155 struct slin16_to_slin8_pvt *resamp_pvt = pvt->pvt; 00156 void *resampler = resamp_pvt->resampler; 00157 float resample_factor = resamp_pvt->resample_factor; 00158 00159 return resample_frame(pvt, resampler, resample_factor, f); 00160 }
static int slin16_to_slin8_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 68 of file codec_resample.c.
References ast_trans_pvt::pvt, slin16_to_slin8_pvt::resample_factor, slin16_to_slin8_pvt::resampler, and RESAMPLER_QUALITY.
00069 { 00070 struct slin16_to_slin8_pvt *resamp_pvt = pvt->pvt; 00071 00072 resamp_pvt->resample_factor = 0.5; 00073 00074 if (!(resamp_pvt->resampler = resample_open(RESAMPLER_QUALITY, 0.5, 0.5))) 00075 return -1; 00076 00077 return 0; 00078 }
static struct ast_frame* slin16_to_slin8_sample | ( | void | ) | [static] |
Definition at line 171 of file codec_resample.c.
References ARRAY_LEN, AST_FORMAT_SLINEAR16, AST_FRAME_VOICE, f, ast_frame::samples, and slin16_slin8_ex.
00172 { 00173 static struct ast_frame f = { 00174 .frametype = AST_FRAME_VOICE, 00175 .subclass = AST_FORMAT_SLINEAR16, 00176 .datalen = sizeof(slin16_slin8_ex), 00177 .samples = ARRAY_LEN(slin16_slin8_ex), 00178 .src = __PRETTY_FUNCTION__, 00179 .data.ptr = slin16_slin8_ex, 00180 }; 00181 00182 return &f; 00183 }
static void slin8_to_slin16_destroy | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 100 of file codec_resample.c.
References ast_trans_pvt::pvt, and slin8_to_slin16_pvt::resampler.
00101 { 00102 struct slin8_to_slin16_pvt *resamp_pvt = pvt->pvt; 00103 00104 if (resamp_pvt->resampler) 00105 resample_close(resamp_pvt->resampler); 00106 }
static int slin8_to_slin16_framein | ( | struct ast_trans_pvt * | pvt, | |
struct ast_frame * | f | |||
) | [static] |
Definition at line 162 of file codec_resample.c.
References f, ast_trans_pvt::pvt, slin8_to_slin16_pvt::resample_factor, resample_frame(), and slin8_to_slin16_pvt::resampler.
00163 { 00164 struct slin8_to_slin16_pvt *resamp_pvt = pvt->pvt; 00165 void *resampler = resamp_pvt->resampler; 00166 float resample_factor = resamp_pvt->resample_factor; 00167 00168 return resample_frame(pvt, resampler, resample_factor, f); 00169 }
static int slin8_to_slin16_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 80 of file codec_resample.c.
References ast_trans_pvt::pvt, slin8_to_slin16_pvt::resample_factor, slin8_to_slin16_pvt::resampler, and RESAMPLER_QUALITY.
00081 { 00082 struct slin8_to_slin16_pvt *resamp_pvt = pvt->pvt; 00083 00084 resamp_pvt->resample_factor = 2.0; 00085 00086 if (!(resamp_pvt->resampler = resample_open(RESAMPLER_QUALITY, 2.0, 2.0))) 00087 return -1; 00088 00089 return 0; 00090 }
static struct ast_frame* slin8_to_slin16_sample | ( | void | ) | [static] |
Definition at line 185 of file codec_resample.c.
References ARRAY_LEN, AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, ast_frame::samples, and slin8_slin16_ex.
00186 { 00187 static struct ast_frame f = { 00188 .frametype = AST_FRAME_VOICE, 00189 .subclass = AST_FORMAT_SLINEAR, 00190 .datalen = sizeof(slin8_slin16_ex), 00191 .samples = ARRAY_LEN(slin8_slin16_ex), 00192 .src = __PRETTY_FUNCTION__, 00193 .data.ptr = slin8_slin16_ex, 00194 }; 00195 00196 return &f; 00197 }
static int unload_module | ( | void | ) | [static] |
Definition at line 225 of file codec_resample.c.
References ast_unregister_translator(), slin16_to_slin8, and slin8_to_slin16.
00226 { 00227 int res = 0; 00228 00229 res |= ast_unregister_translator(&slin16_to_slin8); 00230 res |= ast_unregister_translator(&slin8_to_slin16); 00231 00232 return res; 00233 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "SLIN Resampling Codec" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 245 of file codec_resample.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 245 of file codec_resample.c.
struct ast_translator slin16_to_slin8 [static] |
struct ast_translator slin8_to_slin16 [static] |