# Path: pambox/utils.py
# def make_same_length(a, b, extend_first=True):
#     """Make two vectors the same length.
# 
#     Parameters
#     ----------
#     a,b : array_like
#         Arrays to make of the same length.
#     extend_first : bool, optional
#         Zero-pad the first array if it is the shortest if `True`. Otherwise,
#         cut array `b` to the length of `a`. (Default value = True)
# 
#     Returns
#     -------
#     tuple of ndarrays
#         Two arrays with the same length along the last dimension.
# 
#     """
#     a = np.asarray(a)
#     b = np.asarray(b)
#     if a.shape[-1] < b.shape[-1]:
#         if extend_first:
#             c = np.zeros_like(b)
#             c[..., :a.shape[-1]] += a
#             return c, b
#         else:
#             return a, b[..., :a.shape[-1]]
#     else:
#         c = np.zeros_like(a)
#         c[..., :b.shape[-1]] += b
#         return a, c
# 
# def setdbspl(x, lvl, ac=False, offset=0.0):
#     """Sets the level of signal in dB SPL, along its last dimension.
# 
#     Parameters
#     ----------
#     x : array_like
#         Signal.
#     lvl : float
#         Level, in dB SPL, at which to set the signal.
#     ac : bool
#         Calculate the AC RMS power of the signal by default (`ac=True`),
#         e.g. the mean is removed. If  `False`, considers the non-RMS power.
#         (Default value = False)
#     offset : float
#         Level, in dB SPL, corresponding to an RMS of 1. By default, an RMS of
#         1 corresponds to 0 dB SPL, i.e. the default is 0.
# 
#     Returns
#     -------
#     ndarray
#         Signal of the same dimension as the original.
#     """
#     x = np.asarray(x)
#     if np.isinf(lvl) and lvl < 0:
#         return np.zeros_like(x)
# 
#     if x.ndim > 1:
#         rms_value = rms(x, ac)[(slice(None),) + (x.ndim - 1) * (np.newaxis, )]
#     else:
#         rms_value = rms(x, ac)
#     return x / rms_value * 10. ** ((lvl - float(offset)) / 20.)
# 
# def int2srt(x, y, srt_at=50.0):
#     """Finds intersection using linear interpolation.
# 
#     This function finds the x values at which a curve intersects with a
#     constant value.
# 
#     Parameters
#     ----------
#     x : array_like
#         "x" values
#     y : array_like
#         "y" values
#     srt_at : float
#          Value of `y` at which the interception is calculated. (Default value
#          = 50.0)
# 
#     Returns
#     -------
#     float
# 
#     """
#     x = np.asarray(x)
#     y = np.asarray(y)
# 
#     if x.shape != y.shape:
#         raise ValueError('Inputs of different lenghts.')
#     srt_at = np.float(srt_at)
#     idx = np.nonzero(np.diff(y >= srt_at))[0]
#     if not idx.any() and y[0] == srt_at:
#         return x[0]
# 
#     if len(idx) >= 1:
#         idx = idx[0]
#         srt = x[idx] + (srt_at - y[idx]) * (x[idx + 1] - x[idx]) \
#             / (y[idx + 1] - y[idx])
#     else:
#         srt = np.nan
#     return float(srt)


from datetime import datetime
from functools import partial
from itertools import product
from IPython import parallel as ipyparallel
from six.moves import zip
from pambox.utils import make_same_length, setdbspl, int2srt
import logging
import os
import os.path
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import six
            import os

        if not self.adjust_levels_bef_proc:
            target, masker = self.adjust_levels(target, masker, snr)
        return target, target + masker, masker

    def adjust_levels(self, target, masker, snr):
        """
        Adjusts level of target and maskers.

        Uses the `self.fixed_level` as the reference level for the target and
        masker. If `self.fixed_target` is True, the masker level is varied to
        set the required SNR, otherwise the target level is changed.

        :param target: ndarray
            Target signal.
        :param masker: ndarray
            Masker signal.
        :param snr: float
            SNR at which to set the target and masker.
        :return: tuple
            Level adjusted `target` and `masker`.
        """

        target_level = self.fixed_level
        masker_level = self.fixed_level
        if self.fixed_target:
            masker_level -= snr
        else:
            target_level += snr
        target = setdbspl(target, target_level)

