mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
tutorial: fix s16 scale and add some docs
The float -> s16 scale value is 32767 or 32768 with clamping. Fix this and add some docs. Fixes #3838
This commit is contained in:
parent
8657caa0ac
commit
cb2b7af8fd
1 changed files with 7 additions and 1 deletions
|
|
@ -50,7 +50,13 @@ static void on_process(void *userdata)
|
||||||
if (data->accumulator >= M_PI_M2)
|
if (data->accumulator >= M_PI_M2)
|
||||||
data->accumulator -= M_PI_M2;
|
data->accumulator -= M_PI_M2;
|
||||||
|
|
||||||
val = sin(data->accumulator) * DEFAULT_VOLUME * 16767.f;
|
/* sin() gives a value between -1.0 and 1.0, we first apply
|
||||||
|
* the volume and then scale with 32767.0 to get a 16 bits value
|
||||||
|
* between [-32767 32767].
|
||||||
|
* Another common method to convert a double to
|
||||||
|
* 16 bits is to multiple by 32768.0 and then clamp to
|
||||||
|
* [-32768 32767] to get the full 16 bits range. */
|
||||||
|
val = sin(data->accumulator) * DEFAULT_VOLUME * 32767.0;
|
||||||
for (c = 0; c < DEFAULT_CHANNELS; c++)
|
for (c = 0; c < DEFAULT_CHANNELS; c++)
|
||||||
*dst++ = val;
|
*dst++ = val;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue