所以,我正在尝试重拍Vib Ribbon:http://www.youtube.com/watch?v=ehdymXc0epY 输入将是一个.wav文件,我对如何分析它并创建音量和音高的阈值没有任何想法会产生不同的障碍 - 我已经指向傅里叶变换,我不明白。有人能指出一个适用于这种情况的波形分析课程并让我知道如何开始吗?我无法获得像AudioSurf和音乐可视化器这样的源代码。
为什么java,你可能会问?我正在学习Java课程,所以没有其他语言可以使用。
答案 0 :(得分:1)
您可以编写Praat脚本(Praat可供下载here)以生成包含所需信息的输出文件,然后使用您的java程序读取该txt文件。
可能还有外部图书馆,比如@Gareth说。
答案 1 :(得分:0)
我最终使用了Sound Viewer Tool,尽管是另一种语言(Python)和另一个类项目。如果将以下内容添加到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 /信号处理/数字声音表示有很大帮助。