[svn-commits] file: branch file/audiohooks r66453 - in /team/file/audiohooks: include/aster...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue May 29 10:08:40 MST 2007


Author: file
Date: Tue May 29 12:08:39 2007
New Revision: 66453

URL: http://svn.digium.com/view/asterisk?view=rev&rev=66453
Log:
Add support for adjusting the volume of frames put into the audiohook from the read/write sources.

Modified:
    team/file/audiohooks/include/asterisk/audiohook.h
    team/file/audiohooks/main/audiohook.c

Modified: team/file/audiohooks/include/asterisk/audiohook.h
URL: http://svn.digium.com/view/asterisk/team/file/audiohooks/include/asterisk/audiohook.h?view=diff&rev=66453&r1=66452&r2=66453
==============================================================================
--- team/file/audiohooks/include/asterisk/audiohook.h (original)
+++ team/file/audiohooks/include/asterisk/audiohook.h Tue May 29 12:08:39 2007
@@ -68,6 +68,11 @@
  */
 typedef int (*ast_audiohook_manipulate_callback)(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction);
 
+struct ast_audiohook_options {
+	int read_volume;  /*!< Volume adjustment on frames read from the channel the hook is on */
+	int write_volume; /*!< Volume adjustment on frames written to the channel the hook is on */
+};
+
 struct ast_audiohook {
 	ast_mutex_t lock;                                      /*!< Lock that protects the audiohook structure */
 	ast_cond_t trigger;                                    /*!< Trigger condition (if enabled) */
@@ -80,6 +85,7 @@
 	int format;                                            /*!< Format translation path is setup as */
 	struct ast_trans_pvt *trans_pvt;                       /*!< Translation path for reading frames */
 	ast_audiohook_manipulate_callback manipulate_callback; /*!< Manipulation callback */
+	struct ast_audiohook_options options;                  /*!< Applicable options */
 	AST_LIST_ENTRY(ast_audiohook) list;                    /*!< Linked list information */
 };
 

Modified: team/file/audiohooks/main/audiohook.c
URL: http://svn.digium.com/view/asterisk/team/file/audiohooks/main/audiohook.c?view=diff&rev=66453&r1=66452&r2=66453
==============================================================================
--- team/file/audiohooks/main/audiohook.c (original)
+++ team/file/audiohooks/main/audiohook.c Tue May 29 12:08:39 2007
@@ -149,6 +149,7 @@
 static struct ast_frame *audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction)
 {
 	struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
+	int vol = (direction == AST_AUDIOHOOK_DIRECTION_READ ? audiohook->options.read_volume : audiohook->options.write_volume);
 	short buf[samples];
 	struct ast_frame frame = {
 		.frametype = AST_FRAME_VOICE,
@@ -165,6 +166,10 @@
 	/* Read data in from factory */
 	if (!ast_slinfactory_read(factory, buf, samples))
 		return NULL;
+
+	/* If a volume adjustment needs to be applied apply it */
+	if (vol)
+		ast_frame_adjust_volume(&frame, vol);
 
 	return ast_frdup(&frame);
 }
@@ -185,6 +190,17 @@
 	if (ast_slinfactory_available(&audiohook->read_factory) >= samples) {
 		if (ast_slinfactory_read(&audiohook->read_factory, buf1, samples))
 			read_buf = buf1;
+		/* Adjust read volume if need be */
+		if (audiohook->options.read_volume) {
+			int count = 0;
+			short adjust_value = abs(audiohook->options.read_volume);
+			for (count = 0; count < samples; count++) {
+				if (audiohook->options.read_volume > 0)
+					ast_slinear_saturated_multiply(&buf1[count], &adjust_value);
+				else if (audiohook->options.read_volume < 0)
+					ast_slinear_saturated_divide(&buf1[count], &adjust_value);
+			}
+		}
 	} else if (option_debug)
 		ast_log(LOG_DEBUG, "Failed to get %zd samples from read factory %p\n", samples, &audiohook->read_factory);
 
@@ -192,6 +208,17 @@
 	if (ast_slinfactory_available(&audiohook->write_factory) >= samples) {
 		if (ast_slinfactory_read(&audiohook->write_factory, buf2, samples))
 			write_buf = buf2;
+		/* Adjust write volume if need be */
+		if (audiohook->options.write_volume) {
+			int count = 0;
+			short adjust_value = abs(audiohook->options.write_volume);
+			for (count = 0; count < samples; count++) {
+				if (audiohook->options.write_volume > 0)
+					ast_slinear_saturated_multiply(&buf2[count], &adjust_value);
+				else if (audiohook->options.write_volume < 0)
+					ast_slinear_saturated_divide(&buf2[count], &adjust_value);
+			}
+		}
 	} else if (option_debug)
 		ast_log(LOG_DEBUG, "Failed to get %zd samples from write factory %p\n", samples, &audiohook->write_factory);
 



More information about the svn-commits mailing list