--- main/app.c.orig 2008-03-25 10:42:35.000000000 -0400 +++ main/app.c 2009-02-17 08:03:04.000000000 -0500 @@ -575,6 +575,7 @@ static int __ast_play_and_record(struct int rfmt = 0; struct ast_silence_generator *silgen = NULL; char prependfile[80]; + int exitbydtmf = 0; if (silencethreshold < 0) silencethreshold = global_silence_threshold; @@ -712,24 +713,28 @@ static int __ast_play_and_record(struct } else if (f->frametype == AST_FRAME_VIDEO) { /* Write only once */ ast_writestream(others[0], f); - } else if (f->frametype == AST_FRAME_DTMF) { + } else if (f->frametype == AST_FRAME_DTMF_BEGIN + || f->frametype == AST_FRAME_DTMF) { if (prepend) { /* stop recording with any digit */ ast_verb(3, "User ended message by pressing %c\n", f->subclass); res = 't'; outmsg = 2; + exitbydtmf = 1; break; } if (strchr(acceptdtmf, f->subclass)) { ast_verb(3, "User ended message by pressing %c\n", f->subclass); res = f->subclass; outmsg = 2; + exitbydtmf = 1; break; } if (strchr(canceldtmf, f->subclass)) { ast_verb(3, "User cancelled message by pressing %c\n", f->subclass); res = f->subclass; outmsg = 0; + exitbydtmf = 1; break; } } @@ -777,11 +782,22 @@ static int __ast_play_and_record(struct break; /*!\note * If we ended with silence, trim all but the first 200ms of silence - * off the recording. However, if we ended with '#', we don't want - * to trim ANY part of the recording. + * off the recording. */ if (res > 0 && totalsilence) ast_stream_rewind(others[x], totalsilence - 200); + + /* + * If we ended with '#', trim the first bit of the + * DTMF tone before the detector triggered (5-25ms), + * and then some to account for button press noise. + */ + else if (res > 0 && exitbydtmf) { + /* assumes 8000 Hz */ + int durationms = ast_tellstream(others[x]) / 8; + ast_stream_rewind(others[x], + durationms > 400 ? 400 : 0); + } ast_truncstream(others[x]); ast_closestream(others[x]); }