def validation_loudness_zwicker_wav(signal):
    """Test function for the script loudness_zwicker_stationary

    Test function for the script loudness_zwicker_stationary with
    .wav file as input. The input file is provided by ISO 532-1 annex
    B3, the compliance is assessed according to section 5.1 of the
    standard. One .png compliance plot is generated.

    Parameters
    ----------
    None

    Outputs
    -------
    None
    """

    # Load signal and compute third octave band spectrum
    sig, fs = load(True, signal["data_file"], calib=2 * 2**0.5)

    # Compute Loudness
    loudness = comp_loudness(True, sig, fs)

    # Check ISO 532-1 compliance
    assert check_compliance(loudness, signal)
def validation_sharpness(noise):
    """Test function for the script sharpness_din

    Test function for the script sharpness_din with .wav filesas input. 
    The input files are provided by DIN 45692_2009E
    The compliance is assessed according to chapter 6 of the standard. 
    One .png compliance plot is generated.

    Parameters
    ----------
    None

    Outputs
    -------
    None
    """

    sharpness = np.zeros((len(noise)))
    reference = np.zeros((len(noise)))

    for i in range(len(noise)):
        # Load signal
        sig, fs = load(True, noise[i]["data_file"], calib=1)

        # Compute sharpness
        S = comp_sharpness(True, sig, fs, method='din')
        sharpness[i] = S['values']

        # Load reference value
        reference[i] = noise[i]['S']

    noise_type = noise[0]["type"]

    check_compliance(sharpness, reference, noise_type)
예제 #3
0
def test_sharpness():
    """Test function for the sharpness calculation of an audio signal

    Test function for the function "comp_roughness" with 'din' method.
    The input signals come from DIN 45692_2009E. The compliance is assessed
    according to chapter 6 of the standard.
    One .png compliance plot is generated.

    Parameters
    ----------
    None

    Outputs
    -------
    None
    """

    # Input signal from DIN 45692_2009E
    signal = {
        "data_file": r"mosqito\tests\sharpness\Standard\1KHZ60DB.wav",
        "S": 1
    }

    # Load signal
    sig, fs = load(True, signal["data_file"], calib=1)

    # Compute sharpness
    sharpness = comp_sharpness(True, sig, fs, method="din")
    S = sharpness["values"]

    assert check_compliance(S, signal)
def validation_loudness_zwicker_time(signal):
    """Test function for the script loudness_zwicker_time

    Test function for the script comp_loudness with time-varying
    .wav file as input. The input file is provided by ISO 532-1 annex 
    B4 and B5, the compliance is assessed according to section 6.1 of the 
    standard. One .png compliance plot is generated.

    Parameters
    ----------
    signal: dict
        {
            "data_file": <Path to reference input signal>,
            "N_file": <Path to reference calculated loudness versus time> 
            "N_specif_file": <Path to reference calculated specific loudness>    
            "N_specif_bark": <Bark value of the reference calculation>
        }

    Outputs
    -------
    None
    """

    # Load signal and compute third octave band spectrum
    sig, fs = load(False, signal["data_file"], calib=2 * 2**0.5)

    # Compute Loudness
    loudness = comp_loudness(False, sig, fs, signal["field"])

    # Check ISO 532-1 compliance
    assert check_compliance(loudness, signal)
def test_loudness_zwicker_wav():
    """Test function for the script loudness_zwicker_stationary

    Test function for the script loudness_zwicker_stationary with
    .wav file as input. The input file is provided by ISO 532-1 annex
    B3, the compliance is assessed according to section 5.1 of the
    standard. One .png compliance plot is generated.

    Parameters
    ----------
    None

    Outputs
    -------
    None
    """
    # Test signal as input for stationary loudness
    # (from ISO 532-1 annex B3)
    signal = {
        "data_file": "tests/input/Test signal 3 (1 kHz 60 dB).wav",
        "N": 4.019,
        "N_specif_file": "tests/input/test_signal_3.csv",
    }

    # Load signal and compute third octave band spectrum
    sig, fs = load(True, signal["data_file"], calib=2 * 2**0.5)

    # Compute Loudness
    loudness = comp_loudness(True, sig, fs)

    # Check ISO 532-1 compliance
    assert check_compliance(loudness, signal, "./tests/output/")
예제 #6
0
    def import_signal(self,
                      is_stationary,
                      file,
                      calib=1,
                      mat_signal='',
                      mat_fs=''):
        """ Method to load the signal from a .wav .mat or .uff file
        
        Parameters
        ----------
        is_stationary : boolean
            TRUE if the signal is stationary, FALSE if it is time-varying
        file : string
            string path to the signal file
        calib : float
            calibration factor for the signal to be in [pa]
        mat_signal : string
            in case of a .mat file, name of the signal variable
        mat_fs : string
            in case of a .mat file, name of the sampling frequency variable

    
        Outputs
        -------
        signal : numpy.array
            time signal values
        fs : integer
            sampling frequency        
      
        """

        self.is_stationary = is_stationary
        values, self.fs = load(self.is_stationary, file, calib, mat_signal,
                               mat_fs)
        self.signal = Data1D(values=values, name="Audio signal", unit='Pa')

        self.time_axis = DataLinspace(
            initial=0,
            final=len(self.signal.values) / self.fs,
            step=1 / self.fs,
        )
