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: 2023-07-25 19_08_50.165237
file: /home/circleci/project/examples/sync/sample_rate_test.py
participant: s
session: 0
2023-07-25 19:08:50,165 - INFO    - Expyfun: Using version 2.0.0.dev0 (requested dev)
2023-07-25 19:08:50,166 - INFO    - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2023-07-25 19:08:50,312 - 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:50,313 - INFO    - Expyfun: Setting up screen
2023-07-25 19:08:50,342 - EXP     - Expyfun: Set screen visibility True
2023-07-25 19:08:50,351 - INFO    - Initialized [800 600] 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:50,351 - INFO    - Expyfun: Initializing dummy triggering mode
2023-07-25 19:08:50,352 - INFO    - Expyfun: Initialization complete
2023-07-25 19:08:50,352 - EXP     - Expyfun: Participant: s
2023-07-25 19:08:50,352 - EXP     - Expyfun: Session: 0
2023-07-25 19:08:50,353 - EXP     - Expyfun: Stamp trial ID to ec_id  :
2023-07-25 19:08:50,353 - EXP     - Expyfun: Stamp trial ID to ttl_id : [0]
2023-07-25 19:08:50,353 - EXP     - Stamping TTL triggers: [4]
2023-07-25 19:08:50,378 - EXP     - Expyfun: Loading 2000002 samples to buffer
Starting stimulus.
2023-07-25 19:08:50,390 - EXP     - Expyfun: Starting stimuli: flipping screen and playing audio
2023-07-25 19:08:50,391 - EXP     - Stamping TTL triggers: [1]
Stimulus started. Please wait 23 seconds.
2023-07-25 19:08:50,402 - EXP     - Expyfun: Audio stopped and reset.
Stimulus done.
2023-07-25 19:08:50,402 - INFO    - Expyfun: Exiting
2023-07-25 19:08:50,404 - 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.
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.
    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.242 seconds)

Gallery generated by Sphinx-Gallery