# Path: opensauce/helpers.py
# def round_half_away_from_zero(x):
#     """Rounds a number according to round half away from zero method
# 
#     Args:
#         x - number [float]
# 
#     Returns:
#         q - rounded number [integer]
# 
#     For example:
#        round_half_away_from_zero(3.5) = 4
#        round_half_away_from_zero(3.2) = 3
#        round_half_away_from_zero(-2.7) = -3
#        round_half_away_from_zero(-4.3) = -4
# 
#     The reason for writing our own rounding function is that NumPy uses the
#     round-half-to-even method. There is a Python round() function, but it
#     doesn't work on NumPy vectors. So we wrote our own
#     round-half-away-from-zero method here.
#     """
#     q = np.int_(np.sign(x) * np.floor(np.abs(x) + 0.5))
# 
#     return q
# 
# def convert_boolean_for_praat(b):
#     """ Convert Python boolean for use in Praat
# 
#     Praat uses "yes"/"no" or 1/0 values instead of True/False.
#     Convert True to "yes", False to "no"
#     """
#     if b == True:
#         return "yes"
#     elif b == False:
#         return "no"
#     else:
#         raise ValueError('Input must be a Boolean')


import os
import numpy as np
from subprocess import call
from opensauce.helpers import round_half_away_from_zero, convert_boolean_for_praat
            F0[idx_f] = F0_raw[min_idx]

    return F0

def praat_raw_pitch(wav_fn, praat_path, frame_shift=1, method='cc',
                    min_pitch=40, max_pitch=500, silence_threshold=0.03,
                    voice_threshold=0.45, octave_cost=0.01,
                    octave_jumpcost=0.35, voiced_unvoiced_cost=0.14,
                    kill_octave_jumps=False, interpolate=False, smooth=False,
                    smooth_bandwidth=5):
    """Return raw estimated F0 and corresponding time points using Praat

    Args:
        See praat_pitch() documentation.
        praat_raw_pitch() doesn't have the data_len and frame_precision
        arguments.

    Returns:
        t_raw  - times corresponding to raw F0 [NumPy Vector]
        F0_raw - raw F0 estimates [NumPy vector]
    """
    # Determine extension of Praat output file
    if method == 'ac':
        ext = '.praatac'
    elif method == 'cc':
        ext = '.praatcc'
    else: # pragma: no cover
        raise ValueError('Invalid Praat F0 method. Choices are {}'.format(valid_praat_f0_methods))

    # Convert Boolean variables to Praat values

# Path: opensauce/helpers.py
# def round_half_away_from_zero(x):
#     """Rounds a number according to round half away from zero method
# 
#     Args:
#         x - number [float]
# 
#     Returns:
#         q - rounded number [integer]
# 
#     For example:
#        round_half_away_from_zero(3.5) = 4
#        round_half_away_from_zero(3.2) = 3
#        round_half_away_from_zero(-2.7) = -3
#        round_half_away_from_zero(-4.3) = -4
# 
#     The reason for writing our own rounding function is that NumPy uses the
#     round-half-to-even method. There is a Python round() function, but it
#     doesn't work on NumPy vectors. So we wrote our own
#     round-half-away-from-zero method here.
#     """
#     q = np.int_(np.sign(x) * np.floor(np.abs(x) + 0.5))
# 
#     return q
# 
# def convert_boolean_for_praat(b):
#     """ Convert Python boolean for use in Praat
# 
#     Praat uses "yes"/"no" or 1/0 values instead of True/False.
#     Convert True to "yes", False to "no"
#     """
#     if b == True:
#         return "yes"
#     elif b == False:
#         return "no"
#     else:
#         raise ValueError('Input must be a Boolean')


# Path: opensauce/praat.py
import os
import numpy as np
from subprocess import call
from opensauce.helpers import round_half_away_from_zero, convert_boolean_for_praat

            F0[idx_f] = F0_raw[min_idx]

    return F0

def praat_raw_pitch(wav_fn, praat_path, frame_shift=1, method='cc',
                    min_pitch=40, max_pitch=500, silence_threshold=0.03,
                    voice_threshold=0.45, octave_cost=0.01,
                    octave_jumpcost=0.35, voiced_unvoiced_cost=0.14,
                    kill_octave_jumps=False, interpolate=False, smooth=False,
                    smooth_bandwidth=5):
    """Return raw estimated F0 and corresponding time points using Praat

    Args:
        See praat_pitch() documentation.
        praat_raw_pitch() doesn't have the data_len and frame_precision
        arguments.

    Returns:
        t_raw  - times corresponding to raw F0 [NumPy Vector]
        F0_raw - raw F0 estimates [NumPy vector]
    """
    # Determine extension of Praat output file
    if method == 'ac':
        ext = '.praatac'
    elif method == 'cc':
        ext = '.praatcc'
    else: # pragma: no cover
        raise ValueError('Invalid Praat F0 method. Choices are {}'.format(valid_praat_f0_methods))

    # Convert Boolean variables to Praat values

    kill_octave_jumps = convert_boolean_for_praat(kill_octave_jumps)