sndfile tweak

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@213 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2005-12-27 19:52:30 +00:00
parent 378ce8e115
commit dad4780765
4 changed files with 34 additions and 20 deletions

View File

@ -449,7 +449,6 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig)
switch_clear_flag(tech_pvt, TFLAG_IO); switch_clear_flag(tech_pvt, TFLAG_IO);
switch_clear_flag(tech_pvt, TFLAG_VOICE); switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_thread_cond_signal(tech_pvt->cond);
switch_channel_hangup(channel); switch_channel_hangup(channel);
switch_thread_cond_signal(tech_pvt->cond); switch_thread_cond_signal(tech_pvt->cond);

View File

@ -41,7 +41,7 @@ static const char modname[] = "mod_playback";
void playback_function(switch_core_session *session, char *data) void playback_function(switch_core_session *session, char *data)
{ {
switch_channel *channel; switch_channel *channel;
char buf[960]; short buf[960];
char dtmf[128]; char dtmf[128];
int interval = 0, samples = 0; int interval = 0, samples = 0;
size_t len = 0, ilen = 0; size_t len = 0, ilen = 0;
@ -59,7 +59,7 @@ void playback_function(switch_core_session *session, char *data)
if (switch_core_file_open(&fh, if (switch_core_file_open(&fh,
data, data,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_RAW, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel); switch_channel_hangup(channel);
return; return;
@ -73,14 +73,12 @@ void playback_function(switch_core_session *session, char *data)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s\n", data); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s\n", data);
samples = fh.samplerate / 50;
len = samples * 2;
interval = 20; interval = 20;
len = 320;
samples = 160;
codec_name = "L16"; codec_name = "L16";
write_frame.samples = samples;
/* You can use zap instead of soft if you have it loaded */
if (switch_core_timer_init(&timer, "soft", interval, samples, pool) != SWITCH_STATUS_SUCCESS) { if (switch_core_timer_init(&timer, "soft", interval, samples, pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer failed!\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer failed!\n");
switch_channel_hangup(channel); switch_channel_hangup(channel);
@ -89,7 +87,13 @@ void playback_function(switch_core_session *session, char *data)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval);
if (switch_core_codec_init(&codec, codec_name, 8000, interval, SWITCH_CODEC_FLAG_ENCODE|SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) { if (switch_core_codec_init(&codec,
codec_name,
8000,
interval,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
pool) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
write_frame.codec = &codec; write_frame.codec = &codec;
} else { } else {
@ -100,7 +104,7 @@ void playback_function(switch_core_session *session, char *data)
/* start a thread to absorb incoming audio */ /* start a thread to absorb incoming audio */
switch_core_service_session(session, &thread_session); switch_core_service_session(session, &thread_session);
ilen = len; ilen = samples;
while(switch_channel_get_state(channel) == CS_EXECUTE) { while(switch_channel_get_state(channel) == CS_EXECUTE) {
int done = 0; int done = 0;
@ -127,7 +131,8 @@ void playback_function(switch_core_session *session, char *data)
break; break;
} }
write_frame.datalen = ilen; write_frame.datalen = ilen * 2;
write_frame.samples = ilen;
#ifdef SWAP_LINEAR #ifdef SWAP_LINEAR
switch_swap_linear(write_frame.data, (int)write_frame.datalen / 2); switch_swap_linear(write_frame.data, (int)write_frame.datalen / 2);
#endif #endif

View File

@ -85,22 +85,29 @@ switch_status sndfile_file_open(switch_file_handle *handle, char *path)
} }
if (!strcmp(ext, "r24")) { if (!strcmp(ext, "r24")) {
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16; context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_24;
context->sfinfo.channels = 1; context->sfinfo.channels = 1;
context->sfinfo.samplerate = 24000; context->sfinfo.samplerate = 24000;
} }
if (!strcmp(ext, "r32")) { if (!strcmp(ext, "r32")) {
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16; context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_32;
context->sfinfo.channels = 1; context->sfinfo.channels = 1;
context->sfinfo.samplerate = 32000; context->sfinfo.samplerate = 32000;
} }
if (!strcmp(ext, "gsm")) {
context->sfinfo.format = SF_FORMAT_RAW |SF_FORMAT_GSM610;
context->sfinfo.channels = 1;
context->sfinfo.samplerate = 8000;
}
if (!(context->handle = sf_open(path, mode, &context->sfinfo))) { if (!(context->handle = sf_open(path, mode, &context->sfinfo))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening File [%s] [%s]\n", path, sf_strerror(context->handle)); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening File [%s] [%s]\n", path, sf_strerror(context->handle));
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate);
handle->samples = context->sfinfo.frames; handle->samples = context->sfinfo.frames;
handle->samplerate = context->sfinfo.samplerate; handle->samplerate = context->sfinfo.samplerate;
handle->channels = context->sfinfo.channels; handle->channels = context->sfinfo.channels;
@ -213,7 +220,8 @@ static switch_status setup_formats(void)
char buffer [128] ; char buffer [128] ;
int format, major_count, subtype_count, m, s ; int format, major_count, subtype_count, m, s ;
int len,x,skip; int len,x,skip;
char *extras[] = {"r8", "r16", "r24", "r32", "gsm"};
int exlen = (sizeof(extras) / sizeof(extras[0]));
buffer [0] = 0 ; buffer [0] = 0 ;
sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ; sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
if (strlen (buffer) < 1) { if (strlen (buffer) < 1) {
@ -228,7 +236,7 @@ static switch_status setup_formats(void)
sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ; sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ;
sfinfo.channels = 1 ; sfinfo.channels = 1 ;
len = (major_count + 5) * sizeof(char *); len = ((major_count + (exlen + 2)) * sizeof(char *));
*supported_formats = switch_core_permenant_alloc(len); *supported_formats = switch_core_permenant_alloc(len);
memset(supported_formats, 0, len); memset(supported_formats, 0, len);
@ -260,11 +268,9 @@ static switch_status setup_formats(void)
} }
} }
for(m=0; m< exlen; m++) {
supported_formats[len++] = "r8"; supported_formats[len++] = extras[m];
supported_formats[len++] = "r16"; }
supported_formats[len++] = "r24";
supported_formats[len++] = "r32";

View File

@ -64,6 +64,10 @@ static void event_handler (switch_event *event)
iks *msg; iks *msg;
int loops = 0; int loops = 0;
if (!RUNNING) {
return;
}
while (!globals.session.authorized) { while (!globals.session.authorized) {
switch_yield(100000); switch_yield(100000);
if (loops++ > 5) { if (loops++ > 5) {