Skip to content

Commit

Permalink
Added a test of output for inverted controls that should fail currently
Browse files Browse the repository at this point in the history
  • Loading branch information
ansaminard committed Dec 10, 2024
1 parent 7e7859b commit 26dec54
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ charge 12 24 36 48
0.05 0 0 0 0
0.1 0 20 40 60
0.2 20 20 50 40
0.3 50 30 50 60
10.0 50 30 50 60
####
c:/data/data_charge10.dat
100
5000
charge 12 24 36 48
0.05 20 30 40 50
0.1 10 30 50 -60
0.2 30 40 50 -30
0.3 30 40 70 0
10.0 30 40 70 0
####
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
EXP_LEVEL_OCTAVE_BAND_500 = 44.2
EXP_LEVEL_OCTAVE_BAND_1000 = 46.7
EXP_LEVEL_OCTAVE_BAND_2000 = 50.7
EXP_LEVEL_OCTAVE_BAND_500_INVCON = 51.2
EXP_LEVEL_OCTAVE_BAND_1000_INVCON = 50.3
EXP_LEVEL_OCTAVE_BAND_2000_INVCON = 35.5
EXP_ORDER_LEVEL62 = 3.9810717055349695e-05
EXP_ORDER_LEVEL33_INVERTED = 0.00039810717055349735
EXP_ORDER_LEVEL22_FROM_ACCEL = 0.0016218100973589282
Expand Down Expand Up @@ -465,6 +468,48 @@ def test_source_harmonics_two_parameters_get_output(dpf_sound_test_server):
level = 10 * np.log10(psd_squared_band.sum() * delat_f / REF_ACOUSTIC_POWER)
assert level == pytest.approx(EXP_LEVEL_OCTAVE_BAND_2000, abs=3.0)

# Test output with another source file with inverted controls.
source_obj.load_source_harmonics_two_parameters(
pytest.data_path_sound_composer_harmonics_source_2p_inverted_controls_in_container,
)

source_obj.process(sampling_frequency=44100.0)
f_output = source_obj.get_output()
assert isinstance(f_output, Field)
assert len(f_output.data) / 44100.0 == pytest.approx(3.0)

# Compute the power spectral density over the output signal.
psd = PowerSpectralDensity(
input_signal=f_output,
fft_size=8192,
window_type="HANN",
window_length=8192,
overlap=0.75,
)
psd.process()
psd_squared, psd_freq = psd.get_PSD_squared_linear_as_nparray()
delat_f = psd_freq[1] - psd_freq[0]

# Check the sound power level in the octave bands centered at 500, 1000 and 2000 Hz.
# Due to the non-deterministic nature of the produced signal, tolerance is set to 3 dB.
psd_squared_band = psd_squared[
(psd_freq >= 500 * 2 ** (-1 / 2)) & (psd_freq < 500 * 2 ** (1 / 2))
]
level = 10 * np.log10(psd_squared_band.sum() * delat_f / REF_ACOUSTIC_POWER)
assert level == pytest.approx(EXP_LEVEL_OCTAVE_BAND_500_INVCON, abs=3.0)

psd_squared_band = psd_squared[
(psd_freq >= 1000 * 2 ** (-1 / 2)) & (psd_freq < 1000 * 2 ** (1 / 2))
]
level = 10 * np.log10(psd_squared_band.sum() * delat_f / REF_ACOUSTIC_POWER)
assert level == pytest.approx(EXP_LEVEL_OCTAVE_BAND_1000_INVCON, abs=3.0)

psd_squared_band = psd_squared[
(psd_freq >= 2000 * 2 ** (-1 / 2)) & (psd_freq < 2000 * 2 ** (1 / 2))
]
level = 10 * np.log10(psd_squared_band.sum() * delat_f / REF_ACOUSTIC_POWER)
assert level == pytest.approx(EXP_LEVEL_OCTAVE_BAND_2000_INVCON, abs=3.0)


def test_source_harmonics_two_parameters_get_output_unprocessed(dpf_sound_test_server):
"""Test SourceHarmonicsTwoParameters get_output method's exception."""
Expand Down

0 comments on commit 26dec54

Please sign in to comment.