2016-07-14 9 views
0

奇妙なことです。私は処理を続けるか、javaが処理用Webサイトのサンプルコードに基づいてこのコードでクラッシュする。処理中fftクラッシュ

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: RtApiCore::probeDeviceOpen: the device (2) does not support the requested channel count. Could not run the sketch (Target VM failed to initialize).

PC上では、1 MACそれはマックそれだけで地殻それは押しつぶすまで5秒間、別の上で動作し、私はこれを与え上、全く動作しません。

ライブラリやコードに問題があると思いますか? ライブラリに問題がある場合は、このようなことを行うには最高のサウンドライブラリをお勧めしますか?

ありがとうございました:)

import processing.sound.*; 

FFT fft; 
AudioIn in; 
int bands = 512; 
float[] spectrum = new float[bands]; 

void setup() { 
    size(900, 600); 

    background(255); 

    // Create an Input stream which is routed into the Amplitude analyzer 
    fft = new FFT(this, bands); 
    in = new AudioIn(this, 0); 

    // start the Audio Input 
    in.start(); 

    // patch the AudioIn 
    fft.input(in); 
}  

void draw() { 
    background(255); 
    int midPointW = width/2; 
    int midPointH = height/2; 
    float angle = 1; 
    fft.analyze(spectrum); 
    //float radius = 200; 

    for(int i = 0; i < bands; i++){ 
    // create the actions for placing points on a circle 
    float radius = spectrum[i]*height*10; 
    //float radius = 10; 
    float endX = midPointW+sin(angle) * radius*10; 
    float endY = midPointH+cos(angle) * radius*10; 
    float startX = midPointW+sin(angle) * radius*5; 
    float startY = midPointH+cos(angle) * radius*5; 
    // The result of the FFT is normalized 
    // draw the line for frequency band i scaling it up by 5 to get more amplitude. 
    line(startX, startY, endX, endY); 
    angle = angle + angle; 
    println(endX, "" ,endY); 
// if(angle > 360){ 
//  angle = 0; 
// } 
    }  
} 
+0

あなたが何を求めているのか、これがどの言語なのかは少し不明です。これはC、C++、Javaの要素を持っています。あなたのコードが何をすべきかについてもっと具体的に教えてください。それはファイルベースの分析ですか? 'draw()'はどのように呼び出されますか?どのAPIを解析に使用していますか?いくつかの関連情報が欠落しています。 – user3078414

答えて

1

あなたが角度のように使用する値を印刷し、あなたがそれに気付くでしょうY、Xを起動した場合:

  1. 開始/終了のxを、yの値がNaNになります(数ではない - 無効)
  2. 角度はすぐにInfinityに行く(ただし超えた)
あなたが指数関数的にあなたはおそらくしたくない、この値を大きくしている

angle = angle + angle; 

:主な問題の0

一つは、この行です。 さらに、sin()cos()などの三角関数は、度数ではないラジアンを使用するので、値は小さくなる傾向があります。あなたは、剰余演算子(%)またはconstrain()機能を使用して360度またはTWO_PIラジアンに値を制約することができます

angle = (angle + 0.01) % TWO_PI; 

はあなたのangle > 360チェックがそれを示しているかのように非常に近かったです。それをコメントアウトした理由は分かりません。

は、ここでの微調整であなたのコードだとスケッチが5分以上走ったが、私はまだ遭遇したスケッチを閉じるときにJVMがOSX上でクラッシュ

import processing.sound.*; 

FFT fft; 
AudioIn in; 
int bands = 512; 
float[] spectrum = new float[bands]; 

void setup() { 
    size(900, 600); 

    background(255); 

    // Create an Input stream which is routed into the Amplitude analyzer 
    fft = new FFT(this, bands); 
    in = new AudioIn(this, 0); 

    // start the Audio Input 
    in.start(); 

    // patch the AudioIn 
    fft.input(in); 
}  

void draw() { 
    background(255); 
    int midPointW = width/2; 
    int midPointH = height/2; 
    float angle = 1; 
    fft.analyze(spectrum); 
    //float radius = 200; 

    for (int i = 0; i < bands; i++) { 
    // create the actions for placing points on a circle 
    float radius = spectrum[i] * height * 10; 
    //float radius = 10; 
    float endX = midPointW + (sin(angle) * radius * 10); 
    float endY = midPointH + (cos(angle) * radius * 10); 
    float startX = midPointW + (sin(angle) * radius * 5); 
    float startY = midPointH + (cos(angle) * radius * 5); 
    // The result of the FFT is normalized 
    // draw the line for frequency band i scaling it up by 5 to get more amplitude. 
    line(startX, startY, endX, endY); 
    //angle = angle + angle; 
    angle = (angle + 0.01) % TWO_PI;//linearly increase the angle and constrain it to a 360 degrees (2 * PI) 
    } 
} 

void exit() { 
    in.stop();//try to cleanly stop the audio input 
    super.exit(); 
} 

コメントしています。 私はこのサウンドライブラリをあまり使用していませんし、内部を調べていませんが、バグかもしれません。

これがまだ問題を引き起こしている場合は、実用的な理由から、Contribution Managerを使用してFFTサウンド分析用の別の処理ライブラリをインストールすることをおすすめします。ここ は、ライブラリのカップルです:

  1. Minim - ビジュアライゼーション
  2. Beadsに助けることができるいくつかの素晴らしいlinearlogarithmic平均化機能を提供 - 構文のような豊かなが、よりJavaのを備えています。無料の本もあります:Sonifying Processing

どちらのライブラリもFFTの例を提供しています。