Hi,
i'm forwarding this to the psychtoolbox forum in case it is of
general interest.
yes that's doable and works on all operating systems. The
'FillBuffer' call has an optional 'streamingrefill' flag. If you set
it to 1, it allows to "append" sound to the buffer. Technically it
doesn't really append, but it refills the parts of the buffer that
are already played out, so if you'd refill 1 second of sound, the
function would either return immediately if 1 sec of space is free in
the buffer, or it would wait until space becomes available and then
append.
BasicSoundFeedbackDemo shows this. It implements a sound feedback
loop with controllable latency to create an echo effect if you have a
microphone attached.
Looping is also simple. Just set the 'repetition' parameter in the
'Start' call to zero -- then it repeats until you 'Stop' it. The
lastest driver also has the concept of setting 'stop' times to
preprogram the time of sound offset.
The latest ptb beta also has the commands...
PsychPortAudio('RefillBuffer', pahandle [, bufferhandle=0],
bufferdata [, startIndex=0]);
PsychPortAudio('SetLoop', pahandle[, startSample=0][, endSample=max]
[, UnitIsSeconds=0]);
...to refill arbitrary parts of the buffer during playout, or define
a playback loop in some subpart of the buffer, e.g., allocate a large
buffer, load it with multiple different chunks of sound and switch
between them by changing the "soundloop" that is actually used during
playback
Also new is support for "Schedules", basically like playlists on a
media player. You can define a whole sequence of sound-loops that are
played one after each other to create complex sound on the fly from
predefined sound chunks:
PsychPortAudio('UseSchedule', pahandle, enableSchedule [, maxSize =
128]);
[success, freeslots] = PsychPortAudio('AddToSchedule', pahandle [,
bufferHandle=0][, repetitions=1][, startSample=0][, endSample=max][,
UnitIsSeconds=0]);
I also intend to add support for multiple buffers in a future beta
(like textures or offscreen windows) to make handling of such things
more natural.
There aren't any demos for this new stuff yet, but the online help
should get you started.
One thing that might make sense for most serious playback is to
select the 'reqlatencieclass' setting in PsychPortaudio('Open') as 1,
instead of the default of zero. This selects low-latency mode, but as
a side-effect it also optimized for highest timing precision, which
is more important than low latency most of the time. Oh and it
disables sound-dithering as well: Normally the least significant bit
of a sound signal is modulated with random dithering to reduce
quantization artifacts due to the limited bit-depths of the audio
DAC's. This is good for sound quality, but for very low-level studies
of sound perception you may want to have the sound signal as
unaltered or unaffected as possible.
On MS-Windows it is important to use a professional sound card with
ASIO driver support and the special plugin one can download from the
Wiki for that purpose. Without ASIO support, the standard Windows
sound system only provides very high latencies, miserable timing for
sound onset and offset etc.
i'm forwarding this to the psychtoolbox forum in case it is of
general interest.
yes that's doable and works on all operating systems. The
'FillBuffer' call has an optional 'streamingrefill' flag. If you set
it to 1, it allows to "append" sound to the buffer. Technically it
doesn't really append, but it refills the parts of the buffer that
are already played out, so if you'd refill 1 second of sound, the
function would either return immediately if 1 sec of space is free in
the buffer, or it would wait until space becomes available and then
append.
BasicSoundFeedbackDemo shows this. It implements a sound feedback
loop with controllable latency to create an echo effect if you have a
microphone attached.
Looping is also simple. Just set the 'repetition' parameter in the
'Start' call to zero -- then it repeats until you 'Stop' it. The
lastest driver also has the concept of setting 'stop' times to
preprogram the time of sound offset.
The latest ptb beta also has the commands...
PsychPortAudio('RefillBuffer', pahandle [, bufferhandle=0],
bufferdata [, startIndex=0]);
PsychPortAudio('SetLoop', pahandle[, startSample=0][, endSample=max]
[, UnitIsSeconds=0]);
...to refill arbitrary parts of the buffer during playout, or define
a playback loop in some subpart of the buffer, e.g., allocate a large
buffer, load it with multiple different chunks of sound and switch
between them by changing the "soundloop" that is actually used during
playback
Also new is support for "Schedules", basically like playlists on a
media player. You can define a whole sequence of sound-loops that are
played one after each other to create complex sound on the fly from
predefined sound chunks:
PsychPortAudio('UseSchedule', pahandle, enableSchedule [, maxSize =
128]);
[success, freeslots] = PsychPortAudio('AddToSchedule', pahandle [,
bufferHandle=0][, repetitions=1][, startSample=0][, endSample=max][,
UnitIsSeconds=0]);
I also intend to add support for multiple buffers in a future beta
(like textures or offscreen windows) to make handling of such things
more natural.
There aren't any demos for this new stuff yet, but the online help
should get you started.
One thing that might make sense for most serious playback is to
select the 'reqlatencieclass' setting in PsychPortaudio('Open') as 1,
instead of the default of zero. This selects low-latency mode, but as
a side-effect it also optimized for highest timing precision, which
is more important than low latency most of the time. Oh and it
disables sound-dithering as well: Normally the least significant bit
of a sound signal is modulated with random dithering to reduce
quantization artifacts due to the limited bit-depths of the audio
DAC's. This is good for sound quality, but for very low-level studies
of sound perception you may want to have the sound signal as
unaltered or unaffected as possible.
On MS-Windows it is important to use a professional sound card with
ASIO driver support and the special plugin one can download from the
Wiki for that purpose. Without ASIO support, the standard Windows
sound system only provides very high latencies, miserable timing for
sound onset and offset etc.
On Feb 4, 2009, at 1:42 PM, Vinzenz Schoenfelder wrote:
> hi mario,
> i'm using a fireface firewire-soundcard (with coreaudio output in
> mac os x) to output sound data onto multiple channels. so far, i
> use the standard PsychPortAudio('FillBuffer','Start','Stop')-
> routines to output small chunks of audio.
> is there any way to generate a continuous sound stream, that is fed
> with new data during playing, or that loops without interruption,
> e.g. a continuous sine wave? does it depend on the system matlab
> runs on (linux, mac, windows)?
> kind wishes from berlin
> vinzenz
> ps. i'm writing in english, since a friend (see Cc) of ours in
> london, is also interested.