[asterisk-dev] audiohook with G722 codec: wrong number of samples

Simon Sester sester at ind.rwth-aachen.de
Thu Apr 29 07:19:13 CDT 2010


On Wed, 2010-04-28 at 11:06 -0500, David Vossel wrote:
> Simon,
> 
> If you are using audiohooks, everything is downgraded to 8khz 16bit signed linear, so if we have 16khz G722 with 320 samples, that will be downgraded to 160 sample 8khz audio for the audiohook manipulation.  This is a limitation that I am not happy with.
> 
> David Vossel
> Digium, Inc. | Software Developer, Open Source Software
> 445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
> Check us out at: www.digium.com & www.asterisk.org
> The_Boy_Wonder in #asterisk-dev

David,

Thanks for your help.

For my application I need all 320 samples so I made some changes to the
audiohook.c so that is passes 16khz 16bit signed linear
(AST_FORMAT_SLINEAR16) to the audiohook callback function if necessary.
I attached a diff to my mail. The hack works fine for me, but as far as
I can tell from looking at the code it only works for TYPE-MANIPULATE
audiohooks.

Simon

-------------- next part --------------
169c169
< static struct ast_frame *audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, int format)
---
> static struct ast_frame *audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction)
181,183c181
< 	if(ast_format_rate(format) == 16000) {
< 		frame.subclass = AST_FORMAT_SLINEAR16;
< 	}
---
> 
199c197
< static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples, int format)
---
> static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples)
210,212c208
< 	if(ast_format_rate(format) == 16000) {
< 		frame.subclass = AST_FORMAT_SLINEAR16;
< 	}
---
> 
303c299
< 	if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ? audiohook_read_frame_both(audiohook, samples, format) : audiohook_read_frame_single(audiohook, samples, direction, format))))
---
> 	if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ? audiohook_read_frame_both(audiohook, samples) : audiohook_read_frame_single(audiohook, samples, direction))))
307c303
< 	if (format != read_frame->subclass) {
---
> 	if (format != AST_FORMAT_SLINEAR) {
315c311
< 			if (!(audiohook->trans_pvt = ast_translator_build_path(format, read_frame->subclass))) {
---
> 			if (!(audiohook->trans_pvt = ast_translator_build_path(format, AST_FORMAT_SLINEAR))) {
319d314
< 			audiohook->format = format;
593a589
> 
599,605c595,596
< 			if(ast_format_rate(frame->subclass) == 16000) {
< 				if (!(in_translate->trans_pvt = ast_translator_build_path(AST_FORMAT_SLINEAR16, frame->subclass)))
< 					return frame;
< 			} else {
< 				if (!(in_translate->trans_pvt = ast_translator_build_path(AST_FORMAT_SLINEAR, frame->subclass)))
< 					return frame;
< 			}
---
> 			if (!(in_translate->trans_pvt = ast_translator_build_path(AST_FORMAT_SLINEAR, frame->subclass)))
> 				return frame;
686,697c677,680
< 				if(ast_format_rate(frame->subclass) == 16000) {
< 					if (!(out_translate->trans_pvt = ast_translator_build_path(start_frame->subclass, AST_FORMAT_SLINEAR16))) {
< 						/* We can't transcode this... drop our middle frame and return the original */
< 						ast_frfree(middle_frame);
< 						return start_frame;
< 					}
< 				} else {
< 					if (!(out_translate->trans_pvt = ast_translator_build_path(start_frame->subclass, AST_FORMAT_SLINEAR))) {
< 						/* We can't transcode this... drop our middle frame and return the original */
< 						ast_frfree(middle_frame);
< 						return start_frame;
< 					}
---
> 				if (!(out_translate->trans_pvt = ast_translator_build_path(start_frame->subclass, AST_FORMAT_SLINEAR))) {
> 					/* We can't transcode this... drop our middle frame and return the original */
> 					ast_frfree(middle_frame);
> 					return start_frame;


More information about the asterisk-dev mailing list