Page History: Direct Sound Element
Compare Page Revisions
Page Revision: 2012/05/22 08:10
|
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
- Add a new Direct Sound element into the selected event (where an audio has to be played).
- Select the element in the Element panel, then its properties will appear in the Property panel at the right.
- Load selected audio clips from the Material Library to the item list of the element and select the current clip via Item Index property.
- Browse to the settings group in the element properties and select a sound device from a list of the available hardware.
- 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"
- Test if an audio is played by clicking over the Test Playback property.
- 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 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 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 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
- 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 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 and using Wave Player Element is more 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.
Properties
Generic propertices
Name | Description | Attributes | Value Type | Proxy Reflex |
---|
Settings |
Sound Device | Defines a sound device for audio output | | Enum List |
Playback Mode | efines 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 Playback | Defines if the element monitors the start and end playback times and gets triggered at the end audio clip. | | Boolean |
Test Playback | Initiates 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 Type | Defines 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 Primary | Defines 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 |
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. | | System.Int32 |
Volume control | Defines 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 Info | Information about capacities of the selected sound device. Click to expand all sub-fields. | | Struct |
Buffer Info | Information about the sound buffer created for the selected audio clip. Click to expand all fields. | | Struct |
Playback |
Volume | Defines the volume of the audio playback, in percentages, from 0 (ground) to 100 (full). | | Int32 | Adjusts the volume of played audio. |
Balance | Defines the stereophonic balance of the audio playback, from 100 (most left) to 100 (most right) | | Int32 | Adjusts the stereophonic balance of played audio. |
Start position | Defines the start position of the further audio playbacks in percentages to the total duration of the currently selected audio clip. | | Double | Changes at runtime affect the next playback only. |
Position | Indicates the current playing position (in percentages to the total duration) of the audio clip. Changes are accepted only if the audio is currently playing. | | Double | Changing this property at runtime rewinds the playing clip to the new position. |
Is Playing | Indicates if the element is currently playing an audio. | | Boolean | Changing this property at runtime results in toggling between the play/pause states. |
3D Audio |
Enable 3D | Defines whether the 3D audio positioning feature is used for the playback (if the feature supported by the selected sound device). | | Boolean |
Listener Position | Defines 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 Heading | Defines 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 Heading | The 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 Factor | Defines the number of meters in one abstract distance unit, used in other properties. | | float |
Doppler Factor | Defines 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 Factor | Defines 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 velocity | Defines listener's velocity that is used for generation of the Doppler effect, in the distance units per second | | float |
Runtime info |
Start Time | If Monitor Playback property is true, this property returns the actual event time when the last playback started. | | UInt64 |
End Time | If 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 Triggered | If 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 ===
Name | Description | Constraints | Value Type | Upon Runtime Change |
---|
Material List |
Selected Index | Defines the index of the active item in the material list of the element. | | Int32 | A change causes the current item to be reloaded and an update of the element. |
Selected Item | Defines 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 | | String | A change causes the current item to be reloaded and an update of the element. |
Item Count | Returns the total number of items in the material list of the element. | | Int32 |
Equalize RGB | The 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
Name | Description | Constraints | Value Type | Upon Change |
---|
Control |
Is Enabled | If set to false the element is completely omitted when the experiment is run. | | Boolean |
|
Title | Title 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 |
|