add channels param the the silence generator function
This commit is contained in:
parent
09ae3a9841
commit
579a051867
|
@ -152,7 +152,7 @@ SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len);
|
|||
\param samples the number of 2 byte samples
|
||||
\param divisor the volume factor
|
||||
*/
|
||||
SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor);
|
||||
SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t channels, uint32_t divisor);
|
||||
|
||||
/*!
|
||||
\brief Change the volume of a signed linear audio frame
|
||||
|
|
|
@ -4425,7 +4425,7 @@ static void conference_loop_output(conference_member_t *member)
|
|||
} else {
|
||||
|
||||
if (member->conference->comfort_noise_level) {
|
||||
switch_generate_sln_silence(write_frame.data, samples, member->conference->comfort_noise_level);
|
||||
switch_generate_sln_silence(write_frame.data, samples, member->conference->channels, member->conference->comfort_noise_level);
|
||||
} else {
|
||||
memset(write_frame.data, 255, bytes);
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_random_runtime)
|
|||
int i = 0;
|
||||
int len = sizeof(data) / 2;
|
||||
|
||||
switch_generate_sln_silence(data, len, 1);
|
||||
switch_generate_sln_silence(data, len, 1, 1);
|
||||
random_add_entropy(rfd, data, len);
|
||||
|
||||
while(i < len && !data[i]) i++;
|
||||
|
|
|
@ -94,7 +94,7 @@ static switch_status_t silence_stream_file_read(switch_file_handle_t *handle, vo
|
|||
sh->samples -= (int32_t)*len;
|
||||
}
|
||||
|
||||
switch_generate_sln_silence((int16_t *) data, (uint32_t)*len,
|
||||
switch_generate_sln_silence((int16_t *) data, (uint32_t)*len, handle->channels,
|
||||
sh->silence ? sh->silence : (uint32_t)-1);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
|
|
@ -142,6 +142,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session,
|
|||
|
||||
arg_recursion_check_start(args);
|
||||
|
||||
switch_core_session_get_read_impl(session, &imp);
|
||||
|
||||
/*
|
||||
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND && !switch_channel_test_flag(channel, CF_PROXY_MODE) &&
|
||||
!switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)) {
|
||||
|
@ -171,7 +173,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session,
|
|||
}
|
||||
|
||||
if (ms > 10 && sval) {
|
||||
switch_core_session_get_read_impl(session, &imp);
|
||||
|
||||
if (switch_core_codec_init(&codec,
|
||||
"L16",
|
||||
|
@ -299,7 +300,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session,
|
|||
}
|
||||
|
||||
if (sval && write_frame.datalen) {
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, imp.number_of_channels, sval);
|
||||
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
|
||||
} else {
|
||||
switch_core_session_write_frame(session, &cng_frame, SWITCH_IO_FLAG_NONE, 0);
|
||||
|
@ -992,7 +993,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
|
|||
}
|
||||
|
||||
if (rate && write_frame.data && sval) {
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, read_impl.number_of_channels, sval);
|
||||
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
|
||||
}
|
||||
|
||||
|
@ -1409,7 +1410,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
|
|||
}
|
||||
|
||||
if (write_frame.data) {
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, imp.number_of_channels, sval);
|
||||
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -2531,6 +2531,10 @@ static switch_bool_t session_audio_callback(switch_media_bug_t *bug, void *user_
|
|||
switch_session_audio_t *pvt = (switch_session_audio_t *) user_data;
|
||||
switch_frame_t *frame = NULL;
|
||||
int level = 0, mute = 0;
|
||||
switch_core_session_t *session = switch_core_media_bug_get_session(bug);
|
||||
switch_codec_implementation_t read_impl = { 0 };
|
||||
|
||||
switch_core_session_get_read_impl(session, &read_impl);
|
||||
|
||||
|
||||
if (type == SWITCH_ABC_TYPE_READ_REPLACE || type == SWITCH_ABC_TYPE_WRITE_REPLACE) {
|
||||
|
@ -2553,7 +2557,7 @@ static switch_bool_t session_audio_callback(switch_media_bug_t *bug, void *user_
|
|||
if (frame) {
|
||||
if (mute) {
|
||||
if (mute > 1) {
|
||||
switch_generate_sln_silence(frame->data, frame->datalen / 2, mute);
|
||||
switch_generate_sln_silence(frame->data, frame->datalen / 2, read_impl.number_of_channels, mute);
|
||||
} else {
|
||||
memset(frame->data, 0, frame->datalen);
|
||||
}
|
||||
|
|
|
@ -562,7 +562,8 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
|
|||
read_frame_count++;
|
||||
if (switch_test_flag(read_frame, SFF_CNG)) {
|
||||
if (silence_val) {
|
||||
switch_generate_sln_silence((int16_t *) silence_frame.data, silence_frame.samples, silence_val);
|
||||
switch_generate_sln_silence((int16_t *) silence_frame.data, silence_frame.samples,
|
||||
read_frame->codec->implementation->number_of_channels, silence_val);
|
||||
read_frame = &silence_frame;
|
||||
} else if (!switch_channel_test_flag(chan_b, CF_ACCEPT_CNG)) {
|
||||
continue;
|
||||
|
|
|
@ -1084,7 +1084,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
|
|||
}
|
||||
} else if (ringback.silence) {
|
||||
write_frame.datalen = write_frame.codec->implementation->decoded_bytes_per_packet;
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, ringback.silence);
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2,
|
||||
write_frame.codec->implementation->number_of_channels, ringback.silence);
|
||||
}
|
||||
|
||||
if ((ringback.fh || ringback.silence || ringback.audio_buffer) && write_frame.codec && write_frame.datalen) {
|
||||
|
@ -3213,7 +3214,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
|
|||
if ((ringback.fh || silence || ringback.audio_buffer || oglobals.bridge_early_media > -1) && write_frame.codec && write_frame.datalen) {
|
||||
if (silence) {
|
||||
write_frame.datalen = read_impl.decoded_bytes_per_packet;
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, silence);
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, write_frame.codec->implementation->number_of_channels, silence);
|
||||
}
|
||||
|
||||
if (switch_core_session_write_frame(oglobals.session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
|
||||
|
|
|
@ -713,9 +713,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||
double energy = 0;
|
||||
|
||||
|
||||
for (count = 0; count < samples; count++) {
|
||||
energy += abs(fdata[j]);
|
||||
j += read_impl.number_of_channels;
|
||||
for (count = 0; count < samples * read_impl.number_of_channels; count++) {
|
||||
energy += abs(fdata[j++]);
|
||||
}
|
||||
|
||||
score = (uint32_t) (energy / (samples / divisor));
|
||||
|
@ -730,9 +729,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||
}
|
||||
|
||||
if (fill_cng) {
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, fill_cng);
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, read_impl.number_of_channels, fill_cng);
|
||||
} else if (waste_resources) {
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, waste_resources);
|
||||
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, read_impl.number_of_channels, waste_resources);
|
||||
}
|
||||
|
||||
if (!switch_test_flag(fh, SWITCH_FILE_PAUSE) && !switch_test_flag(read_frame, SFF_CNG)) {
|
||||
|
|
|
@ -181,14 +181,16 @@ SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len)
|
|||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor)
|
||||
|
||||
SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t channels, uint32_t divisor)
|
||||
{
|
||||
int16_t x;
|
||||
uint32_t i;
|
||||
int16_t s;
|
||||
uint32_t x, i, j;
|
||||
int sum_rnd = 0;
|
||||
int16_t rnd2 = (int16_t) switch_micro_time_now() + (int16_t) (intptr_t) data;
|
||||
|
||||
if (channels == 0) channels = 1;
|
||||
|
||||
assert(divisor);
|
||||
|
||||
if (divisor == (uint32_t)-1) {
|
||||
|
@ -201,38 +203,18 @@ SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples
|
|||
rnd2 = rnd2 * 31821U + 13849U;
|
||||
sum_rnd += rnd2;
|
||||
}
|
||||
//switch_normalize_to_16bit(sum_rnd);
|
||||
*data = (int16_t) ((int16_t) sum_rnd / (int) divisor);
|
||||
|
||||
data++;
|
||||
}
|
||||
}
|
||||
#else
|
||||
s = (int16_t) ((int16_t) sum_rnd / (int) divisor);
|
||||
|
||||
SWITCH_DECLARE(void) switch_generate_sln_silence(int16_t *data, uint32_t samples, uint32_t divisor)
|
||||
{
|
||||
int16_t rnd = 0, rnd2, x;
|
||||
uint32_t i;
|
||||
int sum_rnd = 0;
|
||||
|
||||
assert(divisor);
|
||||
|
||||
rnd2 = (int16_t) (intptr_t) (&data + switch_epoch_time_now(NULL));
|
||||
|
||||
for (i = 0; i < samples; i++, sum_rnd = 0) {
|
||||
for (x = 0; x < 10; x++) {
|
||||
rnd = rnd + (int16_t) ((x + i) * rnd2);
|
||||
sum_rnd += rnd;
|
||||
for (j = 0; j < channels; j++) {
|
||||
*data = s;
|
||||
data++;
|
||||
}
|
||||
switch_normalize_to_16bit(sum_rnd);
|
||||
*data = (int16_t) ((int16_t) sum_rnd / (int) divisor);
|
||||
|
||||
data++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16_t *other_data, uint32_t other_samples)
|
||||
{
|
||||
int i;
|
||||
|
|
Loading…
Reference in New Issue