2011-04-20 27 views
0

我找到了一個名爲JVST的庫,可以加載VST文件並相應地過濾音頻。問題是,我不知道如何使用它。我所能做的只是從網站上覆制和粘貼示例代碼,並根據需要進行調整,但仍然無法正常工作。我想要做的是扭曲用戶選擇模擬揚聲器的.au或.wav文件的音頻。我不確定多頻段壓縮是否是最好的使用方式,但是我會嘗試一下,如果失敗了,我可以使用一大堆自定義VST插件。不管怎麼說,這裏是代碼:試圖扭曲Java中的音頻

import sun.audio.*; //import the sun.audio package 
import java.awt.*; 
import java.io.*; 
import org.boris.jvst.*; 
@SuppressWarnings("serial") 
public class SoundPlayer extends Frame implements FilenameFilter { 
Button openButton = new Button("Open"); 
Button playButton = new Button("Play"); 
Button loopButton = new Button("Loop"); 
Button stopButton = new Button("Stop"); 
Label filename = new Label("     "); 
File theFile = null; 
@SuppressWarnings({ "restriction" }) 
AudioData theData = null; 
InputStream nowPlaying = null; 

@SuppressWarnings({ "deprecation" }) 
public SoundPlayer() { 
    super("Boombox"); 
    resize(300, 200); 
    Panel north = new Panel(); 
    north.setLayout(new FlowLayout(FlowLayout.LEFT)); 
    north.add(new Label("File: ")); 
    north.add("North", filename); 
    add("North", north); 
    Panel south = new Panel(); 
    south.add(openButton); 
    south.add(playButton); 
    south.add(loopButton); 
    south.add(stopButton); 
    add("South", south); 
} 

@SuppressWarnings("deprecation") 
public static void main(String[] args) { 
    SoundPlayer sp = new SoundPlayer(); 
    sp.show(); 
} 

@SuppressWarnings({ "deprecation", "restriction" }) 
public void open() { 
    FileDialog fd = new FileDialog(this, "Please select a .au or .wav file:"); 
    fd.setFilenameFilter(this); 
    fd.show(); 
    try { 
     theFile = new File(fd.getDirectory() + "/" + fd.getFile()); 
     if (theFile != null) { 
      filename.setText(theFile.getName()); 
      FileInputStream fis = new FileInputStream(theFile); 
      AudioStream as = new AudioStream(fis); 
      theData = as.getData(); 
     } 
    } 
    catch (IOException e) { 
     System.err.println(e); 
    } 
} 

@SuppressWarnings("restriction") 
public void play() { 
    stop();  
    if (theData == null) open(); 
    if (theData != null) { 
     AudioDataStream ads = new AudioDataStream(theData); 
     AudioPlayer.player.start(ads); 
     nowPlaying = ads; 
    } 
} 

@SuppressWarnings("restriction") 
public void stop() { 
    if (nowPlaying != null) { 
     AudioPlayer.player.stop(nowPlaying); 
     nowPlaying = null; 
    } 
} 

@SuppressWarnings("restriction") 
public void loop() { 
    stop(); 
    if (theData == null) open(); 
    if (theData != null) { 
     ContinuousAudioDataStream cads = new ContinuousAudioDataStream(theData); 
     AudioPlayer.player.start(cads); 
     nowPlaying = cads; 
    } 
} 

public boolean action(Event e, Object what) { 

    if (e.target == playButton) { 
     play(); 
     return true; 
    } 
    else if (e.target == openButton) { 
     open(); 
     return true; 
    } 
    else if (e.target == loopButton) { 
     loop(); 
     return true; 
    } 
    else if (e.target == stopButton) { 
     stop(); 
     return true; 
    } 

    return false; 

} 

public boolean accept(File dir, String name) { 

    name = name.toLowerCase(); 
    if (name.endsWith(".au")) return true; 
    if (name.endsWith(".wav")) return true; 
    return false; 
    public static void main(String[] args); throws Exception { 
     AEffect a = VST.load("C:/Program Files (x86)/Audacity 1.3 Beta (Unicode)/Plug-Ins/mda MultiBand.dll"); 
     a.open(); 
     a.setSampleRate(44100.0f); 
     a.setBlockSize(512); 

     // attempt some processing 
     int blocksize = 512; 
     float[][] inputs = new float[a.numInputs][]; 
     for (int i = 0; i < a.numInputs; i++) { 
      inputs[i] = new float[blocksize]; 
      for (int j = 0; j < blocksize; j++) 
       inputs[i][j] = (float) Math 
       .sin(j * Math.PI * 2 * 440/44100.0); 
     } 
     float[][] outputs = new float[a.numOutputs][]; 
     for (int i = 0; i < a.numOutputs; i++) { 
      outputs[i] = new float[blocksize]; 
      for (int j = 0; j < blocksize; j++) 
       outputs[i][j] = 0; 
     } 

     a.processReplacing(inputs, outputs, blocksize); 

     VST.dispose(a); 
    } 
} 
} 

編輯 它給人的錯誤是:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

    at SoundPlayer.main(SoundPlayer.java:35) 
+1

你可能想縮小一下你的問題。 「它不起作用」不是一個有用的描述。 – 2011-04-20 22:41:38

+0

這條線是什麼? (幾乎在最後)'public static void main(String [] args);拋出異常{' – MByD 2011-04-20 23:18:05

+0

我從[http://jvst.sourceforge.net/]獲得了它@MByD – yutsi 2011-04-21 01:12:06

回答

0

我進口JVST JAR到我的構建路徑,瞧!進口org.boris.jvst。*;工作