This chapter contains functions you can use to play and control sound stimuli that do not contain any visual input (for videos see chapter 8. Video). Remember to store all your stimuli in the stimuli folder! Remember to select the sound option in myParadigmSetup section 5 (change entry to 1). For all the sound functions of this toolbox [GStreamer](https://gstreamer.freedesktop.org/) needs to be installed on your device (https://gstreamer.freedesktop.org/).
This chapter contains functions you can use to play and control sound stimuli that do not contain any visual input (for videos see [chapter 7. Video](Video Display)). Remember to store all your stimuli in the stimuli folder! Remember to select the sound option in [myParadigmSetup](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/myParadigmSetup.m) section 5 (change entry to 1). For all the sound functions of this toolbox [GStreamer](https://gstreamer.freedesktop.org/) needs to be installed on your device (https://gstreamer.freedesktop.org/).
This function lists all available sound systems in the command window. The function has no input or output arguments. It should be called before sounds are used on a new device or after a software update! Not as part of an experimentation script but for preparation.
This function lists all available sound systems in the command window. The function has no input or output arguments. It should be called before sounds are used on a new device or after a software update! Not as part of an experimentation script but for preparation.
## initSound
## initSound
function: sh = initSound(devIndex)
function: sh = [initSound(devIndex)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Sound/initSound.m)
**Description**
**Description**
This function initializes the audio subsystem of your windows computer. Depending on the audio card found on the computer it tries to use the best audio system. Before calling this function it is highly recommended to call the listSound function, which will give you a list of all available sound systems, first! Decide for the best possible sound system before you play the sound. An optional argument deviceIndex can be used to specify a special sound system. Displays warnings if a no ASIO driver is used
This function initializes the audio subsystem of your windows computer. Depending on the audio card found on the computer it tries to use the best audio system. Before calling this function it is highly recommended to call the [listSound](/Sound-options#listsound) function, which will give you a list of all available sound systems, first! Decide for the best possible sound system before you play the sound. An optional argument deviceIndex can be used to specify a special sound system. Displays warnings if a no ASIO driver is used
**Inputs-optional**
**Inputs-optional**
~~~
~~~
...
@@ -22,7 +22,7 @@ This function initializes the audio subsystem of your windows computer. Dependin
...
@@ -22,7 +22,7 @@ This function initializes the audio subsystem of your windows computer. Dependin
~~~
~~~
**Examples**
**Examples**
~~~
~~~matlab
1.initSound;
1.initSound;
% automatically gets the best results
% automatically gets the best results
...
@@ -31,14 +31,14 @@ This function initializes the audio subsystem of your windows computer. Dependin
...
@@ -31,14 +31,14 @@ This function initializes the audio subsystem of your windows computer. Dependin
function: out = [loadSound(sh, filename)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Sound/loadSound.m)
**Description**
**Description**
Loads an audio file and gives easy control for playback during experiments. Supported file formats include .wav and .au files. The filename of the audio file can be specified by the input filename, a window will open if this option is left out. After successfully loading the audio file a handle to the sound file is returned. To control the sound (play, stop etc.) use controlSound.m.
Loads an audio file and gives easy control for playback during experiments. Supported file formats include .wav and .au files. The filename of the audio file can be specified by the input filename, a window will open if this option is left out. After successfully loading the audio file a handle to the sound file is returned. To control the sound (play, stop etc.) use [controlSound.m](/Sound-options#controlsound).
Supported file formats (in MATLAB): wav, ogg, flac, au, aiff, aifc and only on Windows computers mp3 and mpeg-4 aac.
Supported file formats (in MATLAB): wav, ogg, flac, au, aiff, aifc and only on Windows computers mp3 and mpeg-4 aac.
...
@@ -59,7 +59,7 @@ Supported file formats (in MATLAB): wav, ogg, flac, au, aiff, aifc and only on W
...
@@ -59,7 +59,7 @@ Supported file formats (in MATLAB): wav, ogg, flac, au, aiff, aifc and only on W
~~~
~~~
**Examples**
**Examples**
~~~
~~~matlab
1.out=loadSound('feeding.wav');
1.out=loadSound('feeding.wav');
% loading a *.wav file
% loading a *.wav file
...
@@ -68,14 +68,14 @@ Supported file formats (in MATLAB): wav, ogg, flac, au, aiff, aifc and only on W
...
@@ -68,14 +68,14 @@ Supported file formats (in MATLAB): wav, ogg, flac, au, aiff, aifc and only on W
Use this function to get control over an audio file that was loaded with loadSound. Optional arguments give the ability to start in a file or play the file for a given time. This is useful for presenting only parts of an audio file. Playing a sound will not pause the execution of MATLAB-programs. This allows for example to record behavioral responses or turn on visual stimuli during playback.
Use this function to get control over an audio file that was loaded with [loadSound](/Sound-options#loadsound). Optional arguments give the ability to start in a file or play the file for a given time. This is useful for presenting only parts of an audio file. Playing a sound will not pause the execution of MATLAB-programs. This allows for example to record behavioral responses or turn on visual stimuli during playback.
**Inputs**
**Inputs**
~~~
~~~
...
@@ -84,10 +84,10 @@ Use this function to get control over an audio file that was loaded with loadSou
...
@@ -84,10 +84,10 @@ Use this function to get control over an audio file that was loaded with loadSou
**Inputs-optional**
**Inputs-optional**
~~~
~~~
varargin ‘play’ plays the whole sound file until the end. A second (optional) argument defines the number of repetitions.
varargin 'play' plays the whole sound file until the end. A second (optional) argument defines the number of repetitions.
‘stop’ stops playback of the sound (defined by the handle)
'stop' stops playback of the sound (defined by the handle)
‘startStop’ stops playback of the sound after a defined amount of time (in seconds)
'startStop' stops playback of the sound after a defined amount of time (in seconds)
‘delete’ deletes the loaded file from memory
'delete' deletes the loaded file from memory
~~~
~~~
**Outputs**
**Outputs**
...
@@ -96,50 +96,50 @@ Use this function to get control over an audio file that was loaded with loadSou
...
@@ -96,50 +96,50 @@ Use this function to get control over an audio file that was loaded with loadSou
~~~
~~~
**Examples**
**Examples**
~~~
~~~matlab
1.controlSound(soundFile);
1.controlSound(soundFile);
% playing the whole sound file until the end
% playing the whole sound file until the end
2. controlSound(soundFile, ’play’);
2.controlSound(soundFile,'play');
% playing the whole sound file until the end
% playing the whole sound file until the end
3. controlSound(soundFile, ‘play’, 3);
3.controlSound(soundFile,'play',3);
% playing the whole sound file three times until the end
% playing the whole sound file three times until the end
4. controlSound(soundFile, ‘stop’);
4.controlSound(soundFile,'stop');
% stops playback for the sound stored in soundFile
% stops playback for the sound stored in soundFile
5. controlSound(soundFile, ‘startStop’, 5.3);
5.controlSound(soundFile,'startStop',5.3);
% stops playback after 5.3 seconds
% stops playback after 5.3 seconds
6. controlSound(soundFile, ‘delete’);
6.controlSound(soundFile,'delete');
% deletes the file stored in soundFile from memory
% deletes the file stored in soundFile from memory