Fast Dynamic Audio Ramp

Hello there,

I've been struggling with this for a while now. I want to be able to
play a tone and let the user decide when to shut the tone off by
pressing a key without any clicks. Obviously, a click occurs if I just
interrupt playback with a PsychPortAudio('Stop') command after a keypress.

The closest I've come is by using something similar to the fade-out
method at the end of the BasicAMAndMixScheduleDemo file. My code is:

tic
while toc < .2
ramp = 1 - (toc*5);
PsychPortAudio('Volume', pahandle, ramp);
end
PsychPortAudio('Stop', pahandle);

Unfortunately, because this ramps so quickly (200 milliseconds is about
as slow as I can afford), I get easily audible noise artifacts as it
ramps. How else can I achieve my goal of being able to stop a tone in
real time without a click?

I'm on Windows 7 using Asio4all with crummy default laptop audio audio
drivers.

Thank you for any help,

Andy
Hi,

> I've been struggling with this for a while now. I want to be able to
> play a tone and let the user decide when to shut the tone off by
> pressing a key without any clicks. Obviously, a click occurs if I just
> interrupt playback with a PsychPortAudio('Stop') command after a keypress.
>
> The closest I've come is by using something similar to the fade-out
> method at the end of the BasicAMAndMixScheduleDemo file. My code is:
So, you've already come quite close: You need to use the Master+Slave+AM-(amplitude-modulation)-Slave device approach. The audio signal goes into the first slave device. Your envelope/ramp goes in to AM-Slave device (type 32) including a sufficient number of zeros at the end. You can start both slave devices independently. The AM-slave is started immediately after your keypress. The audio signal is then multiplied by the AM envelope. When the envelope reaches the time range with zero amplitude you can safely stop the playback without hearing clicks.

To my experience your approach changing the volume will introduce clicks with most sound cards.

> tic
> while toc < .2
> ramp = 1 - (toc*5);
> PsychPortAudio('Volume', pahandle, ramp);
> end
> PsychPortAudio('Stop', pahandle);
>
> Unfortunately, because this ramps so quickly (200 milliseconds is about
> as slow as I can afford), I get easily audible noise artifacts as it
> ramps. How else can I achieve my goal of being able to stop a tone in
> real time without a click?
>
> I'm on Windows 7 using Asio4all with crummy default laptop audio audio
> drivers.
I would expect very bad timing behavior with this combination.

Hope this helps,
Andreas


> Thank you for any help,
>
> Andy
>
>
> ------------------------------------
>
> Post your message to: psychtoolbox@yahoogroups.com
> Please indicate OS9, OSX, or WIN version, and include your full name.
> Denis Pelli, David Brainard, and Allen Ingling.
> http://psychtoolbox.org
> Yahoo! Groups Links
>
>
>
Thank you very much! This solved it and it works perfectly.

On 12/20/2012 6:56 AM, Andreas Widmann wrote:
> Hi,
>
>> I've been struggling with this for a while now. I want to be able to
>> play a tone and let the user decide when to shut the tone off by
>> pressing a key without any clicks. Obviously, a click occurs if I just
>> interrupt playback with a PsychPortAudio('Stop') command after a keypress.
>>
>> The closest I've come is by using something similar to the fade-out
>> method at the end of the BasicAMAndMixScheduleDemo file. My code is:
> So, you've already come quite close: You need to use the Master+Slave+AM-(amplitude-modulation)-Slave device approach. The audio signal goes into the first slave device. Your envelope/ramp goes in to AM-Slave device (type 32) including a sufficient number of zeros at the end. You can start both slave devices independently. The AM-slave is started immediately after your keypress. The audio signal is then multiplied by the AM envelope. When the envelope reaches the time range with zero amplitude you can safely stop the playback without hearing clicks.
>
> To my experience your approach changing the volume will introduce clicks with most sound cards.
>
>> tic
>> while toc < .2
>> ramp = 1 - (toc*5);
>> PsychPortAudio('Volume', pahandle, ramp);
>> end
>> PsychPortAudio('Stop', pahandle);
>>
>> Unfortunately, because this ramps so quickly (200 milliseconds is about
>> as slow as I can afford), I get easily audible noise artifacts as it
>> ramps. How else can I achieve my goal of being able to stop a tone in
>> real time without a click?
>>
>> I'm on Windows 7 using Asio4all with crummy default laptop audio audio
>> drivers.
> I would expect very bad timing behavior with this combination.
>
> Hope this helps,
> Andreas
>
>
>> Thank you for any help,
>>
>> Andy
>>
>>
>> ------------------------------------
>>
>> Post your message to: psychtoolbox@yahoogroups.com
>> Please indicate OS9, OSX, or WIN version, and include your full name.
>> Denis Pelli, David Brainard, and Allen Ingling.
>> http://psychtoolbox.org
>> Yahoo! Groups Links
>>
>>
>>