audiohook.c: Add ability to adjust volume with float

Add the capability to audiohook for float type volume adjustments.  This allows for adjustments to volume smaller than 6dB.  With INT adjustments, the first step is 2 which converts to ~6dB (or 1/2 volume / double volume depending on adjustment sign). 3dB is a typical adjustment level which can now be accommodated with an adjustment value of 1.41.

This is accomplished by the following:
  Convert internal variables to type float.
  Always use ast_frame_adjust_volume_float() for adjustments.
  Cast int to float in original functions ast_audiohook_volume_set(), and ast_volume_adjust().
  Cast float to int in ast_audiohook_volume_get()
  Add functions ast_audiohook_volume_get_float, ast_audiohook_volume_set_float, and ast_audiohook_volume_adjust_float.

This update maintains 100% backward compatibility.

Resolves: #1171
pull/1174/head
mkmer 1 month ago committed by github-actions[bot]
parent a5bc39fa32
commit edadca7151

@ -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

@ -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;

Loading…
Cancel
Save