下面代码的目的是将wav文件转换为字节数组并绘制字节数组图。有没有人知道如何从wav文件中获取字节数组并将其转换为每次保存频率的数组?
buttonDecode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
buttonStart.setEnabled(false);
buttonDecode.setEnabled(false);
buttonPlay.setEnabled(false);
GraphView thegraph = (GraphView) findViewById(R.id.thegraph);
series = new LineGraphSeries<DataPoint>();
double x,y;
x = 0;
try {
ByteArrayOutputStream outt = new ByteArrayOutputStream();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(wavfile));
int read;
byte[] buff = new byte[1024];
while ((read = in.read(buff)) > 0)
{
outt.write(buff, 0, read);
}
outt.flush();
byte[] audioBytes = outt.toByteArray();
//int[][] graphData = getUnscaledAmplitude(audioBytes, 1);
for(int i = 0; i < audioBytes.length;i++){
//System.out.println(audioBytes[i]);
byte curByte = audioBytes[i];
//int curByte = graphData[0][i];
y = (curByte);
series.appendData(new DataPoint(x,y), true, audioBytes.length);
x = x + 1;
//x = x + (1 / RECORDER_SAMPLERATE);
}
thegraph.addSeries(series);
} catch (IOException e) {
e.printStackTrace();
}
buttonStart.setEnabled(true);
buttonDecode.setEnabled(true);
buttonPlay.setEnabled(true);
//GRAPHING SECTION
}
});