0
在我的应用程序中,我需要首先从特定文件中读取音频数据,然后将其存储在缓冲区中。之后,我会用它来处理和东西。问题是,当我试图打印出它的内容是给0:缓冲区读取文件给出零的音频数据
String data = String.valueOf(buffer[50]+" "+buffer[100]+" "+buffer[200]+buffer[599]);
display.setText(data);
打印上述statment给所有零...为什么???!
这里是我的代码:
public void readAudioDataFromFile() {
String filePath2 = "/storage/sdcard0/Sounds/originalFile.pcm";
FileInputStream ins = null;
File file = new File(filePath2);
int size = (int) file.length();
byte [] buffer=new byte [size];
try {
ins= new FileInputStream(filePath2);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
ins.read(buffer, 0,size);
int count =0;
for(int i=0; i<buffer.length; i++)
{
if(buffer[i]!=0)
count++;
}
String data = String.valueOf((count);
display.setText(data);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
奇怪的是,当我尝试了以下声明:
int x= ins.read(buffer, 0,size);
当我打印的x,它给出了一个数等于文件大小,
此外,当我试图打印出“计数”,你可以看到我的代码,它也给出了输出!
我的意思是不应该都意味着该缓冲区不是空的?以及为什么如果它不是空的,为什么当我试图打印出它的元素它给了我零?
什么样的数据是“音频数据”? – skyman
@bugy在谈论音频数据时,我们可以假设PCM,并且文件的扩展名是PCM。 –
您对'ins.read'的调用返回一个整数,表示从文件中读取的字节数。它返回什么价值? –