我正在尝试在psychtoolbox上创建一个实验,其中一部分涉及在参与者无法响应时发出警报。
我尝试使用提供的蜂鸣声,但听起来根本不像是警报。有什么方法可以实现而无需下载外部声音吗?
我不了解声波或声波,所以请帮忙!
最佳答案
以下代码将加载.wav文件,并通过Psychtoolbox音频系统播放该文件。与使用sound()或蜂鸣声相比,这可以使您具有声音开始的时间戳,并可以更好地进行控制。您也可以使用MATLAB本身生成音调(很容易生成特定频率的正弦波),然后使用它代替.wav数据。
%% this block only needs to be performed once, at the start of the experiment
% initialize the Psychtoolbox audio system in low latency mode
InitializePsychSound(1);
% load in a waveform for the warning
[waveform,Fs] = audioread('alarm.wav');
numChannels = size(waveform, 2);
% open the first audio device in low-latency, stereo mode
% if you have more than one device attached, you will need to specify the
% appropriate deviceid
pahandle = PsychPortAudio('Open', 2, [], 1, Fs, numChannels);
%% during the experiment, when you want to play the alarm
PsychPortAudio('FillBuffer', pahandle, waveform' );
startTime = PsychPortAudio('Start', pahandle, 1);
%% at the conclusion of the experiment
PsychPortAudio('Close');
如果您想产生自己的声音,请看一下Psychtoolbox函数“MakeBeep”,并以44.1k采样率将其替换为波形,例如持续时间为250ms的1000 Hz音调,而不是波形:
% generate a beep
beepWaveform = MakeBeep(1000,.250,44100);
% make stereo
beepWaveform = repmat(beepWaveform, 2, 1);
% fill buffer, play
PsychPortAudio('FillBuffer', pahandle, beepWaveform );
startTime = PsychPortAudio('Start', pahandle, 1);