Note
Go to the end to download the full example code.
Audio sample rate test#
This example tests the TDT sample rate, which we expect to be 24414.0625
.
To test this:
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.
Start Audacity on the sound-card machine.
Configure the sound-card machine and/or Audacity to record from the sound card input.
Tell Audacity to record.
Run this script. It should take about 40 seconds at 24414 sample rate.
When the script completes, stop the Audacity recording.
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.
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 of60.813690
sec for a difference of of40.95936
, yielding an effective sample rate of24414.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-10-08 13_43_17.192728
file: /home/circleci/project/examples/sync/sample_rate_test.py
participant: s
session: 0
2024-10-08 13:43:17,192 - INFO - Expyfun: Using version 2.0.0.dev0 (requested dev)
2024-10-08 13:43:17,193 - INFO - Expyfun: Setting up sound card using pyglet backend with 2 playback channels
2024-10-08 13:43:17,347 - 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-10-08 13:43:17,347 - INFO - Expyfun: Setting up screen
2024-10-08 13:43:17,377 - EXP - Expyfun: Set screen visibility True
2024-10-08 13:43:17,389 - INFO - Initialized [800 600] window on screen XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7f392c363f10>, x=0, y=0, width=1400, height=900, xinerama=0) with DPI 69.73
2024-10-08 13:43:17,389 - INFO - Expyfun: Initializing dummy triggering mode
2024-10-08 13:43:17,390 - INFO - Expyfun: Initialization complete
2024-10-08 13:43:17,390 - EXP - Expyfun: Participant: s
2024-10-08 13:43:17,390 - EXP - Expyfun: Session: 0
2024-10-08 13:43:17,391 - EXP - Expyfun: Stamp trial ID to ec_id :
2024-10-08 13:43:17,391 - EXP - Expyfun: Stamp trial ID to ttl_id : [0]
2024-10-08 13:43:17,392 - EXP - Stamping TTL triggers: [4]
2024-10-08 13:43:17,418 - EXP - Expyfun: Loading 2000002 samples to buffer
Starting stimulus.
2024-10-08 13:43:17,435 - EXP - Expyfun: Starting stimuli: flipping screen and playing audio
2024-10-08 13:43:17,436 - EXP - Stamping TTL triggers: [1]
Stimulus started. Please wait 23 seconds.
2024-10-08 13:43:17,447 - EXP - Expyfun: Audio stopped and reset.
Stimulus done.
2024-10-08 13:43:17,447 - INFO - Expyfun: Exiting
2024-10-08 13:43:17,450 - 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.261 seconds)