diff --git a/include/asterisk/audiohook.h b/include/asterisk/audiohook.h index e19c8339f5..b2e831dd87 100644 --- a/include/asterisk/audiohook.h +++ b/include/asterisk/audiohook.h @@ -328,6 +328,16 @@ int ast_channel_audiohook_count_by_source_running(struct ast_channel *chan, cons */ int ast_audiohook_volume_set(struct ast_channel *chan, enum ast_audiohook_direction direction, int volume); +/*! + * \brief Adjust the volume on frames read from or written to a channel + * \param chan Channel to muck with + * \param direction Direction to set on + * \param volume Value to adjust the volume by + * \retval 0 on success + * \retval -1 on failure + */ +int ast_audiohook_volume_set_float(struct ast_channel *chan, enum ast_audiohook_direction direction, float volume); + /*! * \brief Retrieve the volume adjustment value on frames read from or written to a channel * \param chan Channel to retrieve volume adjustment from @@ -337,6 +347,14 @@ int ast_audiohook_volume_set(struct ast_channel *chan, enum ast_audiohook_direct */ int ast_audiohook_volume_get(struct ast_channel *chan, enum ast_audiohook_direction direction); +/*! + * \brief Retrieve the volume adjustment value on frames read from or written to a channel + * \param chan Channel to retrieve volume adjustment from + * \param direction Direction to retrieve + * \return adjustment value + */ +float ast_audiohook_volume_get_float(struct ast_channel *chan, enum ast_audiohook_direction direction); + /*! * \brief Adjust the volume on frames read from or written to a channel * \param chan Channel to muck with @@ -348,6 +366,16 @@ int ast_audiohook_volume_get(struct ast_channel *chan, enum ast_audiohook_direct */ int ast_audiohook_volume_adjust(struct ast_channel *chan, enum ast_audiohook_direction direction, int volume); +/*! + * \brief Adjust the volume on frames read from or written to a channel + * \param chan Channel to muck with + * \param direction Direction to increase + * \param volume Value to adjust the adjustment by + * \retval 0 on success + * \retval -1 on failure + */ +int ast_audiohook_volume_adjust_float(struct ast_channel *chan, enum ast_audiohook_direction direction, float volume); + /*! \brief Mute frames read from or written to a channel * \param chan Channel to muck with * \param source Type of audiohook diff --git a/main/audiohook.c b/main/audiohook.c index 7709b980a1..86136c22dd 100644 --- a/main/audiohook.c +++ b/main/audiohook.c @@ -1210,8 +1210,8 @@ int ast_channel_audiohook_count_by_source_running(struct ast_channel *chan, cons /*! \brief Audiohook volume adjustment structure */ struct audiohook_volume { struct ast_audiohook audiohook; /*!< Audiohook attached to the channel */ - int read_adjustment; /*!< Value to adjust frames read from the channel by */ - int write_adjustment; /*!< Value to adjust frames written to the channel by */ + float read_adjustment; /*!< Value to adjust frames read from the channel by */ + float write_adjustment; /*!< Value to adjust frames written to the channel by */ }; /*! \brief Callback used to destroy the audiohook volume datastore @@ -1248,7 +1248,7 @@ static int audiohook_volume_callback(struct ast_audiohook *audiohook, struct ast { struct ast_datastore *datastore = NULL; struct audiohook_volume *audiohook_volume = NULL; - int *gain = NULL; + float *gain = NULL; /* If the audiohook is shutting down don't even bother */ if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE) { @@ -1271,7 +1271,7 @@ static int audiohook_volume_callback(struct ast_audiohook *audiohook, struct ast /* If an adjustment value is present modify the frame */ if (gain && *gain) { - ast_frame_adjust_volume(frame, *gain); + ast_frame_adjust_volume_float(frame, *gain); } return 0; @@ -1319,6 +1319,11 @@ static struct audiohook_volume *audiohook_volume_get(struct ast_channel *chan, i } int ast_audiohook_volume_set(struct ast_channel *chan, enum ast_audiohook_direction direction, int volume) +{ + return ast_audiohook_volume_adjust_float(chan, direction, (float) volume); +} + +int ast_audiohook_volume_set_float(struct ast_channel *chan, enum ast_audiohook_direction direction, float volume) { struct audiohook_volume *audiohook_volume = NULL; @@ -1339,9 +1344,14 @@ int ast_audiohook_volume_set(struct ast_channel *chan, enum ast_audiohook_direct } int ast_audiohook_volume_get(struct ast_channel *chan, enum ast_audiohook_direction direction) +{ + return (int) ast_audiohook_volume_get_float(chan, direction); +} + +float ast_audiohook_volume_get_float(struct ast_channel *chan, enum ast_audiohook_direction direction) { struct audiohook_volume *audiohook_volume = NULL; - int adjustment = 0; + float adjustment = 0; /* Attempt to find the audiohook volume information, but do not create it as we only want to look at the values */ if (!(audiohook_volume = audiohook_volume_get(chan, 0))) { @@ -1359,6 +1369,11 @@ int ast_audiohook_volume_get(struct ast_channel *chan, enum ast_audiohook_direct } int ast_audiohook_volume_adjust(struct ast_channel *chan, enum ast_audiohook_direction direction, int volume) +{ + return ast_audiohook_volume_adjust_float(chan, direction, (float) volume); +} + +int ast_audiohook_volume_adjust_float(struct ast_channel *chan, enum ast_audiohook_direction direction, float volume) { struct audiohook_volume *audiohook_volume = NULL;