Solution:
The sgn function should only be for the sin function
int a = amplitude_scale * sgn(sin(phase)) * maxval;