import math
import numpy
from demodulate.cfg import *

def gen_tone(pattern, WPM):
	cycles_per_sample = MORSE_FREQ/SAMPLE_FREQ
	radians_per_sample = cycles_per_sample * 2 * math.pi
	elements_per_second = WPM * 50.0 / 60.0
	samples_per_element = int(SAMPLE_FREQ/elements_per_second)
	
	length = samples_per_element * len(pattern)
	# Empty returns array containing random stuff, so we NEED to overwrite it
	data = numpy.empty(length, dtype=numpy.float32)
	for i in xrange(length):
		keyed = pattern[int(i/samples_per_element)]
		#keyed = 1
		data[i] = 0 if not keyed else (radians_per_sample * i)
	
	data = numpy.sin(data)
	
	
	return data

import math
import numpy
from demodulate.cfg import *

def gen_tone(pattern, WPM):
	cycles_per_sample = MORSE_FREQ/SAMPLE_FREQ
	radians_per_sample = cycles_per_sample * 2 * math.pi
	elements_per_second = WPM * 50.0 / 60.0
	samples_per_element = int(SAMPLE_FREQ/elements_per_second)
	
	length = samples_per_element * len(pattern)
	# Empty returns array containing random stuff, so we NEED to overwrite it
	data = numpy.empty(length, dtype=numpy.float32)
	for i in xrange(length):
		keyed = pattern[int(i/samples_per_element)]
		#keyed = 1
		data[i] = 0 if not keyed else (radians_per_sample * i)
	
	data = numpy.sin(data)
	data *= 2**16-1
	data = numpy.array(data, dtype=numpy.int16)
	
	return data

Use 16 bit samples instead of float
Use 16 bit samples instead of float

  import math
  import numpy
  from demodulate.cfg import *
  
  def gen_tone(pattern, WPM):
  	cycles_per_sample = MORSE_FREQ/SAMPLE_FREQ
  	radians_per_sample = cycles_per_sample * 2 * math.pi
  	elements_per_second = WPM * 50.0 / 60.0
  	samples_per_element = int(SAMPLE_FREQ/elements_per_second)
  	
  	length = samples_per_element * len(pattern)
  	# Empty returns array containing random stuff, so we NEED to overwrite it
  	data = numpy.empty(length, dtype=numpy.float32)
  	for i in xrange(length):
  		keyed = pattern[int(i/samples_per_element)]
  		#keyed = 1
  		data[i] = 0 if not keyed else (radians_per_sample * i)
  	
  	data = numpy.sin(data)
- 	
+ 	data *= 2**16-1
+ 	data = numpy.array(data, dtype=numpy.int16)
  	
  	return data
  
Use 16 bit samples instead of float
## Code Before:
import math
import numpy
from demodulate.cfg import *

def gen_tone(pattern, WPM):
	cycles_per_sample = MORSE_FREQ/SAMPLE_FREQ
	radians_per_sample = cycles_per_sample * 2 * math.pi
	elements_per_second = WPM * 50.0 / 60.0
	samples_per_element = int(SAMPLE_FREQ/elements_per_second)
	
	length = samples_per_element * len(pattern)
	# Empty returns array containing random stuff, so we NEED to overwrite it
	data = numpy.empty(length, dtype=numpy.float32)
	for i in xrange(length):
		keyed = pattern[int(i/samples_per_element)]
		#keyed = 1
		data[i] = 0 if not keyed else (radians_per_sample * i)
	
	data = numpy.sin(data)
	
	
	return data

## Instruction:
Use 16 bit samples instead of float
## Code After:
import math
import numpy
from demodulate.cfg import *

def gen_tone(pattern, WPM):
	cycles_per_sample = MORSE_FREQ/SAMPLE_FREQ
	radians_per_sample = cycles_per_sample * 2 * math.pi
	elements_per_second = WPM * 50.0 / 60.0
	samples_per_element = int(SAMPLE_FREQ/elements_per_second)
	
	length = samples_per_element * len(pattern)
	# Empty returns array containing random stuff, so we NEED to overwrite it
	data = numpy.empty(length, dtype=numpy.float32)
	for i in xrange(length):
		keyed = pattern[int(i/samples_per_element)]
		#keyed = 1
		data[i] = 0 if not keyed else (radians_per_sample * i)
	
	data = numpy.sin(data)
	data *= 2**16-1
	data = numpy.array(data, dtype=numpy.int16)
	
	return data
