#!/usr/bin/python # -*- coding: utf-8 -*- import math header = '''/* Generated file */ #include const uint16_t sin_tab[] = {{{0:s} }}; ''' def generate(): s = '' for n in range(0,256): if (n % 16) == 0: s += '\n ' a = float(n) * math.pi / 128.0 v = int (round (1000.0 * (1.0 + math.sin (a)))); s += '{0:+6d},'.format(v) return s if __name__ == '__main__': s = generate() f = open ('sin.c','w') f.write(header.format(s)) f.close()