# Active (&quot;realtime&quot;) Audio Processing

**URL:** <https://psychtoolbox.discourse.group/t/active-quot-realtime-quot-audio-processing/579>\
**Category:** Uncategorized\
**Created:** [May 28, 2010, 5:47pm UTC](https://psychtoolbox.discourse.group/t/active-quot-realtime-quot-audio-processing/579 "2010-05-28T17:47:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [May 28, 2010, 5:47pm UTC](https://psychtoolbox.discourse.group/t/active-quot-realtime-quot-audio-processing/579/1 "2010-05-28T17:47:56Z")

</div>

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.
