expyfun.TDTController#

class expyfun.TDTController(tdt_params, ec)[source]#

Interface for TDT audio output, stamping, and responses.

Warning

This class should not be instantiated manually, but rather should be created automatically by an appropriate call to ExperimentController.

Parameters:
tdt_paramsdict

A dictionary containing keys with string values:

‘TYPE’

This should always be ‘tdt’.

‘TDT_MODEL’

String name of the TDT model, can be ‘RM1’, ‘RP2’, ‘RP2legacy’, ‘RZ6’, or ‘dummy’ (default). For historical reasons, ‘RP2’ corresponds to the RP2.1, and ‘RP2legacy’ corresponds to the first-revision RP2.

‘TDT_CIRCUIT_PATH’

Path to the TDT circuit. Defaults to an internal expyfun circuit.

‘TDT_INTERFACE’

Type of connection, either ‘USB’ (default) or ‘GB’).

‘TDT_DELAY’

The delay (in ms) for the circuit (default: ‘0’).

‘TDT_TRIG_DELAY’

Additional delay for the triggers (default: ‘0’).

The defaults are superseded on individual machines by the configuration file.

ecinstance of ExperimentController

The ExperimentController.

Attributes:
circuit

TDT circuit path.

fs

Playback frequency of the audio (samples / second).

interface

String representation of TDT interface (‘USB’ or ‘GB’).

model

String representation of TDT model name (‘RM1’, ‘RP2’, etc).

playing

Is a sound currently playing

Methods

check_force_quit([keys])

Compare key buffer to list of force-quit keys and quit if matched.

get_presses(live_keys, timestamp, relative_to)

Get the current entire keyboard / button box buffer.

halt()

Wrapper for tdt.util.RPcoX.Halt().

listen_presses()

Start listening for keypresses.

load_buffer(data)

Load audio samples into TDT buffer.

play()

Send the soft trigger to start the ring buffer playback.

set_noise_level(level)

Set the noise level.

stamp_triggers(triggers[, delay, ...])

Stamp a list of triggers with a given inter-trigger delay.

start_noise()

Send the soft trigger to start the noise generator.

stop([wait])

Send the soft trigger to stop and reset the ring buffer playback.

stop_noise([wait])

Send the soft trigger to stop the noise generator.

wait_for_presses(max_wait, min_wait, ...)

Return all button presses between min_wait and max_wait.

wait_one_press(max_wait, min_wait, ...)

Return the first button pressed after min_wait.

check_force_quit(keys=None)[source]#

Compare key buffer to list of force-quit keys and quit if matched.

This function always uses the keyboard, so is part of abstraction.

Parameters:
keyslist | None

Keys to check.

property circuit#

TDT circuit path.

property fs#

Playback frequency of the audio (samples / second).

get_presses(live_keys, timestamp, relative_to, kind='presses', return_kinds=False)[source]#

Get the current entire keyboard / button box buffer.

Parameters:
live_keyslist | None

Keys to check.

timestampbool

If True, return timestamp.

relative_tofloat

Time to use as a reference.

kindstr

Kind of presses.

return_kindsbool

If True, return kinds.

Returns:
presseslist

The presses (and possibly timestamps and/or types).

halt()[source]#

Wrapper for tdt.util.RPcoX.Halt().

property interface#

String representation of TDT interface (‘USB’ or ‘GB’).

listen_presses()[source]#

Start listening for keypresses.

load_buffer(data)[source]#

Load audio samples into TDT buffer.

Parameters:
datanp.array

Audio data as floats scaled to (-1,+1), formatted as an Nx2 numpy array with dtype ‘float32’.

property model#

String representation of TDT model name (‘RM1’, ‘RP2’, etc).

play()[source]#

Send the soft trigger to start the ring buffer playback.

property playing#

Is a sound currently playing

set_noise_level(level)[source]#

Set the noise level.

Parameters:
levelfloat

The new level.

stamp_triggers(triggers, delay=None, wait_for_last=True, is_trial_id=False)[source]#

Stamp a list of triggers with a given inter-trigger delay.

Parameters:
triggerslist

No input checking is done, so ensure triggers is a list, with each entry an integer with fewer than 8 bits (max 255).

delayfloat | None

The inter-trigger-onset delay (includes “on” time). If None, will use twice the trigger duration (50% duty cycle).

wait_for_lastbool

If True, wait for last trigger to be stamped before returning.

is_trial_idbool

No effect for this controller.

start_noise()[source]#

Send the soft trigger to start the noise generator.

stop(wait=True)[source]#

Send the soft trigger to stop and reset the ring buffer playback.

Parameters:
waitbool

Unused by the TDT.

stop_noise(wait=True)[source]#

Send the soft trigger to stop the noise generator.

Parameters:
waitbool

Unused by the TDT.

wait_for_presses(max_wait, min_wait, live_keys, timestamp, relative_to)[source]#

Return all button presses between min_wait and max_wait.

Parameters:
max_waitfloat

Maximum time to wait.

min_waitfloat

Minimum time to wait.

live_keyslist | None

Keys to consider.

timestampbool

If True, return timestamps.

relative_tofloat

Time to use as a reference.

Returns:
pressedlist

The list of presses (and possibly timestamps).

wait_one_press(max_wait, min_wait, live_keys, timestamp, relative_to)[source]#

Return the first button pressed after min_wait.

Parameters:
max_waitfloat

Maximum time to wait.

min_waitfloat

Minimum time to wait.

live_keyslist | None

Keys to consider.

timestampbool

If True, return timestamps.

relative_tofloat

Time to use as a reference.

Returns:
pressedtuple | str | None

The press. Will be tuple if timestamp is True.