1

I'm doing a project where I'll decode data from a mp3 file directly and store the pcm data obtained into a temporary folder, temp.pcm in the sdcard for later analysis. I'm having trouble decoding the data....

        //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);
        }

**SOLVED
I declared private javazoom.jl.decoder.Decoder decoder as a global key, but it seems that the error why it would not enter the SampleBuffer is that I had to declare it as javazoom.jl.decoder.Decoder decoder = new javazoom.jl.decoder.Decoder.

Jeany
  • 37
  • 1
  • 7

1 Answers1

0

It does not make sense (to me) to open twice an InputStream on File filep. You are not even closing the first stream before you open the second. Please adapt that code first.

greenapps
  • 11,154
  • 2
  • 16
  • 19
  • Ok so I have removed the InputStream is; and the surrounding try/catch block. The line for the SampleBuffer codes is still not being executed.. – Jeany Jul 02 '14 at 11:49
  • You did not tell where you have the basic code from. Please give some link to examples. There are several posts on this site about nearly the same problem. Do you know this one where they open the input stream differently: http://stackoverflow.com/questions/13959599/jlayer-mono-mp3-to-pcm-decoding – greenapps Jul 02 '14 at 12:12
  • I have read almost all the related questions, seems like it was a mistake on my part. I have edited the code already. Sorry :X and thank you for your time!! – Jeany Jul 02 '14 at 12:15