Fix integer underflows when changing sample rate/limit
Tidy up demo.c fixes