Welcome Guest, you are in: Login

EventIDE Wiki

RSSRSS

Navigation




Search the wiki


PoweredBy

Page History: Direct Sound Element

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: 2012/05/21 12:22


Element Icon Direct Sound Element
Info
Category: Auditory Stimuli AddIn: Base Elements
Creator: OkazoLab Team Scope: Parent Event
Owns Snippets: On Triggered Usage: Design-time,Runtime,Snippets
DirectSound element is capable to play WAV audio clips using DirectSound API.


Description

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 a fine tuning of sound hardware and playback modes. As a result, a 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.

Like other audio elements in EventIDE, the Direct Sound element allows a 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.

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 by a manual request made in code snippets at will time. 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 a fine tuning of the sound hardware. There you can select a 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 a 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 monochannel WAV clip for playback if 3D audio is enabled ([3D enable] 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.

Design-time testing

While choosing appropriate values for the element's properties, check the content of the Device Info and Buffer Info properties. These properties are refreshed after any related property change and should not be empty or contain error messages. If you see an error, the playback is not possible, and you have to choose different values for the element's properties. You can also always test an audio playback with the current element settings by clicking the Test Playback property.

Notes

  1. The DirectSound interface in Windows XP in most cases accesses the sound hardware directly. It is NOT the case for Windows Vista and Windows 7, 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 and Windows 7.
  2. If you enable 3D audio, you should use mono audio clips as playback resources for the element.
  3. For better synchronization of the audio playback (in the Once and Loop playback modes), move the DirectSound element at the top of the elements list in the parent event. Elements in the list get to work one by one, as soon as the parent event is activated, so the top position in the list will minimize possible delays.

Properties

Generic propertices

NameDescriptionAttributesValue Type
Settings
Sound DeviceSelected sound device for playback. String
Playback modeDefines the synchronization mode of the playback process. One of three modes can be selected: Once – the sound playback is initiated synchronously with activation of the parent event and an audio clip is played once. Loop - the start of sound playback is synchronized with activation of the parent event but, since that, an audio clip is played in a loop. Manual – the sound playback is initiated manually by a request from code snippets. DObject
Monitor PlaybackDefines if the element monitors the start and end playback times and is triggered at the end of the each playback.DBoolean
Test PlaybackUse this action at the design time to initiate an testing playback with the current settings.Design-time action
Sound buffer
Buffer TypeDefines a type of the sound buffer created for a playback. The buffer type is determined by its location in device/computer memory. DList
Is PrimaryIf 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.DBoolean
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.DInt 32
Volume controlIf true, the volume of played audio can be adjusted at runtime. If false, it can improve temporal precision the playback.DBoolean
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.DBoolean
Design-time info
Device InfoInformation about capacities of the currently selected sound device. Click to expand all sub-fields.DStruct
Buffer InfoInformation about the sound buffer created for the currently selected audio clip. Click to expand all fields.DStruct
Playback
VolumeDefines the volume of the audio playback, in percentages, from 0 (ground) to 100 (full)D,RInt32
BalanceDefines the stereophonic balance of the audio playback, from 100 (most left) to 100 (most right)D,RInt32
Start positionDefines the start position of the audio playback in percentages (0..100) to the total duration of the currently selected audio clip.,RDouble
PositionThe current playback position in percentages (0..100) to the total duration of the currently played audio. The property can be used only at runtime.D,RDouble
Is PlayingIndicates if the element is currently playing an audio. Changing this property at runtime results in toggling between the play/pause states.RBoolean
3D Audio
Enable 3DIf true, it turns on the 3D audio effect for the playback (if supported by the selected sound device).Boolean
Listener PositionThe current 3D position of the virtual listener relatively to the fixed sound source in (0,0,0). Values are in the distance units.D,Rcl3DVector (fields: X,Y,Z)
Front HeadingThe current 3D orientation of the front of the virtual listener relatively to the sound source in (0,0,0). Values are in the distance units.D,Rcl3DVector (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.D,Rcl3DVector (fields: X,Y,Z)
Distance FactorNumber of meters in the distance unit.D,Rfloat
Doppler FactorThe 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).D,Rfloat
Rolloff FactorDetermines 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).D,Rfloat
Listener's velocityListener's velocity that is used for generation of the Doppler effect, in the distance units per secondD,Rfloat
Runtime info
Start TimeIf Monitor Playback property is true, this property stores the actual event time when the last playback started. Indicates the actual playback startup latency in ms if the "Once" playback mode is chosen.R, Read-OnlyUInt64
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.R, Read-OnlyUInt64
Is triggeredIf Monitor Playback property is true, this property indicates if the element has been triggered at least once since activation of the parent event. The triggering occurs each time when the playback ends.R, Read-OnlyBoolean

+=== 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
Control
Is EnabledIf set to false the element is completely omitted when the experiment is run.Boolean
TitleTitle of the element.String

The list of Text element properties:

Resource Holder inherited properties

CATEGORY ,Property name Description type Value type
RESOURCE LIST
Resource index The index of item in the resource list that is currently used by the element. Notice, that index starts from 1.D,R,* Int32
Resource count The number of items loaded in the resource list of the element D,R,Read-only Int32

ScrewTurn Wiki version 5.2.0.8. Some of the icons created by FamFamFam.