Skip to content

Commit 0ed0dba

Browse files
singalsuslawblauciak
authored andcommitted
Volume: Simplify volume synchronization to host
This patch removes a trivial function vol_update() and alters vol_sync_host() to update all channels the same time into the host data structure instead of per channel updates. There is no other change to component operation. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent a7aa557 commit 0ed0dba

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

src/audio/volume/volume.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,27 @@
4444
/**
4545
* \brief Synchronize host mmap() volume with real value.
4646
* \param[in,out] cd Volume component private data.
47-
* \param[in] chan Channel number.
47+
* \param[in] num_channels Update channels 0 to num_channels -1.
4848
*/
49-
static void vol_sync_host(struct comp_data *cd, uint32_t chan)
49+
static void vol_sync_host(struct comp_data *cd, unsigned int num_channels)
5050
{
51-
if (!cd->hvol)
51+
int n;
52+
53+
if (!cd->hvol) {
54+
tracev_volume("vol_sync_host() Warning: null hvol, no update");
5255
return;
56+
}
5357

54-
if (chan < SOF_IPC_MAX_CHANNELS) {
55-
cd->hvol[chan].value = cd->volume[chan];
58+
if (num_channels < SOF_IPC_MAX_CHANNELS) {
59+
for (n = 0; n < num_channels; n++)
60+
cd->hvol[n].value = cd->volume[n];
5661
} else {
57-
trace_volume_error("vol_sync_host() error: "
58-
"chan = %u < SOF_IPC_MAX_CHANNELS", chan);
62+
trace_volume_error("vol_sync_host() error: channels count %d"
63+
" exceeds SOF_IPC_MAX_CHANNELS",
64+
num_channels);
5965
}
6066
}
6167

62-
/**
63-
* \brief Update volume with target value.
64-
* \param[in,out] cd Volume component private data.
65-
* \param[in] chan Channel number.
66-
*/
67-
static void vol_update(struct comp_data *cd, uint32_t chan)
68-
{
69-
cd->volume[chan] = cd->tvolume[chan];
70-
vol_sync_host(cd, chan);
71-
}
72-
7368
/**
7469
* \brief Ramps volume changes over time.
7570
* \param[in,out] data Volume base component device.
@@ -114,8 +109,8 @@ static enum task_state vol_work(void *data)
114109
if (cd->volume[i] < cd->tvolume[i]) {
115110
/* ramp up, check if ramp completed */
116111
if (vol >= cd->tvolume[i] || vol >= cd->vol_max) {
117-
vol_update(cd, i);
118112
cd->ramp_increment[i] = 0;
113+
cd->volume[i] = cd->tvolume[i];
119114
} else {
120115
cd->volume[i] = vol;
121116
again = 1;
@@ -124,25 +119,26 @@ static enum task_state vol_work(void *data)
124119
/* ramp down */
125120
if (vol <= 0) {
126121
/* cannot ramp down below 0 */
127-
vol_update(cd, i);
128122
cd->ramp_increment[i] = 0;
123+
cd->volume[i] = cd->tvolume[i];
129124
} else {
130125
/* ramp completed ? */
131126
if (vol <= cd->tvolume[i] ||
132127
vol <= cd->vol_min) {
133-
vol_update(cd, i);
134128
cd->ramp_increment[i] = 0;
129+
cd->volume[i] = cd->tvolume[i];
135130
} else {
136131
cd->volume[i] = vol;
137132
again = 1;
138133
}
139134
}
140135
}
141136

142-
/* sync host with new value */
143-
vol_sync_host(cd, i);
144137
}
145138

139+
/* sync host with new value */
140+
vol_sync_host(cd, cd->channels);
141+
146142
/* do we need to continue ramping */
147143
if (again)
148144
return SOF_TASK_STATE_RESCHEDULE;
@@ -679,8 +675,7 @@ static int volume_prepare(struct comp_dev *dev)
679675
goto err;
680676
}
681677

682-
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
683-
vol_sync_host(cd, i);
678+
vol_sync_host(cd, PLATFORM_MAX_CHANNELS);
684679

685680
/* Set current volume to min to ensure ramp starts from minimum
686681
* to previous volume request. Copy() checks for ramp started

0 commit comments

Comments
 (0)