Welcome Guest, you are in: Login

EventIDE Wiki



Search the wiki


Element Icon Direct Sound Element
Category: Auditory Stimuli AddIn: Base Elements
Creator: OkazoLab Team Scope: Parent Event
Owns Snippets: On Triggered Usage: Design-time,Runtime,Snippets

Synchronized Internal Actions

Experiment StartParent Event OnsetStatus change between Onset/OffsetParent Event OffsetExperiment End
If playback mode is set to 'single' or 'looped' playback,
then start playback upon onset.
Elements are triggered when the audio clip is finished playing All playback is aborted.


Generic propertices

NameDescriptionConstraintsValue TypeUpon Change
Sound DeviceDefines a sound device for audio output Enum List
Playback ModeDefines the playback mode for audio clips played by the element. In the default mode (Single Playback), a clip is played once on the onset of the parent event. In the Manual mode the playback process is controlled in the snippets by changing the Is Playing property. Enum List
Monitor PlaybackDefines if the element monitors the start and end playback times and gets triggered at the end audio clip.Boolean
Test PlaybackInitiates a single playback of the currently selected clip using the chosen hardware settings of the element Design-time action Returns an error message, if the playback fails.
Sound buffer
Buffer TypeDefines a type of the sound buffer that is created for a playback. The buffer type is determined by its location either in device or computer memory. Enum List
Is PrimaryDefines whether the element will try to allocate the primary buffer memory of the sound device for the fastest playback (exclusively for this element). The sound device has to support this option.Boolean
PriorityDefines the priority of the allocated sound buffer relatively to other buffers. The lowest priority corresponds to 0. The greater is the positive value, the higher priority is given.System.Int32
Volume controlDefines whether the volume of a played audio is allowed to be adjusted at runtime. Setting to false can improve temporal precision the playback.Boolean
Balance Control Defines whether the stereophonic balance of a played audio is allowed to be adjusted at runtime. Setting to false can improve temporal precision of the playback.Boolean
Design-time info
Device InfoInformation about capacities of the selected sound device. Click to expand all sub-fields.Struct
Buffer InfoInformation about the sound buffer created for the selected audio clip. Click to expand all fields.Struct
VolumeDefines the volume of the audio playback, in percentages, from 0 (ground) to 100 (full). Int32Adjusts the volume of played audio.
BalanceDefines the stereophonic balance of the audio playback, from 100 (most left) to 100 (most right) Int32Adjusts the stereophonic balance of played audio.
Start positionDefines the start position of the further audio playbacks in percentages to the total duration of the currently selected audio clip. DoubleChanges at runtime affect the next playback only.
PositionIndicates the current playing position (in percentages to the total duration) of the audio clip. Changes are accepted only if the audio is currently playing. DoubleChanging this property at runtime rewinds the playing clip to the new position.
Is PlayingIndicates if the element is currently playing an audio. BooleanChanging this property at runtime results in toggling between the play/pause states.
3D Audio
Enable 3DDefines whether the 3D audio positioning feature is used for the playback (if the feature supported by the selected sound device).Boolean
Listener PositionDefines the current 3D position of the virtual listener relatively to the fixed sound source in (0,0,0). The value is in the abstract distance units. cl3DVector (fields: X,Y,Z)
Front HeadingDefines the current 3D orientation of the front of the virtual listener relatively to the sound source in (0,0,0). The value is in the abstract distance units. cl3DVector (fields: X,Y,Z)
Top HeadingThe current 3D orientation of the top of the virtual listener relatively to the sound source in (0,0,0). Values are in the distance units. cl3DVector (fields: X,Y,Z)
Distance FactorDefines the number of meters in one abstract distance unit, used in other properties. float
Doppler FactorDefines the Doppler factor that has to be in the range of 0.0 (no Doppler effects) to 10.0 (ten times the Doppler effects found in the real world). float
Rolloff FactorDefines the rate of the sound attenuation over distance. The value has to be in the range of 0.0 (no rolloff) to 10.0 (ten times the rolloff found in the real world). float
Listener's velocityDefines listener's velocity that is used for generation of the Doppler effect, in the distance units per second float
Runtime info
Start TimeIf Monitor Playback property is true, this property returns the actual event time when the last playback started. UInt64
End TimeIf Monitor Playback property is true, this property stores the actual event time when the last playback ended. End Time-Start Time indicates the actual duration of the last playback in ms.UInt64
Is TriggeredIf Monitor Playback property is true, this property indicates that the element has been triggered by end of the playback at least once, since the onset of the parent event. Boolean

