expyfun.SoundCardController#

class expyfun.SoundCardController(params, stim_fs, n_channels=2, trigger_duration=0.01, ec=None)[source]#

Use a sound card.

Parameters:
paramsdict

A dictionary containing parameter keys. See Notes for details.

stim_fsfloat

Stim fs, used to downsample the white noise if necessary.

n_channelsint

The number of playback channels to use.

trigger_durationfloat

The duration (sec) to use for triggers (if applicable).

ecinstance of ExperimentController

The ExperimentController.

Methods

halt()

Halt.

load_buffer(samples)

Load the buffer.

play()

Play.

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()

Start noise.

stop([wait])

Stop.

stop_noise([wait])

Stop noise.

Notes

Params should contain string values:

  • ‘SOUND_CARD_BACKEND’str

    The backend to use. Can be ‘auto’ (default), ‘rtmixer’, ‘pyglet’.

  • ‘SOUND_CARD_API’str

    The API to use for the sound card. See sounddevice.query_hostapis(). The default is OS-dependent.

  • ‘SOUND_CARD_NAME’str

    The name as it is given by sounddevice.query_devices(). The default chooses the default sound card for the OS.

  • ‘SOUND_CARD_FS’float

    The sample rate to use for the sound card. The default lets the OS choose.

  • ‘SOUND_CARD_FIXED_DELAY’float

    The fixed delay (in sec) to use for playback. This is used by the rtmixer backend to ensure fixed latency playback.

  • ‘SOUND_CARD_TRIGGER_CHANNELS’int

    Number of sound card channels to use as stim channels.

  • ‘SOUND_CARD_API_OPTIONS’: dict

    API options, such as {'exclusive': true} for WASAPI.

  • ‘SOUND_CARD_TRIGGER_SCALE’: float

    Scale factor for sound card triggers (after they are bit-shifted by 8). The default value (1. / (2 ** 32 - 1)) is meant to be appropriate for bit-perfect mapping to the 24 bit output of a SPDIF channel.

  • ‘SOUND_CARD_TRIGGER_ID_AFTER_ONSET’: bool

    If True, TTL IDs will be stored and stamped after the 1 trigger.

  • ‘SOUND_CARD_DRIFT_TRIGGER’: list-like

    Defaults to [‘end’] which places a 2 trigger at the very end of the trial. Can also be a scalar or list of scalars to insert 2 triggers at the time of the scalar(s) (in sec). Negative values will be interpreted as time from end of trial.

Note that the defaults are superseded on individual machines by the configuration file.

halt()[source]#

Halt.

load_buffer(samples)[source]#

Load the buffer.

Parameters:
samplesndarray, shape (n_samples, n_channels)

The sound samples.

play()[source]#

Play.

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

If True and SOUND_CARD_TRIGGER_ID_AFTER_ONSET, the triggers will be stashed and appended to the 1 trigger for the sound onset.

start_noise()[source]#

Start noise.

stop(wait=False)[source]#

Stop.

Parameters:
waitbool

If True, wait for the action to complete. This is usually not necessary and can lead to tens of milliseconds of (variable) delay.

stop_noise(wait=False)[source]#

Stop noise.

Parameters:
waitbool

If True, wait for the action to complete. This is usually not necessary and can lead to tens of milliseconds of (variable) delay.