How to play beep before each trial

조회 수: 4 (최근 30일)
Takara Sumoto
Takara Sumoto 2019년 9월 9일
댓글: Walter Roberson 2019년 9월 11일
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
Takara Sumoto
Takara Sumoto 2019년 9월 11일
If I made a code like this below, I can only play beep once before all the audio files are played. (Just for trial, I add 3 audio files instead of 80.)
% opens sound buffer at a different frequency
pahandle = PsychPortAudio('Open', [], [], 2, []);
% generate a beep
beepWaveform = MakeBeep(1000,.250,44100);
% make stereo
beepWaveform = repmat(beepWaveform, 2, 1);
% fill buffer
PsychPortAudio('FillBuffer', pahandle, beepWaveform);
% 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);
%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');
% 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
Walter Roberson
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 CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by