# Path: pambox/utils.py
# def make_same_length(a, b, extend_first=True):
#     """Make two vectors the same length.
# 
#     Parameters
#     ----------
#     a,b : array_like
#         Arrays to make of the same length.
#     extend_first : bool, optional
#         Zero-pad the first array if it is the shortest if `True`. Otherwise,
#         cut array `b` to the length of `a`. (Default value = True)
# 
#     Returns
#     -------
#     tuple of ndarrays
#         Two arrays with the same length along the last dimension.
# 
#     """
#     a = np.asarray(a)
#     b = np.asarray(b)
#     if a.shape[-1] < b.shape[-1]:
#         if extend_first:
#             c = np.zeros_like(b)
#             c[..., :a.shape[-1]] += a
#             return c, b
#         else:
#             return a, b[..., :a.shape[-1]]
#     else:
#         c = np.zeros_like(a)
#         c[..., :b.shape[-1]] += b
#         return a, c
# 
# def setdbspl(x, lvl, ac=False, offset=0.0):
#     """Sets the level of signal in dB SPL, along its last dimension.
# 
#     Parameters
#     ----------
#     x : array_like
#         Signal.
#     lvl : float
#         Level, in dB SPL, at which to set the signal.
#     ac : bool
#         Calculate the AC RMS power of the signal by default (`ac=True`),
#         e.g. the mean is removed. If  `False`, considers the non-RMS power.
#         (Default value = False)
#     offset : float
#         Level, in dB SPL, corresponding to an RMS of 1. By default, an RMS of
#         1 corresponds to 0 dB SPL, i.e. the default is 0.
# 
#     Returns
#     -------
#     ndarray
#         Signal of the same dimension as the original.
#     """
#     x = np.asarray(x)
#     if np.isinf(lvl) and lvl < 0:
#         return np.zeros_like(x)
# 
#     if x.ndim > 1:
#         rms_value = rms(x, ac)[(slice(None),) + (x.ndim - 1) * (np.newaxis, )]
#     else:
#         rms_value = rms(x, ac)
#     return x / rms_value * 10. ** ((lvl - float(offset)) / 20.)
# 
# def int2srt(x, y, srt_at=50.0):
#     """Finds intersection using linear interpolation.
# 
#     This function finds the x values at which a curve intersects with a
#     constant value.
# 
#     Parameters
#     ----------
#     x : array_like
#         "x" values
#     y : array_like
#         "y" values
#     srt_at : float
#          Value of `y` at which the interception is calculated. (Default value
#          = 50.0)
# 
#     Returns
#     -------
#     float
# 
#     """
#     x = np.asarray(x)
#     y = np.asarray(y)
# 
#     if x.shape != y.shape:
#         raise ValueError('Inputs of different lenghts.')
#     srt_at = np.float(srt_at)
#     idx = np.nonzero(np.diff(y >= srt_at))[0]
#     if not idx.any() and y[0] == srt_at:
#         return x[0]
# 
#     if len(idx) >= 1:
#         idx = idx[0]
#         srt = x[idx] + (srt_at - y[idx]) * (x[idx + 1] - x[idx]) \
#             / (y[idx + 1] - y[idx])
#     else:
#         srt = np.nan
#     return float(srt)


# Path: pambox/speech/experiment.py
from datetime import datetime
from functools import partial
from itertools import product
from IPython import parallel as ipyparallel
from six.moves import zip
from pambox.utils import make_same_length, setdbspl, int2srt
import logging
import os
import os.path
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import six
            import os


        if not self.adjust_levels_bef_proc:
            target, masker = self.adjust_levels(target, masker, snr)
        return target, target + masker, masker

    def adjust_levels(self, target, masker, snr):
        """
        Adjusts level of target and maskers.

        Uses the `self.fixed_level` as the reference level for the target and
        masker. If `self.fixed_target` is True, the masker level is varied to
        set the required SNR, otherwise the target level is changed.

        :param target: ndarray
            Target signal.
        :param masker: ndarray
            Masker signal.
        :param snr: float
            SNR at which to set the target and masker.
        :return: tuple
            Level adjusted `target` and `masker`.
        """

        target_level = self.fixed_level
        masker_level = self.fixed_level
        if self.fixed_target:
            masker_level -= snr
        else:
            target_level += snr
        target = setdbspl(target, target_level)

        masker = setdbspl(masker, masker_level)