+=== Properties inherited from clLibraryElement ===
NameDescriptionConstraintsValue TypeUpon Runtime Change
Material List
Selected IndexDefines the index of the active item in the material list of the element. Int32A change causes the current item to be reloaded and an update of the element.
Selected ItemDefines the name of the active item in the material list of the element. The name matches to a name of item in the Material Library StringA change causes the current item to be reloaded and an update of the element.
Item CountReturns the total number of items in the material list of the element.Int32
Equalize RGBThe property is only available in the visual element. If the value is true, the average RGB pixel intensity will be equalized across all items in the material list. You can turn on this property, when you need to obtain a luminance-balanced set of visual stimulus. Boolean

+=== Properties inherited from clElement === Inherited properties of clElement
NameDescriptionConstraintsValue TypeUpon Change
Is EnabledIf set to false the element is completely omitted when the experiment is run.Boolean
TitleTitle of the element.String

Direct Sound element is capable of playing WAV audio clips via DirectSound API.


The DirectSound element is capable of playing audio clips in the Waveform Audio File Format (WAV) via a fast, low-level interface to sound cards called Microsoft DirectSound. The element allows the fine tuning of sound hardware and playback modes. As a result very good temporal precision of audio playback can be achieved in experiments, especially when a sound hardware and drivers are fully compatible with the Direct Sound interface.

The element may have problems reading the compressed Wave files. For better results, the uncompressed PCM format is preferred.

Like other audio elements in EventIDE, the Direct Sound element allows full control of of the playback process: mixing of multiple sounds, changes in sound volume, panning and playback position.

In addition, the element allows an easy management of 3D sound features, e.g. adjusting the 3D surround mapping via coordinates of listener's position in a virtual 3D space.



When to use the DirectSound element

EventIDE provides several elements for delivering auditory stimuli. The audio elements have similar functionality and a choice depends on design demands and the used sound hardware. A guidance on selecting an audio element is available in Auditory Stimuli article.

In short, the DirectSound element is best for Windows XP systems with old-fashioned hardware cards that have an on-board memory or when precise hardware tuning is necessary.

Stimulus Set

The element can be easily adapted to make up an audio stimulus set that contains multiple audio clips. Then one of these clips can be selected to be played in the given trial. To make a stimulus set, load selected audio clips from Material Library directly into the element (e.g. by drag and drop). Then use the Item Index property to select an audio clip for playback. It's recommended to change the Item Index property before the onset of the parent event because preparing the clip for playback takes some time.

Practical Use

  1. Add a new Direct Sound element into the selected event (where an audio has to be played).
  2. Select the element in the Element panel, then its properties will appear in the Property panel at the right.
  3. Load selected audio clips from the Material Library to the item list of the element and select the current clip via Item Index property.
  4. Browse to the settings group in the element properties and select a sound device from a list of the available hardware.
  5. Select a playback mode for the give element via the corresponding property. The common mode for presentation of auditory stimulus is "Single playback on onset of the parent event"
  6. Test if an audio is played by clicking over the Test Playback property.
  7. Make sure that duration of the parent event is greater or equal to duration of the selected audio clip- an audio playback is always aborted on offset of the parent event.

There are two typical scenario of using the element for presenting audio stimuli in multiple trials:

  • If you want to present a random audio clip in each trial, use the 'Single playback' mode and add a proxy linked to the Item Index property. With that proxy you can select an audio clip from the element's list in code snippets (normally before onset of the parent event)
  • If you want to chose whether an audio clip has to be played or not in each trial, select 'Manual' mode add a proxy linked to the Is Playing property. Setting that proxy to true/false in code snippets will allow to turn on/off audio playback on the onset of the parent event (the proxy has to be set before the event onset).

Playback modes

At runtime the element can work in 3 different playback modes, which define how playback process starts and stops. The mode has to be selected at design-time and cannot be changed. However, it's possible to use multiple elements working in different modes in parallel. The available modes are:

