Hi,
I am running PTB 3 on Matlab R2009b on Mac OSX.
I would like to implement a gui with a slider that allows the user to change the frequency of a tone and another slider to control the amplitude. I would like to overlap the windowed data blocks so that I can make smooth transitions between frequencies and amplitudes. If I just send a stream of sine wave blocks there will pops and clicks between the blocks.
Can anybody help with this? It would be great to be able to do this for a lot of projects.
I have considered parallel audio objects that each play every other block, offset by half a block, but haven't yet attempted to implement this. I will keep you posted on progress.
My current (working with clicks) code is below:
fs = 44100;
buff_len= 512;
%generate initial audiodata
freq = 900;
amp = .5;
t=1/fs:1/fs:1/fs*buff_len; % create time signals
x=amp*sin(2*pi*freq*t);
window = hanning(buff_len)';%50 percent overlap window
audiodata = x.*window;
audiodata(2,:) = 0;%second channel addressed elsewhere
%open audio
pahandle_1 = PsychPortAudio('Open', [], 1,2,fs,2,[], 0.010);
PsychPortAudio('FillBuffer', pahandle_1, audiodata);
playbackstart = PsychPortAudio('Start', pahandle_1, 0, 0, 1);
while get(hObject,'Value') == 1%while the gui switch is on
% Generate new captured sound data
freq = get(handles.freq_slid_1,'Value')*fs/2;%check slider for freq
amp = get(handles.amp_slid_1,'Value');%check slider for amp
t=1/fs:1/fs:1/fs*buff_len; % create new time signals
x =amp*sin(2*pi*freq*t);
window = hanning(buff_len)';
audiodata = x.*window;
audiodata(2,:) = 0;
WaitSecs((buff_len/fs)/2);%wait for half the signal to play before refilling the buffer
%also need to account for latency somewhere around here
PsychPortAudio('FillBuffer', pahandle_1, audiodata, 1);
drawnow%so matlab can see the sliders while in a loop
end
Thank you.
I am running PTB 3 on Matlab R2009b on Mac OSX.
I would like to implement a gui with a slider that allows the user to change the frequency of a tone and another slider to control the amplitude. I would like to overlap the windowed data blocks so that I can make smooth transitions between frequencies and amplitudes. If I just send a stream of sine wave blocks there will pops and clicks between the blocks.
Can anybody help with this? It would be great to be able to do this for a lot of projects.
I have considered parallel audio objects that each play every other block, offset by half a block, but haven't yet attempted to implement this. I will keep you posted on progress.
My current (working with clicks) code is below:
fs = 44100;
buff_len= 512;
%generate initial audiodata
freq = 900;
amp = .5;
t=1/fs:1/fs:1/fs*buff_len; % create time signals
x=amp*sin(2*pi*freq*t);
window = hanning(buff_len)';%50 percent overlap window
audiodata = x.*window;
audiodata(2,:) = 0;%second channel addressed elsewhere
%open audio
pahandle_1 = PsychPortAudio('Open', [], 1,2,fs,2,[], 0.010);
PsychPortAudio('FillBuffer', pahandle_1, audiodata);
playbackstart = PsychPortAudio('Start', pahandle_1, 0, 0, 1);
while get(hObject,'Value') == 1%while the gui switch is on
% Generate new captured sound data
freq = get(handles.freq_slid_1,'Value')*fs/2;%check slider for freq
amp = get(handles.amp_slid_1,'Value');%check slider for amp
t=1/fs:1/fs:1/fs*buff_len; % create new time signals
x =amp*sin(2*pi*freq*t);
window = hanning(buff_len)';
audiodata = x.*window;
audiodata(2,:) = 0;
WaitSecs((buff_len/fs)/2);%wait for half the signal to play before refilling the buffer
%also need to account for latency somewhere around here
PsychPortAudio('FillBuffer', pahandle_1, audiodata, 1);
drawnow%so matlab can see the sliders while in a loop
end
Thank you.