This is exactly what I needed! When I first got the 'Unable to write into sound device'-error I didn't know how to solve it. This small script did exactly what I wanted it to do. Thanks!
Aaaarrgh! Thanks! Took me ages to find out why my program crashed. And with the tipp from chi-feng tai your fix actually works. I recommend calling it beep3.m to avoid conflict with psychtoolbox' makebeep.m
Peggy Chen,
There is one improvment that can be done for Window PC user.
Instead of using SND('Wait'), it is better to use pause(seconds). If the beep sound duration is shorter than 1 seconds. SND('Wait') will not work. No beeps at all.
SND('Quiet') = SND('Close'). Just need to use one of them. Don't need to repeat the same action which is clear playsnd.
Bothe example will give you 1000 beeps without giving you an error message.
example1:
Beep=sin([1:400]);
rate=22254;
for n=1:1000
SND('Play',Beep,rate);
pause((length(Beep)/rate));
SND('Close');
end
Example2 (Another simpler and better code):
Beep=sin([1:400]);
rate=22254;
for n=1:1000
sound(Beep,rate);
pause((length(Beep)/rate))
clear playsnd
end
I checked the beep2.m and i think althoug you tried to make a variation of that file, but the ofiginal is still better. But it's good you had the courage to modify it.