import math


def generate_sin_wave(sample_rate, frequency, duration, amplitude):
    """
    Generate a sinusoidal wave based on `sample_rate`, `frequency`, `duration` and `amplitude`
    `frequency` in Hertz, `duration` in seconds, the values of `amplitude` must be in range [0..1]
    """
    data = []
    samples_num = int(duration * sample_rate)
    volume = amplitude * 32767
    for n in range(samples_num):
        value = math.sin(2 * math.pi * n * frequency / sample_rate)
        data.append(int(value * volume))
    return data