[commit] r11226 - in freeswitch/trunk/src: . include
Author: anthm Date: Thu Jan 15 11:47:21 2009 New Revision: 11226 Log: mux multi-channel audio files to mono to support playing stereo sound files Modified: freeswitch/trunk/src/include/switch_resample.h freeswitch/trunk/src/switch_core_file.c freeswitch/trunk/src/switch_resample.c Modified: freeswitch/trunk/src/include/switch_resample.h ============================================================================== --- freeswitch/trunk/src/include/switch_resample.h (original) +++ freeswitch/trunk/src/include/switch_resample.h Thu Jan 15 11:47:21 2009 @@ -168,6 +168,8 @@ SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples); +SWITCH_DECLARE(void) switch_mux_channels(int16_t *data, uint32_t samples, uint32_t channels); + SWITCH_END_EXTERN_C #endif /* For Emacs: Modified: freeswitch/trunk/src/switch_core_file.c ============================================================================== --- freeswitch/trunk/src/switch_core_file.c (original) +++ freeswitch/trunk/src/switch_core_file.c Thu Jan 15 11:47:21 2009 @@ -120,7 +120,11 @@ if (fh->pre_buffer_datalen) { //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Prebuffering %d bytes\n", (int)fh->pre_buffer_datalen); switch_buffer_create_dynamic(&fh->pre_buffer, fh->pre_buffer_datalen * fh->channels, fh->pre_buffer_datalen * fh->channels / 2, 0); - fh->pre_buffer_data = switch_core_alloc(fh->memory_pool, fh->pre_buffer_datalen); + fh->pre_buffer_data = switch_core_alloc(fh->memory_pool, fh->pre_buffer_datalen * fh->channels); + } + + if (fh->channels > 1) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "File has %d channels, muxing to mono will occur.\n", fh->channels); } switch_set_flag(fh, SWITCH_FILE_OPEN); @@ -164,6 +168,9 @@ if ((status = fh->file_interface->file_read(fh, fh->pre_buffer_data, &rlen)) != SWITCH_STATUS_SUCCESS || !rlen) { switch_set_flag(fh, SWITCH_FILE_BUFFER_DONE); } else { + if (fh->channels > 1) { + switch_mux_channels((int16_t *)fh->pre_buffer_data, rlen, fh->channels); + } switch_buffer_write(fh->pre_buffer, fh->pre_buffer_data, asis ? rlen : rlen * 2); } } @@ -185,6 +192,11 @@ switch_set_flag(fh, SWITCH_FILE_DONE); goto top; } + + if (fh->channels > 1) { + switch_mux_channels((int16_t *)data, *len, fh->channels); + } + } Modified: freeswitch/trunk/src/switch_resample.c ============================================================================== --- freeswitch/trunk/src/switch_resample.c (original) +++ freeswitch/trunk/src/switch_resample.c Thu Jan 15 11:47:21 2009 @@ -244,6 +244,27 @@ return x; } +SWITCH_DECLARE(void) switch_mux_channels(int16_t *data, uint32_t samples, uint32_t channels) +{ + int16_t *buf; + switch_size_t len = samples * sizeof(int16_t); + uint32_t i = 0, j = 0, k = 0; + + switch_zmalloc(buf, len); + + for(i = 0; i < samples; i++) { + for (j = 0; j < channels; j++) { + int32_t z = buf[i] + data[k++]; + switch_normalize_to_16bit(z); + buf[i] = (int16_t) z; + } + } + + memcpy(data, buf, len); + free(buf); + +} + SWITCH_DECLARE(void) switch_change_sln_volume(int16_t *data, uint32_t samples, int32_t vol) { double newrate = 0;
participants (1)
-
FreeSWITCH SVN