I have two raw sound streams that I need to add together. For the purposes of this question, we can assume they are the same bitrate and bit depth (say 16 bit sample, 44.1k
I did the following thing:
MAX_VAL = Full 8 or 16 or whatever value
dst_val = your base audio sample
src_val = sample to add to base
Res = (((MAX_VAL - dst_val) * src_val) / MAX_VAL) + dst_val
Multiply the left headroom of src by the MAX_VAL normalized destination value and add it. It will never clip, never be less loud and sound absolutely natural.
Example:
250.5882 = (((255 - 180) * 240) / 255) + 180
And this sounds good :)