#! /usr/bin/env python

from Tkinter import *
from tkSnack import *
root = Tkinter.Tk()

initializeSnack(root);
import sys;

length=len(sys.argv);

if length>1:
	path=sys.argv[1];
else:
	print "pitch2.py input [start end min max framelength]";
	sys.exit();

if length>2:
	startsample=int(sys.argv[2]);
else:
	startsample=0;

if length>3:
	endsample=int(sys.argv[3]);
else:
	endsample=0;

if length>4:
	min=int(sys.argv[4]);
else:
	min=60;

if length>5:
	max=int(sys.argv[5]);
else:
	max=600;

if length>6:
	flength=float(sys.argv[6]);
else:
	flength=0.01;

#guess min is 0.01
if(flength>0.01):
	flength=0.01;


mysound=Sound(load=path);
mysound.convert(encoding='Lin16',channels='1');

if endsample == 0:
	endsample=mysound.length();
elif endsample <0:
	endsample=mysound.length()+endsample;

#print endsample;
#framelength=0.01, 0.1 has error 
#windowlength=0.025,0 has error
resultList=mysound.pitch(method='ESPS',framelength=flength,minpitch=min,maxpitch=max,start=startsample,end=endsample);


for i in resultList:
	print i;