35 #include <speex/speex.h> 36 #include <speex/speex_preprocess.h> 39 #undef SWITCH_MOD_DECLARE_DATA 40 #define SWITCH_MOD_DECLARE_DATA __declspec(dllexport) 110 struct SpeexBits encoder_bits;
113 SpeexPreprocessState *
pp;
117 struct SpeexBits decoder_bits;
127 char *fmtp_dup = NULL;
136 memcpy(codec_settings, &default_codec_settings,
sizeof(*codec_settings));
148 fmtp_dup = strdup(fmtp);
153 for (x = 0; x < argc; x++) {
154 char *data = argv[x];
157 while (*data ==
' ') {
160 if (!(arg = strchr(data,
'='))) {
168 if (!strcasecmp(
"vbr", data)) {
170 if (!strcasecmp(
"vad", arg)) {
172 codec_settings->
vbr = 0;
173 codec_settings->
vad = 1;
174 codec_settings->
pp_vad = 1;
178 codec_settings->
vbr = 1;
179 codec_settings->
vad = 0;
180 codec_settings->
pp_vad = 1;
183 codec_settings->
vbr = 0;
184 codec_settings->
vad = 0;
185 codec_settings->
pp_vad = 0;
188 }
else if (!strcasecmp(
"cng", data)) {
191 }
else if (!strcasecmp(
"mode", data)) {
195 if (!strncasecmp(
"any", arg, 3)) {
199 arg_dup = strdup(arg);
202 char *mode_str = mode[0];
203 if (mode_str[0] ==
'"') {
208 mode_num = atoi(mode_str);
244 if (mode_num >= 0 && mode_num <= 10) {
246 codec_settings->
quality = mode_num;
266 int encoding, decoding;
274 const SpeexMode *
mode = NULL;
287 mode = &speex_nb_mode;
289 mode = &speex_wb_mode;
291 mode = &speex_uwb_mode;
368 uint32_t decoded_data_len,
369 uint32_t decoded_rate,
void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
383 is_speech = speex_preprocess(context->
pp, buf, NULL);
399 *encoded_data_len = 0;
411 (*encoded_data_len)--;
419 uint32_t encoded_data_len,
420 uint32_t encoded_rate,
void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
435 speex_bits_read_from(&context->
decoder_bits, (
char *) encoded_data, (
int) encoded_data_len);
445 int encoding, decoding;
482 if (
zstr(settings_name)) {
498 if (!strcasecmp(
"quality", name)) {
500 int tmp = atoi(value);
502 default_codec_settings.
quality = tmp;
506 }
else if (!strcasecmp(
"complexity", name)) {
508 int tmp = atoi(value);
514 }
else if (!strcasecmp(
"enhancement", name)) {
517 }
else if (!strcasecmp(
"vad", name)) {
520 }
else if (!strcasecmp(
"vbr", name)) {
523 }
else if (!strcasecmp(
"vbr-quality", name)) {
525 float tmp = (float)atof(value);
531 }
else if (!strcasecmp(
"abr", name)) {
533 int tmp = atoi(value);
535 default_codec_settings.
abr = tmp;
539 }
else if (!strcasecmp(
"dtx", name)) {
542 }
else if (!strcasecmp(
"preproc", name)) {
545 }
else if (!strcasecmp(
"pp-vad", name)) {
548 }
else if (!strcasecmp(
"pp-agc", name)) {
551 }
else if (!strcasecmp(
"pp-agc-level", name)) {
553 float tmp = (float)atof(value);
559 }
else if (!strcasecmp(
"pp-denoise", name)) {
562 }
else if (!strcasecmp(
"pp-dereverb", name)) {
565 }
else if (!strcasecmp(
"pp-dereverb-decay", name)) {
567 float tmp = (float)atof(value);
573 }
else if (!strcasecmp(
"pp-dereverb-level", name)) {
575 float tmp = (float)atof(value);
593 int mpf = 20000, spf = 160, bpf = 320, rate = 8000, counta, countb;
595 int bps[4] = { 0, 24600, 42200, 44000 };
603 for (counta = 1; counta <= 3; counta++) {
604 for (countb = 1; countb > 0; countb--) {
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
SpeexPreprocessState * pp
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
#define SWITCH_CHANNEL_LOG
const char * switch_xml_attr(_In_opt_ switch_xml_t xml, _In_opt_z_ const char *attr)
returns the value of the requested tag attribute, or NULL if not found
SWITCH_MODULE_LOAD_FUNCTION(core_speex_load)
uint32_t decoded_bytes_per_packet
switch_memory_pool_t * pool
speex_codec_settings_t codec_settings
const char *const const char *const const cJSON *const value
static void switch_core_codec_add_implementation(switch_memory_pool_t *pool, switch_codec_interface_t *codec_interface, const switch_codec_type_t codec_type, switch_payload_t ianacode, const char *iananame, char *fmtp, uint32_t samples_per_second, uint32_t actual_samples_per_second, int bits_per_second, int microseconds_per_packet, uint32_t samples_per_packet, uint32_t decoded_bytes_per_packet, uint32_t encoded_bytes_per_packet, uint8_t number_of_channels, int codec_frames_per_packet, switch_core_codec_init_func_t init, switch_core_codec_encode_func_t encode, switch_core_codec_decode_func_t decode, switch_core_codec_destroy_func_t destroy)
switch_bool_t switch_is_number(const char *str)
struct SpeexBits decoder_bits
A representation of an XML tree.
static switch_status_t switch_speex_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
uint32_t switch_codec_flag_t
static switch_status_t switch_speex_encode(switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data, uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
static switch_status_t switch_speex_decode(switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data, uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
const switch_codec_implementation_t * implementation
switch_byte_t switch_byte_t * buf
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
uint32_t actual_samples_per_second
switch_memory_pool_t * memory_pool
Top level module interface to implement a series of codec implementations.
switch_byte_t switch_byte_t uint32_t switch_bitpack_mode_t mode
unsigned int encoder_frame_size
uint32_t actual_samples_per_second
#define SWITCH_ADD_CODEC(codec_int, int_name)
static void load_configuration(void)
switch_status_t
Common return values.
switch_core_codec_fmtp_parse_func_t parse_fmtp
switch_xml_t switch_xml_open_cfg(_In_z_ const char *file_path, _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params)
open a config in the core registry
switch_loadable_module_interface_t * switch_loadable_module_create_module_interface(switch_memory_pool_t *pool, const char *name)
unsigned int decoder_frame_size
SWITCH_MODULE_DEFINITION(CORE_SPEEX_MODULE, core_speex_load, NULL, NULL)
switch_xml_t switch_xml_child(_In_ switch_xml_t xml, _In_z_ const char *name)
returns the first child tag (one level deeper) with the given name or NULL \ if not found ...
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
static switch_status_t switch_speex_fmtp_parse(const char *fmtp, switch_codec_fmtp_t *codec_fmtp)
static switch_status_t switch_speex_destroy(switch_codec_t *codec)
Various codec settings (currently only relevant to speex)
static speex_codec_settings_t default_codec_settings
struct SpeexBits encoder_bits