我正在做一个项目,我将直接解码mp3文件中的数据,并将获得的pcm数据存储到存储卡中的临时文件夹temp.pcm中,以供以后分析。我解码数据有困难....
//a short array to store raw pcm data
short[] buffer = new short[bufferSize];
ByteArrayOutputStream outStream = new ByteArrayOutputStream(1024);
File filep = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/onenineoone.mp3");
InputStream inputStream = new BufferedInputStream(new FileInputStream(filep), 8 * 1024);
short[] pcm=null;
try
{
Bitstream bitstream = new Bitstream(inputStream);
boolean done = false;
while (!done)
{
javazoom.jl.decoder.Header frameHeader = bitstream.readFrame();
javazoom.jl.decoder.Decoder decoder = new javazoom.jl.decoder.Decoder;
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(frameHeader, bitstream);
****Log.i("decoder", "error in the samplebuffer??");****
if (output.getSampleFrequency() != 44100 || output.getChannelCount() != 1) throw new DecoderException("Stereo or non-44100 sampling rate .mp3 not supported", null);
pcm = output.getBuffer();
for (short s:pcm) {
outStream.write(s);
}
buffer=pcm;
}
done = true;
bitstream.closeFrame();
} catch (BitstreamException e) {
throw new IOException("Bitstream error: " + e);
} catch (DecoderException e) {
Log.w("error is:", "Decoder error", e);
}
* *解决
我声明私有javazoom.jl.decoder.Decoder解码器作为全局密钥,但似乎它不会进入SampleBuffer的错误原因是我必须将其声明为javazoom.jl.decoder.Decoder = new javazoom.jl.decoder.
在文件文件上打开两次InputStream是没有意义的(对我来说)。在打开第二个流之前,您甚至没有关闭第一个流。请先修改代码