Direct Sound Element

Modified on 2018/07/16 02:04 by Administrator — Categorized as: Auditory Stimuli, Base Elements, Elements

Summary

Element Icon Direct Sound
Info
Category: Audio Stimuli AddIn: Base Layer
Creator: OkazoLab Scope: Parent event
Owns Snippets: None Usage: Snippets

Properties

NameDescription                              ConstraintsTypeOn
runtime
change
Settings
Sound Device        Selected sound device for playback                String         
Playback Mode        Defines the synchronization mode of the playback process. Once- a single playback synchronized with activation of the parent event, Loop- a looped playback synchronized with the parent event, Manual- a playback is initiated manually                stPlay..         
Monitor Playback        Defines if the element monitors the start and end playback times and is triggered at the end of the each playback                Boolean         
Test Playback                         Boolean         
Sound Buffer
Buffer Type        Defines a type of the sound buffer created for a playback. The buffer type is determined by its location in device/computer memory.                stDire..         
Is Primary        If true, 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         
Priority        Defines 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.                UInt32         
Volume Control        If true, the volume of played audio can be adjusted at runtime. If false, it can improve temporal precision the playback.                Boolean         
Balance Control        If true, the stereophonic balance of played audio can be adjusted at runtime. If false, it can improve temporal precision of the playback.                Boolean         
Design-time Info
Device Info        Information about capacities of the currently selected sound device. Click to expand all fields.                stDSDe..         
Buffer Info        Information about the sound buffer created for the currently selected audio clip. Click to expand all fields.                stDSBu..         
Playback
Volume        Defines the volume of the audio playback, in percentages, from 0 (ground) to 100 (full)                Int32         
Balance        Defines the stereophonic balance of the audio playback, from 100 (most left) to 100 (most right)                Int32         
Start position        Defines the start position of the audio playback in percentages (0..100) to the total duration of the currently selected audio clip.                Double         
Position        The current playback position in percentages (0..100) to the total duration of the currently played audio. The property can be used only at runtime.                Double         
Is Playing        Indicates if the element is currently playing an audio. Changing this property at runtime results in toggling between the play/pause states.                Boolean         
3D Audio
Enable 3D                         Boolean         
Listener Position        The current 3D position of the virtual listener relatively to the fixed sound source in (0,0,0). Vector values are in the distance units.                cl3DVe..         
Front Heading        The current 3D orientation of the front of the virtual listener relatively to the sound source in (0,0,0). Vector values are in the distance units.                cl3DVe..         
Top Heading        The current 3D orientation of the top of the virtual listener relatively to the sound source in (0,0,0). Vector values are in the distance units.                cl3DVe..         
Distance Factor        Number of meters in the distance unit                Single         
Doppler Factor        The Doppler factor that has a range of 0.0 (no Doppler effects) to 10.0 (ten times the Doppler effects found in the real world)                Single         
Rolloff Factor        Determines the rate of the sound attenuation over distance. Has a range of 0.0 (no rolloff) to 10.0 (ten times the rolloff found in the real world).The effect is global for all Direct Sound elements                Single         
Doppler Velocity        Listener's velocity that is used for generation of the Doppler effect, in the distance units per second                cl3DVe..         
Runtime Status
Start Time        If Monitor Playback property is true, this property stores the actual event time when the last playback started                clTime         
End Time        If Monitor Playback property is true, this property stores the actual event time when the last playback ended                clTime         
Is Triggered        If Monitor Playback property is true, this property indicates if the element has been triggered at least once after activation of the parent event. Triggering occurs each time when the playback ends.                Boolean         
Material List
Selected Index        Defines an index of the active item in the material list of this element                Int32         
Selected Item        Defines a name if the active library item in the material list of this element                String         
Item Count        Returns the total number of material items in the list of this element                Int32         
Control
Is Enabled        If set to false the element is completely omitted when the experiment is run                Boolean         
Title        Title of the element                String         

Direct Sound Element is capable of playing audio clips in the wave format via DirectSound API. The element is recommended for Windows XP and old sound cards, when temporal accuracy is important. The elements allows deep tuning of playback process, if it's supported by a sound card and drivers.


Description

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.

Snapshots

Image

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:


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.

Notes