Code covered by the BSD License  

Highlights from
home made turntable

image thumbnail

home made turntable

by

Maxim Vedenyov (view profile)

 

Transforms mouse motion to sound to make scratch effect.

add_to_buffer
function add_to_buffer
global d st ao pc ps hf L
global x1 x2 y1 y2 x y yac k ind yac_hist

if ~ishandle(hf) % when figure closed then also stop:
    st=true;
end
if st
    set(ao,'SamplesOutputFcn','');
    if ishandle(hf)
        close(hf); % close figure with button
    end
else
    
    % read mouse:
    pr=get(0,'PointerLocation');
    x_old=x;
    y_old=y;
    x=pr(1);
    y=pr(2);
    yac_old=yac;
    yac=yac+y-y_old; % accumulative y
    
    % cyclic behaviour:
    islim=false;
    if x>x2
        islim=true;
        x=x1+x-x2;
    end
    if x<x1
        islim=true;
        x=x2+x-x1;
    end
    if y>y2
        islim=true;
        y=y1+y-y2;
    end
    if y<y1
        islim=true;
        y=y2+y-y1;
    end
    if islim
        set(0,'PointerLocation',[x y]);
    end
    
    yac_hist=[yac_hist(2:6); yac]; % history
    
    % preapre piece:
    %ind=round(k*(yac_old+(yac-yac_old)*((0:ps-1)/ps))); % linear interpolation
    % yi = interp1(x,Y,xi,method)
    %ind=round(k*interp1((0:5)',yac_hist,(2+(0:ps-1)'/ps),'spline'));
    yac_old_ma=mean(yac_hist(1:5));
    yac_ma=mean(yac_hist(2:6));
    ind=round(k*(yac_old_ma+(yac_ma-yac_old_ma)*((0:ps-1)/ps))); % MA
    f12=find((ind>1)&(ind<L));
    if length(f12)~=ps
        f1=find(ind<1);
        Lf1=length(f1);
        f2=find(ind>L);
        Lf2=length(f2);
        d1(:,1)=[zeros(Lf1,1); d(ind(f12),1); zeros(Lf2,1)];
        d1(:,2)=[zeros(Lf1,1); d(ind(f12),2); zeros(Lf2,1)];
    else
        d1=d(ind,:);
    end
        
    
    
    % add to buffer:
    putdata(ao,d1);
    pc=pc+1;
end
    

Contact us