Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从wav文件的字节数组中获取频率图?_Java_Android_Frequency Analysis - Fatal编程技术网

Java 如何从wav文件的字节数组中获取频率图?

Java 如何从wav文件的字节数组中获取频率图?,java,android,frequency-analysis,Java,Android,Frequency Analysis,下面代码的目的是将wav文件转换为字节数组并绘制字节数组。有人知道如何从wav文件中提取字节数组,并将其转换为每次保存频率的数组吗 buttonDecode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { buttonStart.setEnabled(false);

下面代码的目的是将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


            }
        });
buttonDecode.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
buttonStart.setEnabled(false);
buttonDecode.setEnabled(假);
buttonPlay.setEnabled(错误);
GraphView thegraph=(GraphView)findViewById(R.id.thegraph);
系列=新的LineGraphSeries();
双x,y;
x=0;
试一试{
ByteArrayOutputStream outt=新建ByteArrayOutputStream();
BufferedInputStream in=新BufferedInputStream(新文件输入流(wavfile));
int-read;
字节[]buff=新字节[1024];
而((read=in.read(buff))>0)
{
输出写入(buff,0,读取);
}
out.flush();
byte[]audioBytes=outt.toByteArray();
//int[][]graphData=getUnscaledAmplitude(音频字节,1);
对于(int i=0;i