コード例 #1
0
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":
        "mosqito/tests/loudness/data/ISO_532-1/Test signal 3 (1 kHz 60 dB).wav",
        "N": 4.019,
        "N_specif_file":
        "mosqito/tests/loudness/data/ISO_532-1/test_signal_3.csv",
    }

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

    # Compute Loudness
    N, N_specific = loudness_zwicker_stationary(third_spec['values'])

    # Check ISO 532-1 compliance
    assert check_compliance(N, N_specific, signal)
コード例 #2
0
def test_loudness_zwicker_3oct():
    """Test function for the script loudness_zwicker_stationary

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

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

    Outputs
    -------
    None
    """
    # Third octave levels as input for stationary loudness
    # (from ISO 532-1 annex B2)
    test_signal_1 = np.array([
        -60,
        -60,
        78,
        79,
        89,
        72,
        80,
        89,
        75,
        87,
        85,
        79,
        86,
        80,
        71,
        70,
        72,
        71,
        72,
        74,
        69,
        65,
        67,
        77,
        68,
        58,
        45,
        30.0,
    ])

    signal = {
        "data_file": "Test signal 1.txt",
        "N": 83.296,
        "N_specif_file": "tests/input/test_signal_1.csv",
    }
    N, N_specific = loudness_zwicker_stationary(test_signal_1)
    loudness = {"values": N, "specific values": N_specific}

    tst = check_compliance(loudness, signal, "./tests/output/")
    assert tst
コード例 #3
0
ファイル: SoundQuality.py プロジェクト: JosemaAlvarez/MoSQITo
    def compute_loudness(self, field_type='free'):
        """ Method to compute the loudness according to Zwicker's method
        
        Parameter
        ----------
        field-type: string
            'free' by default or 'diffuse'      
               
        """
        if self.third_spec == None:
            self.comp_3oct_spec()

        if self.is_stationary == True:
            N, N_specific = loudness_zwicker_stationary(
                self.third_spec.values, self.third_spec.axes[0].values,
                field_type)
        elif self.is_stationary == False:
            N, N_specific = loudness_zwicker_time(self.third_spec.values,
                                                  field_type)

        barks = Data1D(name='Frequency Bark scale',
                       unit='Bark',
                       values=np.linspace(0.1, 24, int(24 / 0.1)))

        if self.is_stationary == True:
            self.loudness_zwicker = Data1D(values=[N],
                                           name="Loudness",
                                           unit="Sones")
            self.loudness_zwicker_specific = DataFreq(symbol="N'",
                                                      axes=[barks],
                                                      values=N_specific,
                                                      name="Specific loudness",
                                                      unit="Sones")
        elif self.is_stationary == False:
            time = Data1D(symbol="T",
                          name="Time axis",
                          unit="s",
                          values=np.linspace(0,
                                             len(self.signal.values) / self.fs,
                                             num=N.size))

            self.loudness_zwicker = DataTime(symbol="N",
                                             axes=[time],
                                             values=N,
                                             name="Loudness",
                                             unit="Sones")
            self.loudness_zwicker_specific = DataFreq(symbol="N'",
                                                      axes=[barks, time],
                                                      values=N_specific,
                                                      name="Specific loudness",
                                                      unit="Sones")
コード例 #4
0
def comp_loudness_from_3spec(is_stationary,
                             third_spec,
                             third_axis=[],
                             field_type="free"):
    """Acoustic loudness calculation according to Zwicker method for
    stationary and time-varying signals.

    Parameters
    ----------
    is_stationary: boolean
        TRUE if the signal is stationary, FALSE if it is time-varying
    third_spec: numpy.array
        third octave spectrum
    third_axis: numpy.array
        third-octav frequency axis
    field-type: string
        'free' by default or 'diffuse'

    Outputs
    -------
    output : dict
        {
            "name": "Loudness",
            "values": N: float/numpy.array
                loudness value
            "specific values": N_specific: numpy.array
                specific loudness values
            "freqs": bark_axis: numpy.array
                frequency axis corresponding to N_specific values in bark
        }
    """

    if is_stationary == True:
        N, N_specific = loudness_zwicker_stationary(third_spec, third_axis,
                                                    field_type)
    elif is_stationary == False:
        N, N_specific = loudness_zwicker_time(third_spec, field_type)

    if third_axis == []:
        # critical band rate scale
        third_axis = np.linspace(0.1, 24, int(24 / 0.1))

    output = {
        "name": "Loudness",
        "values": N,
        "specific values": N_specific,
        "freqs": third_axis,
    }

    return output
コード例 #5
0
ファイル: comp_loudness.py プロジェクト: mglesser/MoSQITo
def comp_loudness(is_stationary, signal, fs, field_type="free"):
    """Acoustic loudness calculation according to Zwicker method for
    stationary and time-varying signals.

    Parameters
    ----------
    is_stationary: boolean
        TRUE if the signal is stationary, FALSE if it is time-varying
    signal : numpy.array
        time signal values
    fs : integer
        sampling frequency
    field-type: string
        'free' by default or 'diffuse'

    Outputs
    -------
    output : dict
        {
            "name": "Loudness",
            "values": N: float/numpy.array
                loudness value
            "specific values": N_specific: numpy.array
                specific loudness values
            "freqs": bark_axis: numpy.array
                frequency axis corresponding to N_specific values in bark
        }
    """

    if is_stationary == True:
        third_spec = comp_third_spec(is_stationary, signal, fs)
        N, N_specific = loudness_zwicker_stationary(
            third_spec["values"], third_spec["freqs"], field_type
        )
    elif is_stationary == False:
        spec_third, _, _ = calc_third_octave_levels(signal, fs)
        N, N_specific = loudness_zwicker_time(spec_third, field_type)

    # critical band rate scale
    bark_axis = np.linspace(0.1, 24, int(24 / 0.1))

    output = {
        "name": "Loudness",
        "values": N,
        "specific values": N_specific,
        "freqs": bark_axis,
    }

    return output