How to play beep before each trial
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2019년 9월 11일
% 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);
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!