mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-12 21:24:14 +00:00
small tweak to resampler
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7435 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
ab519911c4
commit
89b9e1fbf1
@ -774,7 +774,7 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread,
|
|||||||
/* If the caller is not at the right sample rate resample him to suit and buffer accordingly */
|
/* If the caller is not at the right sample rate resample him to suit and buffer accordingly */
|
||||||
if (imember->mux_resampler) {
|
if (imember->mux_resampler) {
|
||||||
int16_t *bptr = (int16_t *) imember->frame;
|
int16_t *bptr = (int16_t *) imember->frame;
|
||||||
int16_t out[1024];
|
int16_t out[SWITCH_RECOMMENDED_BUFFER_SIZE];
|
||||||
int len = (int) imember->read;
|
int len = (int) imember->read;
|
||||||
|
|
||||||
imember->mux_resampler->from_len = switch_short_to_float(bptr, imember->mux_resampler->from, (int) len / 2);
|
imember->mux_resampler->from_len = switch_short_to_float(bptr, imember->mux_resampler->from, (int) len / 2);
|
||||||
@ -784,6 +784,10 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread,
|
|||||||
switch_float_to_short(imember->mux_resampler->to, out, len);
|
switch_float_to_short(imember->mux_resampler->to, out, len);
|
||||||
len = imember->mux_resampler->to_len * 2;
|
len = imember->mux_resampler->to_len * 2;
|
||||||
|
|
||||||
|
if (len > SWITCH_RECOMMENDED_BUFFER_SIZE) {
|
||||||
|
len = SWITCH_RECOMMENDED_BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
switch_buffer_write(imember->resample_buffer, out, len);
|
switch_buffer_write(imember->resample_buffer, out, len);
|
||||||
if (switch_buffer_inuse(imember->resample_buffer) >= bytes) {
|
if (switch_buffer_inuse(imember->resample_buffer) >= bytes) {
|
||||||
imember->read = (uint32_t) switch_buffer_read(imember->resample_buffer, imember->frame, bytes);
|
imember->read = (uint32_t) switch_buffer_read(imember->resample_buffer, imember->frame, bytes);
|
||||||
|
@ -143,9 +143,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
|
|||||||
if (!fh->resampler) {
|
if (!fh->resampler) {
|
||||||
if (switch_resample_create(&fh->resampler,
|
if (switch_resample_create(&fh->resampler,
|
||||||
fh->native_rate,
|
fh->native_rate,
|
||||||
orig_len * 10,
|
orig_len,
|
||||||
fh->samplerate,
|
fh->samplerate,
|
||||||
(uint32_t)orig_len * 10,
|
(uint32_t)orig_len,
|
||||||
fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
@ -197,9 +197,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
|||||||
if (!fh->resampler) {
|
if (!fh->resampler) {
|
||||||
if (switch_resample_create(&fh->resampler,
|
if (switch_resample_create(&fh->resampler,
|
||||||
fh->native_rate,
|
fh->native_rate,
|
||||||
orig_len * 10,
|
orig_len,
|
||||||
fh->samplerate,
|
fh->samplerate,
|
||||||
(uint32_t)orig_len * 10,
|
(uint32_t)orig_len,
|
||||||
fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
|
@ -192,9 +192,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||||||
switch_mutex_lock(session->resample_mutex);
|
switch_mutex_lock(session->resample_mutex);
|
||||||
status = switch_resample_create(&session->read_resampler,
|
status = switch_resample_create(&session->read_resampler,
|
||||||
read_frame->codec->implementation->actual_samples_per_second,
|
read_frame->codec->implementation->actual_samples_per_second,
|
||||||
read_frame->codec->implementation->bytes_per_frame * 20,
|
read_frame->codec->implementation->bytes_per_frame,
|
||||||
session->read_codec->implementation->actual_samples_per_second,
|
session->read_codec->implementation->actual_samples_per_second,
|
||||||
session->read_codec->implementation->bytes_per_frame * 20, session->pool);
|
session->read_codec->implementation->bytes_per_frame, session->pool);
|
||||||
switch_mutex_unlock(session->resample_mutex);
|
switch_mutex_unlock(session->resample_mutex);
|
||||||
|
|
||||||
if (status != SWITCH_STATUS_SUCCESS) {
|
if (status != SWITCH_STATUS_SUCCESS) {
|
||||||
@ -520,9 +520,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||||||
switch_mutex_lock(session->resample_mutex);
|
switch_mutex_lock(session->resample_mutex);
|
||||||
status = switch_resample_create(&session->write_resampler,
|
status = switch_resample_create(&session->write_resampler,
|
||||||
frame->codec->implementation->actual_samples_per_second,
|
frame->codec->implementation->actual_samples_per_second,
|
||||||
frame->codec->implementation->bytes_per_frame * 20,
|
frame->codec->implementation->bytes_per_frame,
|
||||||
session->write_codec->implementation->actual_samples_per_second,
|
session->write_codec->implementation->actual_samples_per_second,
|
||||||
session->write_codec->implementation->bytes_per_frame * 20, session->pool);
|
session->write_codec->implementation->bytes_per_frame, session->pool);
|
||||||
switch_mutex_unlock(session->resample_mutex);
|
switch_mutex_unlock(session->resample_mutex);
|
||||||
if (status != SWITCH_STATUS_SUCCESS) {
|
if (status != SWITCH_STATUS_SUCCESS) {
|
||||||
goto done;
|
goto done;
|
||||||
@ -753,9 +753,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||||||
switch_mutex_lock(session->resample_mutex);
|
switch_mutex_lock(session->resample_mutex);
|
||||||
status = switch_resample_create(&session->read_resampler,
|
status = switch_resample_create(&session->read_resampler,
|
||||||
frame->codec->implementation->actual_samples_per_second,
|
frame->codec->implementation->actual_samples_per_second,
|
||||||
frame->codec->implementation->bytes_per_frame * 20,
|
frame->codec->implementation->bytes_per_frame,
|
||||||
session->write_codec->implementation->actual_samples_per_second,
|
session->write_codec->implementation->actual_samples_per_second,
|
||||||
session->write_codec->implementation->bytes_per_frame * 20, session->pool);
|
session->write_codec->implementation->bytes_per_frame, session->pool);
|
||||||
switch_mutex_unlock(session->resample_mutex);
|
switch_mutex_unlock(session->resample_mutex);
|
||||||
|
|
||||||
if (status != SWITCH_STATUS_SUCCESS) {
|
if (status != SWITCH_STATUS_SUCCESS) {
|
||||||
|
@ -51,6 +51,8 @@
|
|||||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define resample_buffer(a, b, c) a > b ? ((a / 1000) / 2) * c : ((b / 1000) / 2) * c
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t **new_resampler,
|
SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t **new_resampler,
|
||||||
int from_rate, switch_size_t from_size, int to_rate, uint32_t to_size, switch_memory_pool_t *pool)
|
int from_rate, switch_size_t from_size, int to_rate, uint32_t to_size, switch_memory_pool_t *pool)
|
||||||
{
|
{
|
||||||
@ -74,9 +76,9 @@ SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t
|
|||||||
resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor);
|
resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate,
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate,
|
||||||
resampler->factor);
|
resampler->factor);
|
||||||
resampler->from_size = from_size;
|
resampler->from_size = resample_buffer(to_rate, from_rate, (uint32_t)from_size);
|
||||||
resampler->from = (float *) switch_core_alloc(pool, resampler->from_size);
|
resampler->from = (float *) switch_core_alloc(pool, resampler->from_size);
|
||||||
resampler->to_size = to_size;
|
resampler->to_size = resample_buffer(to_rate, from_rate, (uint32_t)to_size); ;
|
||||||
resampler->to = (float *) switch_core_alloc(pool, resampler->to_size);
|
resampler->to = (float *) switch_core_alloc(pool, resampler->to_size);
|
||||||
|
|
||||||
*new_resampler = resampler;
|
*new_resampler = resampler;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user