從本質上講,你必須做這樣的事情:
double x;//Read Wave in here
for (i=0;i<x.length;i++)
{
energy+=Tss*(x[i]^2);
}
如何讀取this article借來的波形文件。
public class ReadExample
{
public static void main(String[] args)
{
try
{
// Open the wav file specified as the first argument
WavFile wavFile = WavFile.openWavFile(new File(args[0]));
// Get the number of audio channels in the wav file
int numChannels = wavFile.getNumChannels();
// Create a buffer of 100 frames
double[] buffer = new double[100 * numChannels];
int framesRead;
do
{
// Read frames into buffer
framesRead = wavFile.readFrames(buffer, 100);
// Loop through frames and look for minimum and maximum value
for (int s=0 ; s<framesRead * numChannels ; s++)
{
//This is where you put the your code in
}
}
while (framesRead != 0);
// Close the wavFile
wavFile.close();
}
catch (Exception e)
{
System.err.println(e);
}
}
}
底線是,有沒有一個很好的乾淨的方式來做到這一點,就像在MATLAB中。甚至沒有一個函數可以直接讀取波形文件。儘管如此,它使用網站提供的WavFile類是相對直接的。
重寫它作爲一個循環將是一個很好的起點,因爲我非常懷疑android java將允許matlab的vecotrized形式。至少自己嘗試一下。 – Dan
如何使用循環,請你詳細說明一下嗎? – user1741938