Audio sample rate test#

This example tests the TDT sample rate, which we expect to be 24414.0625. To test this:

  1. Connect the TDT audio output to the sound card input. This can be on the same machine that the TDT is connected to, or a different one. In most cases you will need a 1/4” male to 1/8” male cable running from the TDT headphone monitor to the recording computer’s line input.

  2. Start Audacity on the sound-card machine.

  3. Configure the sound-card machine and/or Audacity to record from the sound card input.

  4. Tell Audacity to record.

  5. Run this script. It should take about 40 seconds at 24414 sample rate.

  6. When the script completes, stop the Audacity recording.

  7. Visually inspect the audacity recording for the time of the two sinc peaks. One peak should occur toward the beginning and the other toward the end.

  8. The sound that was played put 1e6 (1,000,000) samples between the two peaks. So you can get the effective sample rate as:

    \[f_s = \frac{1000000}{t_{stop} - t_{start}}\]

    For example, Eric’s RM1 (2017/01/10) had a start time of 19.854330 sec and an end time of 60.813690 sec for a difference of of 40.95936, yielding an effective sample rate of 24414.44 Hz.

If the audio output can also be connected simultaneously to other equipment, e.g., an EEG system, the output can be split (or left/right outputs used) to test multiple system synchronization at once.

exp_name: FsTest
date: 2024-11-19 15_32_48.464271
file: /home/circleci/project/examples/sync/sample_rate_test.py
participant: s
session: 0
2024-11-19 15:32:48,464 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2024-11-19 15:32:48,465 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2024-11-19 15:32:48,622 - 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"
2024-11-19 15:32:48,622 - INFO    - Expyfun: Setting up screen
2024-11-19 15:32:48,651 - EXP     - Expyfun: Set screen visibility True
2024-11-19 15:32:48,661 - INFO    - Initialized [800 600] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f25553adba0>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2024-11-19 15:32:48,661 - INFO    - Expyfun: Initializing dummy triggering mode
2024-11-19 15:32:48,662 - INFO    - Expyfun: Initialization complete
2024-11-19 15:32:48,662 - EXP     - Expyfun: Participant: s
2024-11-19 15:32:48,662 - EXP     - Expyfun: Session: 0
2024-11-19 15:32:48,663 - EXP     - Expyfun: Stamp trial ID to ec_id  :
2024-11-19 15:32:48,663 - EXP     - Expyfun: Stamp trial ID to ttl_id : [0]
2024-11-19 15:32:48,664 - EXP     - Stamping TTL triggers: [4]
2024-11-19 15:32:48,690 - EXP     - Expyfun: Loading 2000002 samples to buffer
Starting stimulus.
2024-11-19 15:32:48,701 - EXP     - Expyfun: Starting stimuli: flipping screen and playing audio
2024-11-19 15:32:48,702 - EXP     - Stamping TTL triggers: [1]
Stimulus started. Please wait 23 seconds.
2024-11-19 15:32:48,713 - EXP     - Expyfun: Audio stopped and reset.
Stimulus done.
2024-11-19 15:32:48,713 - INFO    - Expyfun: Exiting
2024-11-19 15:32:48,716 - EXP     - Expyfun: Audio stopped and reset.

# Author: Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD (3-clause)

import numpy as np

from expyfun import ExperimentController, building_doc

print(__doc__)

stim = np.zeros(int(1e6) + 1)
stim[[0, -1]] = 1.0
with ExperimentController(
    "FsTest",
    full_screen=False,
    noise_db=-np.inf,
    participant="s",
    session="0",
    output_dir=None,
    suppress_resamp=True,
    check_rms=None,
    version="dev",
) as ec:
    ec.identify_trial(ec_id="", ttl_id=[0])
    ec.load_buffer(stim)
    print("Starting stimulus.")
    ec.start_stimulus()
    wait_dur = len(stim) / ec.fs + 1.0
    print("Stimulus started. Please wait %d seconds." % wait_dur)
    if not building_doc:
        ec.wait_secs(wait_dur)
    ec.stop()
    print("Stimulus done.")

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

Gallery generated by Sphinx-Gallery