1

私は、次のようなサウンド修飾子に取り組んでいます。

1) ユーザーから入力を取得する ( X,Y )

2) XYを使用して、所定のサウンド ファイルにエフェクトを適用します。

コードを追うのは少し難しいので、特に必要がない限り投稿しません。

私は 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

注: ピッチシフトは、特定のサウンド ファイルのピッチを変更する機能です。

4

1 に答える 1

0

コメントとコードをより注意深く読んだ後、グローバル変数は必要ありません。代わりに、次のようにします。

function effectBox(X,Y)
  % whatever code you need here...

コールバックの設定:

h = figure; % create new figure, get handle
set h, 'WindowButtonMotionFcn', @mouseMove); % execute mouseMove when mouse moves

コールバックは次のようになります。

Function mouseMove()
  C = get (gca, 'CurrentPoint'); % read current position of mouse when it moves
  effectBox( C(1), C(2) ); % calls effectBox with mouse coordinates X,Y

注 - 現在、Matlab ライセンスのあるマシンの近くにいないため、これをテストできませんでした。期待どおりに動作しない場合は、コメントで教えてください。解決のお手伝いをします。

于 2013-05-10T02:36:48.703 に答える