-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perform volume scaling in capture/playback
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
543ddcb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S16NE
translates to Signed 16 bit Native Endian. Why are you sampling it as unsigned -uint16_t
?Doing it wrong should cause audible distortion.
I don't think that
memcpy()
of a single sample is needed. Just castp
asfloat*
insidecase
block. Thevoid *
is compatible with all casts and you won't get aliasing, since you access the memory only as the given type. Think of it as separate function that takesfloat * buf
.You shouldn't need clamping in the
S16NE
case, sincefval <= 1.0
.Yeh, I know, you can't trust floats.
543ddcb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a bug. Thank you for pointing this out. Fix pushed in ae3ea44.
I was indeed afraid of aliasing warnings from a compiler. Some time ago I found that small fixed-sized
memcpy
's GCC replaces with__builtin_memcpy
, which in turn are emited as direct copy instructions, even without optimization enabled. And, I think, there was also something about memory alignment. Just dereferencing unaligned pointer to a type is undefined behavior. So I ended up usingmemcpy
trick, which should work in all cases. (Of course, it doesn't matter on x86, since it can do unaligned loads transparently).fval
could be greater than1.0
, since PulseAudio have higher-than-100% volumes.PA_VOLUME_NORM
(== 0x10000U) is 100%, while maximum allowed volume isPA_VOLUME_MAX
, which isUINT32_MAX/2
.