在psychtoolbox matlab中创建警报声音
Creating alarm sound in psychtoolbox matlab
我正在尝试在 psychtoolbox 上创建一个实验,其中一部分涉及在参与者未能响应时发出警报。
我尝试使用提供的蜂鸣声,但它听起来一点也不像闹钟。有什么办法可以不用下载外部声音就可以实现吗?
我对声音或声波一无所知,所以请帮忙!
对我来说,beep
可以像这样在循环中多次播放它来做你想做的事:
% Adjust the no. of loop iterations depending on how long you want to play the alarm
for k=1:100
beep; pause(1);
end
除此之外,您可以使用 built-in 听起来像这样:
load('gong'); % This sound seems suitable to me for alarm. Try others from the list
for k=1:100
sound(y,Fs); pause(1);
end
以下是您可能想要尝试的 built-in 声音列表:
chirp
gong
handel
laughter
splat
train
以下代码将加载一个 .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',并将其替换为波形,例如 1000 Hz 音调,持续 250 毫秒,以 44.1k 采样率:
% 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);
我正在尝试在 psychtoolbox 上创建一个实验,其中一部分涉及在参与者未能响应时发出警报。
我尝试使用提供的蜂鸣声,但它听起来一点也不像闹钟。有什么办法可以不用下载外部声音就可以实现吗?
我对声音或声波一无所知,所以请帮忙!
对我来说,beep
可以像这样在循环中多次播放它来做你想做的事:
% Adjust the no. of loop iterations depending on how long you want to play the alarm
for k=1:100
beep; pause(1);
end
除此之外,您可以使用 built-in 听起来像这样:
load('gong'); % This sound seems suitable to me for alarm. Try others from the list
for k=1:100
sound(y,Fs); pause(1);
end
以下是您可能想要尝试的 built-in 声音列表:
chirp
gong
handel
laughter
splat
train
以下代码将加载一个 .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',并将其替换为波形,例如 1000 Hz 音调,持续 250 毫秒,以 44.1k 采样率:
% 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);