Index: res/res_musiconhold.c =================================================================== --- res/res_musiconhold.c (revision 24494) +++ res/res_musiconhold.c (working copy) @@ -109,6 +109,7 @@ struct moh_files_state { struct mohclass *class; int origwfmt; + int writeformat; int samples; int sample_queue; unsigned char pos; @@ -221,16 +222,14 @@ state->pos = state->pos % state->class->total_files; - if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { - ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name); - return -1; - } if (!ast_openstream_full(chan, state->class->filearray[state->pos], chan->language, 1)) { ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", state->class->filearray[state->pos], strerror(errno)); state->pos++; return -1; } + state->writeformat = chan->writeformat; + if (option_debug) ast_log(LOG_DEBUG, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]); @@ -299,8 +298,8 @@ state->origwfmt = chan->writeformat; - if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { - ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name); + if (state->writeformat != 0 && ast_set_write_format(chan, state->writeformat)) { + ast_log(LOG_WARNING, "Unable to set '%s' to %d format (write)\n", chan->name, state->writeformat); free(chan->music_state); chan->music_state = NULL; } else {