Update Sound Options: links & code authored by Fabian Berg's avatar Fabian Berg
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/).
[[_TOC_]]
## listSound
function: listSound
function: [listSound](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Sound/listSound.m)
**Description**
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
function: sh = initSound(devIndex)
function: sh = [initSound(devIndex)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Sound/initSound.m)
**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**
~~~
......@@ -22,7 +22,7 @@ This function initializes the audio subsystem of your windows computer. Dependin
~~~
**Examples**
~~~
~~~matlab
1. initSound;
% automatically gets the best results
......@@ -31,14 +31,14 @@ This function initializes the audio subsystem of your windows computer. Dependin
~~~
**See also**
listSound, controlSound, closeSound
[listSound](/Sound-options#listsound), [controlSound](/Sound-options#controlsound), [closeSound](/Sound-options#closesound)
## loadSound
function: out = loadSound(sh, filename)
function: out = [loadSound(sh, filename)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Sound/loadSound.m)
**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.
......@@ -59,7 +59,7 @@ Supported file formats (in MATLAB): wav, ogg, flac, au, aiff, aifc and only on W
~~~
**Examples**
~~~
~~~matlab
1. out = loadSound('feeding.wav');
% loading a *.wav file
......@@ -68,14 +68,14 @@ Supported file formats (in MATLAB): wav, ogg, flac, au, aiff, aifc and only on W
~~~
**See also**
controlSound, closeSound, loadImage, showStimuli
[controlSound](/Sound-options#controlsound), [closeSound](/Sound-options#closesound), [loadImage](/Image-display#loadimage), [showStimuli](/Image-display#showstimuli)
## controlSound
function: startTime = controlSound(soundFile, varargin)
function: startTime = [controlSound(soundFile, varargin)](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Sound/controlSound.m)
**Description**
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**
~~~
......@@ -84,10 +84,10 @@ Use this function to get control over an audio file that was loaded with loadSou
**Inputs-optional**
~~~
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)
startStop stops playback of the sound after a defined amount of time (in seconds)
delete deletes the loaded file from memory
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)
'startStop' stops playback of the sound after a defined amount of time (in seconds)
'delete' deletes the loaded file from memory
~~~
**Outputs**
......@@ -96,50 +96,50 @@ Use this function to get control over an audio file that was loaded with loadSou
~~~
**Examples**
~~~
~~~matlab
1. controlSound(soundFile);
% playing the whole sound file until the end
2. controlSound(soundFile, play);
2. controlSound(soundFile, 'play');
% 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
4. controlSound(soundFile, stop);
4. controlSound(soundFile, 'stop');
% 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
6. controlSound(soundFile, delete);
6. controlSound(soundFile, 'delete');
% deletes the file stored in soundFile from memory
~~~
**See also**
loadSound, closeSound, loadImage, showStimuli
[loadSound](/Sound-options#loadsound), [closeSound](/Sound-options#closesound), [loadImage](/Image-display#loadimage), [showStimuli](/Image-display#showstimuli)
**Examples**
~~~
~~~matlab
1. listSound;
% automatically get the best results
~~~
**See also**
initSound, controlSound, closeSound
[initSound](/Sound-options#initsound), [controlSound](/Sound-options#controlsound), [closeSound](/Sound-options#closesound)
## closeSound
function: closeSound
function: [closeSound](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Sound/closeSound.m)
**Description**
Use this function to close all audio ports that were initialized using initSound.
Use this function to close all audio ports that were initialized using [initSound](/Sound-options#initsound).
**Examples**
~~~
~~~matlab
1. closeSound
ans = []
~~~
**See also**
loadSound, controlSound
[loadSound](/Sound-options#loadsound), [controlSound](/Sound-options#controlsound)
\ No newline at end of file