#!/usr/bin/python # -*- coding: utf-8 -*- import math header = '''/* Generated file */ #include const int16_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 (480.0 * (math.sin (a)))); s += '{0:+6d},'.format(v) return s def dtmf(): f0 = 24000.0 mf = math.pow (2.0, 32.0) / f0 dtmf_l = [ 941, 852, 770, 697 ] dtmf_h = [1209, 1336, 1477, 1633] s = 'const unsigned dtmf_low_tab [] = {' for f in dtmf_l: n = int (f * mf) s += ' 0x{0:08x},'.format (n) s += ' };\n' s += 'const unsigned dtmf_hi__tab [] = {' for f in dtmf_h: n = int (f * mf) s += ' 0x{0:08x},'.format (n) s += ' };\n' return s if __name__ == '__main__': s = generate() f = open ('sin.c','w') f.write(header.format(s)) f.write(dtmf()) f.close()