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.

run_me.m
global d Fs st ao pc ps hf L
global x1 x2 y1 y2 x y yac k ind yac_hist


% read wav file
[FileName,PathName] = uigetfile('*.wav','Select the wav-file');
[d Fs]=wavread([PathName FileName]);
L=length(d);
% stop button:
st=false; % stop flag
hf=figure;
h = uicontrol('Style', 'pushbutton', 'String', 'Stop',...
    'units','normalized',...
    'fontsize',12,...
    'Position', [0.4 0.4 0.2 0.1], 'Callback', 'stp');


% prepare mouse limits:
ss=get(0,'ScreenSize');
dxm=0.2;
dym=0.2; % relative margin
dx=round(dxm*ss(3));
dy=round(dxm*ss(4));
x1=ss(1)+dx;
x2=ss(1)+ss(3)-dx;
y1=ss(2)+dy;
y2=ss(2)+ss(4)-dy;

% mouse position:
pr=get(0,'PointerLocation');
x=pr(1);
y=pr(2);
k=7; % gain between mouse and index in wave   indes_in_wave=k*yac
yac=round(L/2/k); % accamulative y position
yac_hist=yac*ones(6,1); % yac history

% prepare device:
ao = analogoutput('winsound');
ch = addchannel(ao,1:2);
set(ao,'SampleRate',Fs)
p=0.025; % sec, piece size
ps=round(p*Fs); % piece size as index
set(ao,'BufferingConfig',[ps 4]);
set(ao,'SamplesOutputFcn','add_to_buffer');
set(ao,'SamplesOutputFcnCount',ps);
pc=1; % piece conter
% make margin
for mc=1:3 % 3 pieces margin
    i1=1+(pc-1)*ps;
    i2=pc*ps;
    d1=d(i1:i2,:);
    putdata(ao,d1);
    pc=pc+1;
end
start(ao); % start looped process

Contact us