#!/bin/env python

import math
import sys
import struct

PERIOD=256
VMAX=2**16
vals = [0] * PERIOD

if len(sys.argv) == 1:
    sys.stderr.write("usage: {} CMD\n".format(sys.argv[0]))
    sys.exit(1)
    
if sys.argv[1] == 'isin':
    for i in range(PERIOD):
        vals[i] = math.sin(i * 2 * math.pi / PERIOD)
elif sys.argv[1] == 'qsin':
    for i in range(PERIOD):
        vals[i] = math.sin((i + PERIOD / 4) * 2 * math.pi / PERIOD)
else:
    sys.stderr.write("unknown command\n")
    sys.exit(1)

for i in range(PERIOD):
    # Normalize between [0:1]
    vals[i] = (1.0 + vals[i]) / 2
    # Convert to ushort
    vals[i] *= VMAX - 1
    sys.stdout.write(struct.pack('H', vals[i]))

    
