Sound level test and visual size calibration

This example tests the audio level and video size. For audio, it produces an 80 db SPL 1000 Hz tone (note that at 1000 Hz, the frequency weighting for SPL measurement shouldn’t matter). For video, it produces a square that should be 10 degrees visual angle and tells you what the physical width should be in cm. This of course depends on correct settings for monitor width, resolution, and distance.

level test
exp_name: LevelTest
date: 2023-07-25 19_08_17.912270
file: /home/circleci/project/examples/experiments/level_test.py
participant: s
session: 0
2023-07-25 19:08:17,912 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2023-07-25 19:08:17,913 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2023-07-25 19:08:18,102 - WARNING - Expyfun: Mismatch between reported stim sample rate (24414) and device sample rate (44100.0). Nothing will be done about this because suppress_resamp is "True"
2023-07-25 19:08:18,102 - INFO    - Expyfun: Setting up screen
2023-07-25 19:08:18,134 - EXP     - Expyfun: Set screen visibility True
2023-07-25 19:08:18,148 - INFO    - Initialized [1400  900] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f1a95b502b0>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2023-07-25 19:08:18,148 - INFO    - Expyfun: Initializing dummy triggering mode
2023-07-25 19:08:18,150 - INFO    - Expyfun: Initialization complete
2023-07-25 19:08:18,150 - EXP     - Expyfun: Participant: s
2023-07-25 19:08:18,150 - EXP     - Expyfun: Session: 0
2023-07-25 19:08:18,164 - EXP     - Expyfun: Loading 882000 samples to buffer
2023-07-25 19:08:18,245 - EXP     - Expyfun: Starting stimuli: flipping screen and playing audio
2023-07-25 19:08:18,247 - EXP     - Stamping TTL triggers: [1]
2023-07-25 19:08:18,259 - EXP     - Expyfun: Audio stopped and reset.
2023-07-25 19:08:18,259 - INFO    - Expyfun: Exiting
2023-07-25 19:08:18,265 - EXP     - Expyfun: Audio stopped and reset.

# Author: Ross Maddox <rkmaddox@uw.edu>
#
# License: BSD (3-clause)

import numpy as np

from expyfun import ExperimentController, building_doc
from expyfun.visual import Rectangle
import expyfun.analyze as ea

print(__doc__)


with ExperimentController('LevelTest', full_screen=True, noise_db=-np.inf,
                          participant='s', session='0', output_dir=None,
                          suppress_resamp=True, check_rms=None,
                          stim_db=80, version='dev') as ec:
    tone = (0.01 * np.sqrt(2.) *
            np.sin(2 * np.pi * 1000. * np.arange(0, 10, 1. / ec.fs)))
    assert np.allclose(np.sqrt(np.mean(tone * tone)), 0.01)
    square = Rectangle(ec, (0, 0, 10, 10), units='deg', fill_color='r')
    cm = np.diff(ec._convert_units([[0, 5], [0, 5]], 'deg', 'pix'),
                 axis=-1)[0] / ec.dpi / 0.39370
    ec.load_buffer(tone)  # RMS == 0.01
    pressed = None
    screenshot = None
    while pressed != '8':  # enable a clean quit if required
        square.draw()
        ec.screen_text('Width: {} cm'.format(np.round(2 * cm, 1)), wrap=False)
        ec.screen_text('Output level: {} dB'.format(ec.stim_db), wrap=True)
        screenshot = ec.screenshot() if screenshot is None else screenshot
        t1 = ec.start_stimulus(start_of_trial=False)  # skip checks
        pressed = ec.wait_one_press(10)[0] if not building_doc else '8'
        ec.flip()
        ec.wait_one_press(0.5 if not building_doc else 0.)
        ec.stop()

ea.plot_screen(screenshot)

Total running time of the script: ( 0 minutes 0.437 seconds)

Gallery generated by Sphinx-Gallery