Skip to content

fast 16bit clamping arithmetic? (was: "Inline decorator?") #14110

Answered by Lana-chan
Lana-chan asked this question in ESP32
Discussion options

You must be logged in to vote

clamping bit values after a bit shift. that's what i'm missing. this is the actual full code now

			if vol < 0:
				bsmp = bsmp = (bsmp & 0b1000000000000000) | (((bsmp & 0b0111111111111111) << int(abs(vol))) & 0b0111111111111111)
			else:
				bsmp = (bsmp & 0b1000000000000000) | ((bsmp & 0b0111111111111111) >> vol)
				if (bsmp & 0b1000000000000000) != 0:
					bsmp |= (0b111111111111111 << 15-vol)
			bsmp_int = 0 - (0b10000000000000000 - int(bsmp & 0b1111111111111111)) if bsmp & 0b1000000000000000 else bsmp
			buf_int = 0 - (0b10000000000000000 - int(buf[i] & 0b1111111111111111)) if buf[i] & 0b1000000000000000 else buf[i]
			res = bsmp_int + buf_int
			res = (_INT_MINVAL if res < _INT_MINVAL

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
4 replies
@dpgeorge
Comment options

@Lana-chan
Comment options

@Lana-chan
Comment options

@Lana-chan
Comment options

Answer selected by Lana-chan
Comment options

You must be logged in to vote
1 reply
@Lana-chan
Comment options

Comment options

You must be logged in to vote
1 reply
@Lana-chan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
ESP32
Labels
None yet
4 participants