2011-12-26 9 views
-1

私はVib Ribbonをリメイクしようとしています:http://www.youtube.com/watch?v=ehdymXc0epY 入力は.wavファイルになります。それを分析し、ボリュームやピッチのしきい値を作成してさまざまな障害を引き起こす方法について少しは考えていません。私は理解していないフーリエ変換を指摘してきました。誰かがこの状況で動作する波形解析クラスを教えてもらえますか? AudioSurfや音楽ビジュアライザーなどのソースコードを手に入れることはできませんでした。Javaで.wavファイルの音量、ピッチ、およびスピードを分析するにはどうすればよいですか?

なぜJavaですか、あなたが聞くかもしれませんか?私は入門的なJavaクラスを取っているので、他の言語は使えません。

+0

特別なライブラリが必要です。あなたはこれを試すことができます:http://blog.datasingularity.com/?p=53 – Gareth

+0

私はそれを使用することはできませんでしたが、おかげ - 非常に有用なリンク。 – blastb

答えて

0

別の言語(Python)でも別のクラスプロジェクトでも、このためにSound Viewer Toolが使用されました。以下はsvt.pyに追加されている場合:

def processWav(filename, channel): 
    """ 
    filename: path to a wav file 
    Channel: 1 for left, 2 for right 
    Returns centroids, frequencies, volumes 
    """ 
    #open file 
    audio_file = audiolab.sndfile(filename, 'read') 
    #should be length of audiofile in seconds * 60. will fix this later 
    import contextlib 
    import wave 
    with contextlib.closing(wave.open(filename, 'r')) as f: 
     frames = f.getnframes() 
     rate = f.getframerate() 
     duration = frames/float(rate) 
    duration *= 30 #30 data points for every second of audio yay 
    duration = int(duration) #can only return an integer number of frames so yeah 
    #print duration 
    #Not really samples per pixel but I'll let that slide 
    samples_per_pixel = audio_file.get_nframes()/float(duration) 
    #some rule says this frequency has to be half of the sample rate 
    nyquist_freq = (audio_file.get_samplerate()/2) + 0.0 
    #fft_size stays 4096 
    processor = AudioProcessor(audio_file, 2048, channel, numpy.hanning) 

    centroids = [] 
    frequencies = [] 
    volumes = [] 

    for x in range(duration): 
     seek_point = int(x * samples_per_pixel) 
     next_seek_point = int((x + 1) * samples_per_pixel) 
     (spectral_centroid, db_spectrum) = processor.spectral_centroid(seek_point) 
     peaks = processor.peaks(seek_point, next_seek_point)  
     centroids.append(spectral_centroid) 
     frequencies.append(db_spectrum) 
     volumes.append(peaks) 

    #print "Centroids:" + str(centroids) 
    #print "Frequencies:" + str(frequencies) 
    #print "Volumes:" + str(volumes) 

    #convert volumes[] from peaks to actual volumes 
    for i in range(len(volumes)): 
     volumes[i] = abs(volumes[i][0]) + abs(volumes[i][1]) 
    #round frequencies to save resources 
    for i in range(len(frequencies)): 
     for j in range(len(frequencies[i])): 
      frequencies[i][j] = round(frequencies[i][j], 4) 
    return centroids, frequencies, volumes 

分析が簡単にwavファイルで行うことができます。セントロイドは音楽の音色を表します。周波数の加重平均は、任意の時点における全体的な明るさを示します。

最初の回答hereは、FFT /信号処理/デジタルサウンド表現の理解に大きな助けとなりました。

1

Praatスクリプト(Praatはダウンロード可能です。here)を使用して、必要な情報を含む出力ファイルを作成し、javaプログラムでそのtxtファイルを読むことができます。

おそらく@Garethのような外部ライブラリもあります。

関連する問題