예제 #7
0
def test_tnr():
    """Test function for the prominence ratio calculation of an audio signal

    Validation function for the Audio_signal class "comp_tnr" method with signal array
    as input. The input signals are generated using audacity.

    Parameters
    ----------
    None

    Outputs
    -------
    None
    """
    # Test signal as input for prominence ratio calculation
    # signals generated using audacity : white noise + tones at 200 and 2000 Hz
    # the first one is stationary, the second is time-varying
    signal = []

    signal.append({
        "is_stationary":
        True,
        "tones freq": [200, 2000],
        "data_file":
        r"tests\input\white_noise_442_1768_Hz_stationary.wav",
    })

    signal.append({
        "is_stationary":
        False,
        "data_file":
        r"tests\input\white_noise_442_1768_Hz_varying.wav",
    })

    for i in range(len(signal)):
        # Load signal
        audio, fs = load(signal[i]["is_stationary"], signal[i]["data_file"])
        # Compute tone-to-noise ratio
        tnr = comp_tnr(signal[i]["is_stationary"], audio, fs, prominence=True)
예제 #8
0
def test_loudness_zwicker_time():
    """Test function for the script loudness_zwicker_time

    Test function for the script loudness_zwicker_time with
    .wav file as input. The input file is provided by ISO 532-1 annex
    B4 and B5, the compliance is assessed according to section 6.1 of the
    standard. One .png compliance plot is generated.

    Parameters
    ----------
    None

    Outputs
    -------
    None
    """
    # Test signal as input for time-varying loudness
    # (from ISO 532-1 annex B4)
    signal = {
        "data_file":
        "tests/input/Test signal 6 (tone 250 Hz 30 dB - 80 dB).wav",
        "xls":
        "tests/input/Results and tests for synthetic signals (time varying loudness).xlsx",
        "tab": "Test signal 6",
        "N_specif_bark": 2.5,
        "field": "free",
    }

    # Load signal and compute third octave band spectrum
    sig, fs = load(False, signal["data_file"], calib=2 * 2**0.5)

    # Compute Loudness
    loudness = comp_loudness(False, sig, fs, signal["field"])

    # Check ISO 532-1 compliance
    assert check_compliance(loudness, signal, "./tests/output/")
예제 #9
0
        min frequency of the output spectrum
    fmax : float
        max frequency of the output spectrum
    n : int
        number of bands pr octave


    Outputs
    --------
    spectrum : ndarray
        nth octave band spectrum of signal sig [Pa]
    freq : ndarray
        Corresponding nth octave bands center frequencies
    """

    f_dict = getFrequencies(fmin, fmax, n)
    filters = designFilters(f_dict, fs, plot=False)
    spectrum = analyseData(filters, signal, f_dict, plot=False)

    freq = [nominal_center_freq(f, n) for f in f_dict["f"][:, 1]]

    return spectrum


if __name__ == "__main__":
    signal, fs = load(
        True,
        "./validations/loudness_zwicker/data/ISO_532-1/Test signal 5 (pinknoise 60 dB).wav",
        calib=2 * 2**0.5,
    )
    spectrum = comp_nth_spec(signal, fs)
예제 #10
0
    def __init__(self, file, is_stationary=False, calib=1, mat_signal="", mat_fs=""):
        """Constructor of the class. Loads the signal from a .wav .mat or .uff file

        Parameters
        ----------
        self : Audio object
            Object from the Audio class
        file : string
            string path to the signal file
        is_stationary : boolean
            TRUE if the signal is stationary, FALSE if it is time-varying
        calib : float
            calibration factor for the signal to be in [pa]
        mat_signal : string
            in case of a .mat file, name of the signal variable
        mat_fs : string
            in case of a .mat file, name of the sampling frequency variable

        """

        # Import audio signal
        values, fs = load(
            is_stationary,
            file,
            calib=calib,
            mat_signal=mat_signal,
            mat_fs=mat_fs,
        )

        # Create Data object for time axis
        time_axis = DataLinspace(
            name="time",
            unit="s",
            initial=0,
            final=(len(values) - 1) / fs,
            number=len(values),
            include_endpoint=True,
        )

        # Create audio signal Data object and populate the object
        self.fs = fs
        self.is_stationary = is_stationary
        self.signal = DataTime(
            name="Audio signal",
            symbol="x",
            unit="Pa",
            normalizations={"ref": 2e-5},
            axes=[time_axis],
            values=values,
        )

        # Init physical metrics attributes
        self.third_spec = None
        self.level = None
        self.welch = None

        # Init physiological metrics attributes
        self.loudness_zwicker = None
        self.loudness_zwicker_specific = None
        self.sharpness = dict()
        self.roughness = dict()
        self.tonality = dict()