我正在研究一种声音修改器,它将:
1)从用户那里获取输入(X,Y)
2) 使用X和Y将效果应用到预定的声音文件
该代码有点难以理解,因此除非另有要求,否则我不会发布它。
我有一个名为 effectBox.m 的函数:
function[] = effectBox(x,y)
顾名思义,它将效果应用于 for 循环中的 10 个连续声音样本。
我想在每次发生事件时更改 (x,y)。
我使用了回调:
function sounder()
f=figure;
set(f,'WindowButtonMotionFcn',@effectBox);
当鼠标移动时,它会获取触发事件的第一个 X 和 Y 值,并将效果应用于所有 10 个样本。但是我希望每次鼠标再次移动时它都会改变。
换句话说,sounder.m 调用并为 effectBox.m 提供第一组输入,但我希望它能够在代码运行时也能做同样的事情。
我在这个项目上工作了很长时间,我真的不知道如何克服这个障碍。我怎样才能解决这个问题?
编辑:这是我对 effectBox.m 有效的代码
clc
clear all
%Load Sound File
[ses Fs] = wavread ('C:\Users\Ogulcan\Desktop\Bitirme Projesi\Codes\kravitz.wav');
%Adjust the sound file so that both channels represent a 1-D matrix
leftChannel = ses(:,1);
rightChannel = ses(:,2);
sound = (leftChannel + rightChannel) / 2;
%length of the sample
t=length(sound);
%number of samples
ns=10;
i=1;
per=t/ns;
%Divide the sample into 5 parts and apply vibrato and pitchshift to each sample.
while i<ns;
global x
global y
coords = get(0,'PointerLocation');
%the timer object triggers every second. If you need it faster, decrease the value for
%Period
timerObj = timer('TimerFcn',@timerCallback,'Period', per);
x=coords(1);
y=coords(2);
start(timerObj);
v=sound(i*t/ns:(i+1)*t/ns);
e1 = pitchShift(v,1024,256,x/100);
a=size (e1+1);
vl = 1:a(2);
k = vl/5000;
%The cursors position in the x axis is our input.
vib= sin(pi*y*k/450);
%Add the vibrato effect to the sound
e=(e1.*vib);
wavplay(10*e,44100);
if i==9
i=1;
end
i=i+1;
end
注意:pitchshift 是一个改变给定声音文件音高的函数。