Single playback on onset of the parent event

In this mode the element starts to play an audio synchronously with the onset of the parent event. The audio is played to the end one time. If parent event is deactivated before the audio end is reached, the playback is aborted.

Looped playback on event onset

In this mode the element starts to play an audio synchronously with the onset of the parent event and keep repeating it automatically when the playback end is reached. This playback loop lasts until deactivation of the parent event.

Manual playback

In this mode the element plays an audio only via a manual request which is made by code snippets when desired. The playback is initiated by assigning true to the Is Playing property of the element. Later, the same property can be used to monitor if the audio is still currently played. Is Playing property automatically turns to false when the playback ends. At this moment and later you can initiate a new playback if the parent event is still active.

Advanced capacities

The DirectSound element has a group of properties for fine tuning of sound hardware. There you can select the sound card among multiple sound cards installed on the same computer and set up its memory configuration for the most efficient audio playback. The element automatically collects and returns information about hardware capacities of the sound card that can be accessed by the Device Info property. For testing purposes the element is capable of measuring its own playback time statistics,e.g. the properties Start Time and End Time can be used to estimate the offset and actual playback duration at runtime.

3D audio

The DirectSound element supports the 3D audio effect widening the perceived sound image for the listener. For most realistic results using more than 2 speakers is necessary. The overall control over 3D audio effect is very simple- the element adjusts audible channels according to the position of a virtual listener relatively to a fixed sound source in 3D space. You can dynamically change the listener position at runtime, changing just 3 coordinates. In addition, you can customize the produced 3D audio with the Doppler effect and with the effect of sound attenuation over a distance. Notice, that you have to provide a mono wave clip for playback if 3D audio is enabled (by the Enable 3D property)

Performance notes

In general, the temporal accuracy of the DirectSound playback is always traded for requested controls over the playback process. For example, you may get more accurate timing if you decide not to change the sound volume during playback. The DirectSound element allows you to choose only controls that are currently necessary. Set the properties Volume control, Balance control, 3D enable, Triggering to False in order to get better temporal performance. In addition, you can manually set up the memory management for playing sound. If the sound card supports it, try to allocate the memory buffer for an audio in the hardware memory of the sound card by setting the Buffer type property. If you have a single auditory stimulus delivery in your experiment, you can try to use the Primary buffer of the sound card for a single DirectSound element (the Primary Buffer property) - it should give you even better playback performance. Using audio clips of uncompressed formats, like WAVE PCM, with the sample rate and other characteristics matching to the format of the sound card memory buffers can also greatly improve the playback performance.

Triggering at the end of the playback

Sometimes it's necessary to abort the parent event immediately after the playback has reached its end. Since the Wave Player element can contain multiple audio clips of different durations, the duration of the parent event can not set to fix value. The wave player elements offers an easy solution - it monitors the playback process and gets triggered at the end of each audio clip. Triggering causes a call of the OnTriggered snippet that can be used for user actions. In addition, the element has a boolean property, called Is Triggered, which can be used directly (as Proxy) in controlling the event flow.


  • The Direct Sound element is optimized to deliver the best timing accuracy of the audio playback. However, it's always recommended to measure empirically the timing of the actual playback when high accuracy is required. The measurements can be done with oscilloscope connected to the output of the sound card. Probing different settings of the element can help to achieve the optimal results.
  • The DirectSound interface get a direct access to sound hardware only in Windows XP. It is NOT the case for Windows Vista/7/8, where DirectSound works in the software emulation mode. Although such emulation can be very efficient, the temporal precision of sound playback with DirectSound element can be lower under Windows Vista/7/8 and using Wave Player Element is recommended.
  • If 3D audio feature are enabled, only mono audio clips have to used with the element.
  • Slightly better onset of the audio playback can be achieved if the element is placed at the top of the elements list in the parent event. Elements in the list get activated one by one on the onset of the parent event, so the top position in the list will minimize the onset delay.
  Name Size
- DirectSoundEl.png 244.91 KB
- DirectSoundEl_sm.jpg 21.75 KB

ScrewTurn Wiki version Some of the icons created by FamFamFam.