Whi*_*e-E 5 java audio comparison fft wav
我现在很难过.我一直在环顾四周,试验音频比较.我已经找到了相当多的材料,并且大量引用了不同的库和方法.
到目前为止,我已经使用Audacity并导出一个名为"long.wav"的3分钟wav文件,然后将其前30秒分成一个名为"short.wav"的文件.我想在线上的某处我可以通过java在每个视觉上记录(log.txt)数据,并且应该能够在值中看到至少一些视觉上的相似性....这里是一些代码
主要方法:
int totalFramesRead = 0;
File fileIn = new File(filePath);
BufferedWriter writer = new BufferedWriter(new FileWriter(outPath));
writer.flush();
writer.write("");
try {
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(fileIn);
int bytesPerFrame =
audioInputStream.getFormat().getFrameSize();
if (bytesPerFrame == AudioSystem.NOT_SPECIFIED) {
// some audio formats may have unspecified frame size
// in that case we may read any amount of bytes
bytesPerFrame = 1;
}
// Set an arbitrary buffer size of 1024 frames.
int numBytes = 1024 * bytesPerFrame;
byte[] audioBytes = new byte[numBytes];
try {
int numBytesRead = 0;
int numFramesRead = 0;
// Try to read numBytes bytes from the file.
while ((numBytesRead =
audioInputStream.read(audioBytes)) != -1) {
// Calculate the number of frames actually read.
numFramesRead = numBytesRead / bytesPerFrame;
totalFramesRead += numFramesRead;
// Here, do something useful with the audio data that's
// now in the audioBytes array...
if(totalFramesRead <= 4096 * 100)
{
Complex[][] results = PerformFFT(audioBytes);
int[][] lines = GetKeyPoints(results);
DumpToFile(lines, writer);
}
}
} catch (Exception ex) {
// Handle the error...
}
audioInputStream.close();
} catch (Exception e) {
// Handle the error...
}
writer.close();
Run Code Online (Sandbox Code Playgroud)
然后PerformFFT:
public static Complex[][] PerformFFT(byte[] data) throws IOException
{
final int totalSize = data.length;
int amountPossible = totalSize/Harvester.CHUNK_SIZE;
//When turning into frequency domain we'll need complex numbers:
Complex[][] results = new Complex[amountPossible][];
//For all the chunks:
for(int times = 0;times < amountPossible; times++) {
Complex[] complex = new Complex[Harvester.CHUNK_SIZE];
for(int i = 0;i < Harvester.CHUNK_SIZE;i++) {
//Put the time domain data into a complex number with imaginary part as 0:
complex[i] = new Complex(data[(times*Harvester.CHUNK_SIZE)+i], 0);
}
//Perform FFT analysis on the chunk:
results[times] = FFT.fft(complex);
}
return results;
}
Run Code Online (Sandbox Code Playgroud)
此时我尝试了无处不在的日志:变换前的audioBytes,复杂值和FFT结果.
问题:无论我记录什么值,每个wav文件的log.txt都完全不同.我不明白.鉴于我从large.wav获取了small.wav(并且它们具有所有相同的属性),原始wav byte [] data ...或Complex [] [] fft数据之间应该存在非常大的相似性. ..或者到目前为止的东西......
如果数据在这些计算的任何一点都不接近相似,我怎么可能尝试比较这些文件.
我知道我在音频分析方面缺少相当多的知识,这就是我来到董事会寻求帮助的原因!感谢您提供的任何信息,帮助或修复!
对于 16 位音频,3e-05 与 0 并没有太大区别。因此,零文件与零文件几乎相同(可能由于一些微小的舍入误差而缺少相等性。)
添加:为了进行比较,使用一些 Java 绘图库读入并绘制两个波形中的每一个波形在超过大部分(接近)零的部分时的部分。
| 归档时间: |
|
| 查看次数: |
2468 次 |
| 最近记录: |