2014-09-03 19 views
0

我對編碼完全陌生,字面上只是把事情搞砸了,而且還在努力學習。翻轉頻率可視化 - Java - 正在處理

第一:

所以,我有一段代碼,它可以幫助我從一個音軌可視化的頻率。簡而言之,我只是想知道如何從左到右和從右到左翻轉可視化。在代碼中,我試圖翻轉左上角和左下角。

第二:

此外,如果任何人知道像一路延伸可視化長度草圖的邊緣。

就在一般情況下,如果你能向我解釋爲什麼和如何,無論解決方案可能在這裏學習。非常感謝提前的幫助。

這是我想要翻轉的代碼位。

for(int i = 0; i < song.left.size() - 1; i++) 
{ 
    //TOP - LEFT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

    //Bottom - RIGHT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 

整個草圖:

import ddf.minim.*; 
import ddf.minim.analysis.*; 

Minim minim; 
AudioPlayer song; 
FFT fft; 

void setup() 
{ 
    size(1024, 512, P3D); 

    minim = new Minim(this); 

    song = minim.loadFile("mysong.mp3", 1024); 
    song.play(); 

    fft = new FFT(song.bufferSize(), song.sampleRate()); 
} 

void draw() 
{ 
    background(0); 
    fft.forward(song.mix); 

    stroke(255); 
    strokeWeight(3); 
    for (int i = 0; i < fft.specSize(); i = i+10) // i+10 Controls a sequence of repeated 

    { 
    //TOP - RIGHT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

    //Bottom - LEFT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 

    //TOP - LEFT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

    //Bottom - RIGHT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 
    } 
} 

回答

1

注:所有代碼UNTESTED

// this is drawing one line from center of screen 
// to (top of screen - frequency) 
// returned from a specific "slot"in fft via fft.getBand(i) 

line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

// note that fft.getBand(i) is multiplied by 4. this is your range, 
// increase that number and lines will be bigger 


// the next line does the same but towards the bottom of screen 
// note th '+' instead of '-'' 
// so if you want to keep them with the same range you gotta change here as well 
// better, make a range var.. 
line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 

你有一個循環,從FFT得到每一個波段,並繪製一條線爲每一個(實際上是兩個,一個上下一個)。頻率可視化的順序由您通過fft的順序給出。現在你要從0到fft列表的長度。 去向後和抽籤將翻轉:

// from end to begin... 
for (int i = fft.specSize()-1 ; i > 0; i-=10) 

    { 
    //TOP - RIGHT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 - fft.getBand(i)*4); 

    //Bottom - LEFT 
    line(i/2+width/2, height/2, i/2+width/2, height/2 + fft.getBand(i)*4); 
    } 

或者喲可以使用scale(-1, 0)水平翻轉屏幕......然後你就可以進一步控制轉換與push/popMatrix()

HTH