Re: Using libmp3lame in Android

"Robert Hegemann" <[email protected]> Fri, 24 Nov 2017 12:10:23 +0100
Newsgroups gmane.comp.audio.mp3.lame
Message-ID <op.y97fzlaj7p99ik@krypton>
Salut Benjamin,

may I suggest, that you pay attention to the return value
of hip_decode?

if x < 0 then there is some error condition
if x = 0 then the decoder needs more data to produce PCM samples
if x > 0 then the decoder returned the amount of x PCM samples

In your code, mp3Len is not the number of decoded PCM samples.

Ciao Robert


Am 23.11.2017, 10:30 Uhr, schrieb Rebondy Benjamin via Lame-dev  
<[email protected]>:

> Hi,
> I have no idea whether this is the right place to ask a development  
> question regarding the use of libmp3lame on Android. I'm having some  
> trouble decoding mp3 using the hip_decode() function and could use a  
> little bit of help. If this is not the right place to ask such a  
> question, don't read the following email :).I'm trying to code an  
> Android Application which receives mp3 audio chunks through a WebSocket  
> (audio is a live-stream voice encoded with libmp3lame).The Android app  
> is supposed to play each small audio chunks received, thus making the  
> app able to "listen" to the broadcaster in real-time.I'm using  
> AudioTrack in Android, which allows me to "write" into the track a byte  
> array every time I receive one, and play it instantly. The only problem  
> is that Audio Track does not accept MP3. So I need to decode each little  
> audio chunk from MP3 to PCM. I first used JLayer, which worked, but had  
> some "robotic effect" while trying to listen to the live stream. I  
> figured it was a decoding problem. Since the MP3 is firstly encoded  
> using libmp3lame, I figured using the same library to decode the signal  
> might be smarter.I finally implemented the libmp3lame in my Android NDK  
> and I'm currently trying to decode each small audio chunks into PCM  
> using the hip_decode function. I'm currently doing this :JNIEXPORT  
> jshortArray JNICALL  
> Java_com_example_jneb_myapplication_AudioTrackClass_decoderInit(JNIEnv  
> *env, jobject jobj,
>                                                                                      jbyteArray  
> data, jint size) {
>     jsize mp3Len =  (*env)->GetArrayLength(env, data);
>     // Print the data.length = 96
>     LOGI("JNI integer: %d", mp3Len);
>     // mp3 contains all 96 values
>     jbyte *mp3 = (*env)->GetByteArrayElements(env, data, 0);
>
>     // Trying to decode mp3 into PCM
>     int x = hip_decode(hip, (unsigned char*) mp3, (size_t) mp3Len,  
> pcm_l, pcm_r);
>
>     jshortArray pcmBuffer;
>     pcmBuffer = (*env)->NewShortArray(env, mp3Len);
>     (*env)->SetShortArrayRegion(env, pcmBuffer, 0, mp3Len, pcm_l);
>     // Releasing byte array
>     (*env)->ReleaseByteArrayElements(env, data, mp3, 0);
>
>     // Returning
>     return pcmBuffer;}I have a byte array in the input of the function,  
> and I need the decoded PCM sample in the output. Right now when I read  
> the pcmBuffer value in my Java-Side application, all data are "0". So  
> here I'm stuck. I don't know what I'm doing wrong since my C skills are  
> really really bad, and I couldn't find a lot of MP3 decoding example on  
> the web.
>
>
> I apologize in advance if it's not the right place to ask a question.
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Lame-dev mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/lame-dev


-- 
Erstellt mit Operas E-Mail-Modul: http://www.opera.com/mail/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot