Psychportaudio: live merging of buffers

Hi all, I have a question for any Psychportaudio users. I'm trying to do teh following:
I have a large number of small sound files (~800 ms), each of which is loaded into its own psychportaudio buffer. What I want to do is play them in a sequence *roughly* 500-700 ms apart, with two stipulations which are my problem:
1) The onset time of each sound file can change dynamically during the sequence... i.e., we don't know (based on some participant feedback) until just after sound a has started whether sound b needs to start 500, 525, 550 etc ms after sound a started. To solve this I could of course psychportaudio refillbuffer to selectively "punch in" sound b into thr ongoing buffer but:
2) because of a combination of clip length and time between onsets, sounds a and b would overlap. I DON'T want to just abruptly stop sound a and start b, I'd like to mix them. Of course, if onset times were predicatble then I could just create a big buffer and mix the sounds myself, but, see point 1 :-)

So, is there any way I'm missing of being able to dynamically update a playing buffer by MERGING a second buffer into it rather than replacing information in there? (or alternatively, to read out what that section of the buffer currently contains, so I can create a new mixed buffer to "punch in"?)

Thanks for any help, ladies and gentlemen

Jim
--- In psychtoolbox@yahoogroups.com, "jim.parkinson" <jimparkinson@...> wrote:
>
> Hi all, I have a question for any Psychportaudio users. I'm trying to do teh following:
> I have a large number of small sound files (~800 ms), each of which is loaded into its own psychportaudio buffer. What I want to do is play them in a sequence *roughly* 500-700 ms apart, with two stipulations which are my problem:
> 1) The onset time of each sound file can change dynamically during the sequence... i.e., we don't know (based on some participant feedback) until just after sound a has started whether sound b needs to start 500, 525, 550 etc ms after sound a started. To solve this I could of course psychportaudio refillbuffer to selectively "punch in" sound b into thr ongoing buffer but:
> 2) because of a combination of clip length and time between onsets, sounds a and b would overlap. I DON'T want to just abruptly stop sound a and start b, I'd like to mix them. Of course, if onset times were predicatble then I could just create a big buffer and mix the sounds myself, but, see point 1 :-)
>
> So, is there any way I'm missing of being able to dynamically update a playing buffer by MERGING a second buffer into it rather than replacing information in there? (or alternatively, to read out what that section of the buffer currently contains, so I can create a new mixed buffer to "punch in"?)
>

BasicAMAndMixScheduleDemo.m is probably a good start for you. It shows how to create multipe "virtual" sound cards, attached to a real one, control each of them independently and mix their output together and/or apply some amplitude modulation (envelope function) to each of these virtual cards. It also shows how to use sound schedules to define playlists of sound buffers, with controllable timing between buffers and the ability to update the playlist while playing.

For your task you'd probably look at the way that demo mixes beep sounds with white noise, you may not even need the "sound schedule" functionality, just two audio slave devices attached to the single real master device. Then you can attach soundbuffer a) to the 1st device and start playing, attach buffer b) to the 2nd device and once you know when that sound should start playing, call 'Start' with proper requested onset times, then probably recycle the 1st device again to attach some sound buffer c) etc. On half-way recent computer hardware, the driver can handle dozens of such slave devices and mix their sounds together, each with independent control of timing, volume and envelope corve for amplitude modulation.

There is also BasicSoundScheduleDemo which shows different uses for sound schedules.

best,
-mario