View Single Post
Posts: 18 | Thanked: 94 times | Joined on Dec 2012
#15
Originally Posted by thp View Post
Have a look at the nativeMixData function - all JNI methods take an JNIEnv * as their first method, the second one is the object on which the function is called (for our purposes, this is mostly "any" object - I usually pass a pointer to the global object there, but any random pointer should work). The third parameter is a long that you can use to pass an application-specific pointer. The fourth is a pointer to the buffer which is filled with audio data, and the fifth is the length of that buffer.

Would be great if you could submit your modules as pull request to apkenv on Github
Hi, and thanks again for providing apkenv for us.

I have tryed to study this sound output for angry birds but I can't seem to figure out how to get it working. Thus far my code is this:

Typedef for nativeMixData:
Code:
typedef void (*angrybirds_mixdata_t)(JNIEnv *env, jobject obj, jlong paramLong, jbyteArray paramArrayOfByte, jint paramInt) SOFTFP;
Start audio output when CallVoidMethodV(startOutput) calls:
Code:
        /* Open the audio device */
        SDL_AudioSpec *desired, *obtained;

        desired = malloc(sizeof(SDL_AudioSpec));
        obtained = malloc(sizeof(SDL_AudioSpec));
        desired->freq=44100;
        desired->format=AUDIO_S16SYS;
        desired->channels=2;
        desired->samples=8192;
        desired->callback=my_audio_callback;
        desired->userdata=p0;

        if( SDL_InitSubSystem(SDL_INIT_AUDIO) < 0 )
	    exit(-1);

        if ( SDL_OpenAudio(desired, obtained) < 0 )
             exit(-1);
        
        free(desired);
        SDL_PauseAudio(0);
I can see that this works as my_audio_callback function calls for more data:
Code:
void my_audio_callback(void *ud, Uint8 *stream, int len)
{
    printf("call mixdata (%i)\n",len);
    jlong tmplong = 0;
    jbyte* buffer = calloc(len,1);
    angrybirds_priv.native_mixdata(ENV(global), VM(global), (jlong)&tmplong, buffer, len);
    memcpy(stream,buffer,len);
    free(buffer);
}
But buffer seems to be completely empty (no audio data returned). Is that application-specific pointer important and is audio format correct or is problem with something else here?

PS. I do that pull request if I ever get this audio stuff working
 

The Following User Says Thank You to Art-O For This Useful Post: