mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 08:13:22 +00:00
audiohook.c: Simplify variable usage in audiohook_read_frame_both().
Change-Id: I58bed58631a94295b267991c5b61a3a93c167f0c
This commit is contained in:
@@ -253,11 +253,16 @@ static struct ast_frame *audiohook_read_frame_single(struct ast_audiohook *audio
|
|||||||
|
|
||||||
static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples, struct ast_frame **read_reference, struct ast_frame **write_reference)
|
static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples, struct ast_frame **read_reference, struct ast_frame **write_reference)
|
||||||
{
|
{
|
||||||
int i = 0, usable_read, usable_write;
|
int count;
|
||||||
short buf1[samples], buf2[samples], *read_buf = NULL, *write_buf = NULL, *final_buf = NULL, *data1 = NULL, *data2 = NULL;
|
int usable_read;
|
||||||
|
int usable_write;
|
||||||
|
short adjust_value;
|
||||||
|
short buf1[samples];
|
||||||
|
short buf2[samples];
|
||||||
|
short *read_buf = NULL;
|
||||||
|
short *write_buf = NULL;
|
||||||
struct ast_frame frame = {
|
struct ast_frame frame = {
|
||||||
.frametype = AST_FRAME_VOICE,
|
.frametype = AST_FRAME_VOICE,
|
||||||
.data.ptr = NULL,
|
|
||||||
.datalen = sizeof(buf1),
|
.datalen = sizeof(buf1),
|
||||||
.samples = samples,
|
.samples = samples,
|
||||||
};
|
};
|
||||||
@@ -290,8 +295,7 @@ static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audioho
|
|||||||
read_buf = buf1;
|
read_buf = buf1;
|
||||||
/* Adjust read volume if need be */
|
/* Adjust read volume if need be */
|
||||||
if (audiohook->options.read_volume) {
|
if (audiohook->options.read_volume) {
|
||||||
int count = 0;
|
adjust_value = abs(audiohook->options.read_volume);
|
||||||
short adjust_value = abs(audiohook->options.read_volume);
|
|
||||||
for (count = 0; count < samples; count++) {
|
for (count = 0; count < samples; count++) {
|
||||||
if (audiohook->options.read_volume > 0) {
|
if (audiohook->options.read_volume > 0) {
|
||||||
ast_slinear_saturated_multiply(&buf1[count], &adjust_value);
|
ast_slinear_saturated_multiply(&buf1[count], &adjust_value);
|
||||||
@@ -311,8 +315,7 @@ static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audioho
|
|||||||
write_buf = buf2;
|
write_buf = buf2;
|
||||||
/* Adjust write volume if need be */
|
/* Adjust write volume if need be */
|
||||||
if (audiohook->options.write_volume) {
|
if (audiohook->options.write_volume) {
|
||||||
int count = 0;
|
adjust_value = abs(audiohook->options.write_volume);
|
||||||
short adjust_value = abs(audiohook->options.write_volume);
|
|
||||||
for (count = 0; count < samples; count++) {
|
for (count = 0; count < samples; count++) {
|
||||||
if (audiohook->options.write_volume > 0) {
|
if (audiohook->options.write_volume > 0) {
|
||||||
ast_slinear_saturated_multiply(&buf2[count], &adjust_value);
|
ast_slinear_saturated_multiply(&buf2[count], &adjust_value);
|
||||||
@@ -330,30 +333,28 @@ static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audioho
|
|||||||
|
|
||||||
/* Basically we figure out which buffer to use... and if mixing can be done here */
|
/* Basically we figure out which buffer to use... and if mixing can be done here */
|
||||||
if (read_buf && read_reference) {
|
if (read_buf && read_reference) {
|
||||||
frame.data.ptr = buf1;
|
frame.data.ptr = read_buf;
|
||||||
*read_reference = ast_frdup(&frame);
|
*read_reference = ast_frdup(&frame);
|
||||||
}
|
}
|
||||||
if (write_buf && write_reference) {
|
if (write_buf && write_reference) {
|
||||||
frame.data.ptr = buf2;
|
frame.data.ptr = write_buf;
|
||||||
*write_reference = ast_frdup(&frame);
|
*write_reference = ast_frdup(&frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_buf && write_buf) {
|
/* Make the correct buffer part of the built frame, so it gets duplicated. */
|
||||||
for (i = 0, data1 = read_buf, data2 = write_buf; i < samples; i++, data1++, data2++) {
|
if (read_buf) {
|
||||||
ast_slinear_saturated_add(data1, data2);
|
frame.data.ptr = read_buf;
|
||||||
|
if (write_buf) {
|
||||||
|
for (count = 0; count < samples; count++) {
|
||||||
|
ast_slinear_saturated_add(read_buf++, write_buf++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final_buf = buf1;
|
|
||||||
} else if (read_buf) {
|
|
||||||
final_buf = buf1;
|
|
||||||
} else if (write_buf) {
|
} else if (write_buf) {
|
||||||
final_buf = buf2;
|
frame.data.ptr = write_buf;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make the final buffer part of the frame, so it gets duplicated fine */
|
|
||||||
frame.data.ptr = final_buf;
|
|
||||||
|
|
||||||
/* Yahoo, a combined copy of the audio! */
|
/* Yahoo, a combined copy of the audio! */
|
||||||
return ast_frdup(&frame);
|
return ast_frdup(&frame);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user