Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1311b0bf authored by Trinath Thammishetty's avatar Trinath Thammishetty Committed by Ramu Gottipati
Browse files

hal: Add volume control for pcm playback

Add stream specific volume control for pcm playback.
Used for Low latency and Deep buffer cases.

Change-Id: I0f9721f91a7926ab2c99de84e9bf9333ff0bd91d
parent 66bc5ec2
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@
#define DIRECT_PCM_NUM_FRAGMENTS 2
#define COMPRESS_PLAYBACK_VOLUME_MAX 0x2000
#define VOIP_PLAYBACK_VOLUME_MAX 0x2000
#define PCM_PLAYBACK_VOLUME_MAX 0x2000
#define DSD_VOLUME_MIN_DB (-110)

#define PROXY_OPEN_RETRY_COUNT           100
@@ -443,6 +444,7 @@ static int last_known_cal_step = -1 ;
static int check_a2dp_restore_l(struct audio_device *adev, struct stream_out *out, bool restore);
static int out_set_compr_volume(struct audio_stream_out *stream, float left, float right);
static int out_set_voip_volume(struct audio_stream_out *stream, float left, float right);
static int out_set_pcm_volume(struct audio_stream_out *stream, float left, float right);

static bool may_use_noirq_mode(struct audio_device *adev, audio_usecase_t uc_id,
                               int flags __unused)
@@ -3094,6 +3096,8 @@ int start_output_stream(struct stream_out *out)
        // apply volume for voip playback after path is set up
        if (out->usecase == USECASE_AUDIO_PLAYBACK_VOIP)
            out_set_voip_volume(&out->stream, out->volume_l, out->volume_r);
        else if ((out->usecase == USECASE_AUDIO_PLAYBACK_LOW_LATENCY || out->usecase == USECASE_AUDIO_PLAYBACK_DEEP_BUFFER))
            out_set_pcm_volume(&out->stream, out->volume_l, out->volume_r);
    } else {
        platform_set_stream_channel_map(adev->platform, out->channel_mask,
                   out->pcm_device_id, &out->channel_map_param.channel_map[0]);
@@ -4150,6 +4154,33 @@ static int out_set_voip_volume(struct audio_stream_out *stream, float left,
    return 0;
}

static int out_set_pcm_volume(struct audio_stream_out *stream, float left,
                              float right)
{
    struct stream_out *out = (struct stream_out *)stream;
    /* Volume control for pcm playback */
    if (left != right) {
        return -EINVAL;
    } else {
        char mixer_ctl_name [128];
        struct audio_device *adev = out->dev;
        struct mixer_ctl *ctl;
        int pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
        snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Playback %d Volume", pcm_device_id);
        ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
        if (!ctl) {
            ALOGE("%s : Could not get ctl for mixer cmd - %s", __func__, mixer_ctl_name);
            return -EINVAL;
        }
        int volume = (int) (left * PCM_PLAYBACK_VOLUME_MAX);
        mixer_ctl_set_value(ctl, 0, volume);

        ALOGV("%s : Pcm set volume value %d", __func__, volume);

        return 0;
    }
}

static int out_set_volume(struct audio_stream_out *stream, float left,
                          float right)
{
@@ -4199,6 +4230,13 @@ static int out_set_volume(struct audio_stream_out *stream, float left,
        out->volume_l = left;
        out->volume_r = right;
        return ret;
    } else {
        /* Volume control for pcm playback */
        if (!out->standby)
            ret = out_set_pcm_volume(stream, left, right);
        out->volume_l = left;
        out->volume_r = right;
        return ret;
    }

    return -ENOSYS;