Пример #1
0
def sinewave():
    samples = 1024.0
    amplitude = 2047.0  # P-P /2

    i = 0
    datalist = []
    while i < samples:
        value = numpy.sin((2 * numpy.pi) * (i / samples)) * amplitude
        datalist.append(int(round(value)))
        i = i + 1
    # print datalist
    p2c.print_c_list('int16_t', 'wt_sinewave', datalist)
Пример #2
0
def sinewave() :
    samples=1024.0
    amplitude=2047.0    # P-P /2

    i=0
    datalist=[]
    while i < samples :
        value=numpy.sin((2*numpy.pi)*(i/samples))*amplitude 
        datalist.append(int(round(value)))
        i=i+1
    # print datalist
    p2c.print_c_list('int16_t', 'wt_sinewave', datalist)   
Пример #3
0
def phasetable() :
    keys=12
    fractions=64   # steps in between each half note
    base_freq=2093   # frequency of C7, base note of the highest supported octave
    base_key=96   # MIDI key

    pcm_freq=40178.0    # PCM playback sample rate
    pcm_step_max=2**32 # 32 bit phase counters

    i=0             # counter

    datalist=[]

    while i <= ( keys*fractions ) :
        freq=base_freq*(2.0**(1.0/(keys*fractions)))**i
        step=int(round(pcm_step_max/(pcm_freq/freq)))
        # print i, freq, step
        datalist.append(step)
        i=i+1

    p2c.print_c_list('const uint32_t', 'phasetable', datalist)
Пример #4
0
def phasetable():
    keys = 12
    fractions = 64  # steps in between each half note
    base_freq = 2093  # frequency of C7, base note of the highest supported octave
    base_key = 96  # MIDI key

    pcm_freq = 40178.0  # PCM playback sample rate
    pcm_step_max = 2**32  # 32 bit phase counters

    i = 0  # counter

    datalist = []

    while i <= (keys * fractions):
        freq = base_freq * (2.0**(1.0 / (keys * fractions)))**i
        step = int(round(pcm_step_max / (pcm_freq / freq)))
        # print i, freq, step
        datalist.append(step)
        i = i + 1

    p2c.print_c_list('const uint32_t', 'phasetable', datalist)
Пример #5
0
extrasteps=255%octaves  # extra table entries to cover the last entries in the
                         # 256 steps table.

p=0
div_list=[]
csel_list=[]

i=0     # counter
while i <= ( oct_steps * octaves + extrasteps ) :
    # find out frequency ... 
    f=int(round(base_f*(2.0**(1.0/(oct_steps)))**i ))

    # find timer divider ... 
    # x = 20M/200*f
    x = cpuclk/2/(100*f)
    csel=0x01   # AVR clock /1.
    if x > 255 :
        x = cpuclk/2/8/(100*f)
        csel=0x02   # AVR clock /8
    if x > 255 :
         x = cpuclk/2/64/(100*f)
         csel=0x03  # AVR clock /64 
    
    div_list.append(x)
    csel_list.append(csel)
    i=i+1
    # print i,f,x,csel
    
p2c.print_c_list('uint8_t', 'divider', div_list, ' PROGMEM')
p2c.print_c_list('uint8_t', 'prescaler', csel_list, ' PROGMEM')