I am using AudioTrack class to play large mp3 files. Actually i want to
manipulate voice on fly like changing the pitch or speed 1x 2x etc.
As soundtrack works only for short files. So i found AudioTrack the only
option.
I am using JLayer to decode my mp3 file (stored on sdcard) to PCM byte
array.
Following is the code for Decoder function:
public static byte[] decode(String path, int startMs, int maxMs) throws
> IOException, DecoderException
> {
> ByteArrayOutputStream outStream = new ByteArrayOutputStream(1024);
> float totalMs = 0;
> boolean seeking = true;
> File file = new File(path);
> InputStream inputStream = new BufferedInputStream(new
> FileInputStream(file), 8 * 1024);
> try
> {
> Bitstream bitstream = new Bitstream(inputStream);
> Decoder decoder = new Decoder();
> boolean done = false;
> while (! done)
> {
> javazoom.jl.decoder.Header frameHeader = bitstream.readFrame();
> if (frameHeader == null)
> done = true;
> else
> {
> totalMs += frameHeader.ms_per_frame();
> if (totalMs >= startMs)
> seeking = false;
> if (! seeking)
> {
> SampleBuffer output = (SampleBuffer)
> decoder.decodeFrame(frameHeader, bitstream);
> if (output.getSampleFrequency() != 44100 ||
> output.getChannelCount() != 2)
> throw new DecoderException("mono or non-44100 MP3 not
> supported", null);
> short[] pcm = output.getBuffer();
> for (short s : pcm)
> {
> outStream.write(s & 0xff);
> outStream.write((s >> 8 ) & 0xff);
> }
> }
> if (totalMs >= (startMs + maxMs))
> done = true;
> }
> bitstream.closeFrame();
> }
> return outStream.toByteArray();
> }
> catch (BitstreamException e)
> {
> throw new IOException("Bitstream error: " + e);
> }
> catch (DecoderException e)
> {
> Log.w("error is:", "Decoder error", e);
> }
> return null;
> }
So i pass like this
buffer = decode(Environment.getExternalStorageDirectory()+"/cm.mp3",
> i,i+1000);
But this is taking so long. Even if i pass max size to 15 seconds. it takes
about 1 min to load into buffer. Is there any other mp3 decoder
avaialable.? faster than this.
What are other ways? can i just stream large audio file to SOUNDPOOL?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en