How to play beep before each trial
6 views (last 30 days)
Show older comments
I have 80 audio files and I want to play beep before each audio starts as a cue.
Should I add "Beeper(400, [0.3], [0.5]);" in the loop, or outside of the loop?
for i=1:length(audio_files)
aud_file=strcat('C:\toolbox\aud_file\',audio_files(i).name);
% load sound file (make sure that it is in the same folder as this script)
[soundData freq]=audioread(aud_file);
% opens sound buffer at a different frequency
pahandle = PsychPortAudio('Open', [], [], 2, []);
% loads data into buffer
PsychPortAudio('FillBuffer', pahandle, soundData');
% how many repititions of the sound
repetitions=1;
%starts sound immediatley
PsychPortAudio('Start', pahandle, repetitions,0);
% stop
PsychPortAudio('Stop', pahandle, 1,0);
%wait
WaitSecs(3);
%close
PsychPortAudio('Close', pahandle);
end
5 Comments
Walter Roberson
on 11 Sep 2019
% opens sound buffer at a different frequency
pabhandle = PsychPortAudio('Open', [], [], 2, []);
% generate a beep
beepWaveform = MakeBeep(1000,.250,44100);
% make stereo
beepWaveform = repmat(beepWaveform, 2, 1);
% fill buffer
PsychPortAudio('FillBuffer', pabhandle, beepWaveform);
% how many repititions of the sound
repetitions=1;
%randomaize
a=randperm(3);
for i=1:length(audio_files)
aud_file=strcat('C:\toolbox\aud_file\',audio_files(a(i)).name);
% load sound file (make sure that it is in the same folder as this script)
[soundData freq]=audioread(aud_file);
% opens sound buffer at a different frequency
pahandle = PsychPortAudio('Open', [], [], 2, []);
% loads data into buffer
PsychPortAudio('FillBuffer', pahandle, soundData');
%starts beep sound immediatley
PsychPortAudio('Start', pabhandle, repetitions,0);
% stop beep
WaitSecs(1);
PsychPortAudio('Stop', pabhandle, 1,0);
% how many repititions of the sound
repetitions=1;
%starts sound immediatley
PsychPortAudio('Start', pahandle, repetitions,0);
% stop
PsychPortAudio('Stop', pahandle, 1,0);
%wait
WaitSecs(1);
%close
PsychPortAudio('Close', pahandle);
end
%close beep
PsychPortAudio('Close', pabhandle);
Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!