#!/usr/bin/env python
from __future__ import print_function
def printf(str, *args):
    print(str % args, end='')
import math
import sys

# 
# A cassette interface is similar to a modem connected to a serial 
# port. The 1s and 0s from the serial port are converted to audio 
# tones using audio frequency-shift keying (AFSK). A '0' bit is 
# represented as four cycles of a 1200 Hz sine wave, and a '1' bit 
# as eight cycles of 2400 Hz. This gives a data rate of 300 baud. 
# Each frame starts with one start bit (a '0') followed by eight 
# data bits (least significant bit first) followed by two stop bits 
# ('1's). So each frame is 11 bits, for a data rate of  27 3⁄11 
# bytes per second.
#

samplerate=44100

hz0=1200.0
cycles0=4
hz1=2400.0
cycles1=8

rate0=1.0/(hz0/samplerate)
rate1=1.0/(hz1/samplerate)

steps=rate0*cycles0

if steps<>int(steps):
    sys.exit("Error - steps not integer, please change samplerate")

offset=127
gain=100.0

print ("ZERO=$(echo -e \"",end="")
for i in range(int(steps)):
    printf("\\x%02x", offset+round(gain*math.sin(i*math.pi*2/rate0),0))
print ("\")")

print ("ONE=$(echo -e \"",end="")
for i in range(int(steps)):
    printf("\\x%02x", offset+round(gain*math.sin(i*math.pi*2/rate1),0))
print ("\")")
