Ejemplo n.º 1
0
// Called before SDL_main() to initialize JNI bindings
extern "C" void SDL_Android_Init(JNIEnv* mEnv, jclass cls)
{
    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()");

    Android_JNI_SetupThread();

    mActivityClass = (jclass)mEnv->NewGlobalRef(cls);

    midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass,
                                "createGLContext","(II[I)Z");
    midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass,
                                "flipBuffers","()V");
    midAudioInit = mEnv->GetStaticMethodID(mActivityClass,
                                "audioInit", "(IZZI)V");
    midAudioWriteShortBuffer = mEnv->GetStaticMethodID(mActivityClass,
                                "audioWriteShortBuffer", "([S)V");
    midAudioWriteByteBuffer = mEnv->GetStaticMethodID(mActivityClass,
                                "audioWriteByteBuffer", "([B)V");
    midAudioQuit = mEnv->GetStaticMethodID(mActivityClass,
                                "audioQuit", "()V");

    bHasNewData = false;

    if(!midCreateGLContext || !midFlipBuffers || !midAudioInit ||
       !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) {
        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
    }
    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!");
}
Ejemplo n.º 2
0
extern "C" void Java_org_libsdl_app_SDLActivity_nativeRunAudioThread(
                                    JNIEnv* env, jclass cls)
{
    /* This is the audio thread, with a different environment */
    Android_JNI_SetupThread();

    Android_RunAudioThread();
}
Ejemplo n.º 3
0
static void *
RunThread(void *data)
{
#ifdef __ANDROID__
    Android_JNI_SetupThread();
#endif
    SDL_RunThread(data);
    return NULL;
}
Ejemplo n.º 4
0
extern "C" int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames)
{
    int audioBufferFrames;

    int status;
    JNIEnv *env = Android_JNI_GetEnv();

    if (!env) {
        LOGE("callback_handler: failed to attach current thread");
    }
    Android_JNI_SetupThread();

    
    __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device");
    audioBuffer16Bit = is16Bit;
    audioBufferStereo = channelCount > 1;

    env->CallStaticObjectMethod(mActivityClass, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames);

    /* Allocating the audio buffer from the Java side and passing it as the return value for audioInit no longer works on
     * Android >= 4.2 due to a "stale global reference" error. So now we allocate this buffer directly from this side. */
    
    if (is16Bit) {
        jshortArray audioBufferLocal = env->NewShortArray(desiredBufferFrames * (audioBufferStereo ? 2 : 1));
        if (audioBufferLocal) {
            audioBuffer = env->NewGlobalRef(audioBufferLocal);
            env->DeleteLocalRef(audioBufferLocal);
        }
    }
    else {
        jbyteArray audioBufferLocal = env->NewByteArray(desiredBufferFrames * (audioBufferStereo ? 2 : 1));
        if (audioBufferLocal) {
            audioBuffer = env->NewGlobalRef(audioBufferLocal);
            env->DeleteLocalRef(audioBufferLocal);
        }
    }

    if (audioBuffer == NULL) {
        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: could not allocate an audio buffer!");
        return 0;
    }

    jboolean isCopy = JNI_FALSE;
    if (audioBuffer16Bit) {
        audioBufferPinned = env->GetShortArrayElements((jshortArray)audioBuffer, &isCopy);
        audioBufferFrames = env->GetArrayLength((jshortArray)audioBuffer);
    } else {
        audioBufferPinned = env->GetByteArrayElements((jbyteArray)audioBuffer, &isCopy);
        audioBufferFrames = env->GetArrayLength((jbyteArray)audioBuffer);
    }
    if (audioBufferStereo) {
        audioBufferFrames /= 2;
    }
 
    return audioBufferFrames;
}
Ejemplo n.º 5
0
JNIEXPORT int JNICALL 
Java_com_xperia64_timidityae_JNIHandler_prepareTimidity(JNIEnv * env, jobject  obj, jstring config, jstring config2, jint jmono, jint jcustResamp, jint jsixteen, jint jPresSil, jint jreloading, jint jfreeInsts)
{
	itIsDone = 0;
	if(!jreloading)
	{
		Android_JNI_SetupThread();
		//jclass tmp = 
		//pushClazz = (jclass)(*env)->NewGlobalRef(env, tmp);
		pushClazz = (*env)->NewGlobalRef(env,(*env)->FindClass(env, "com/xperia64/timidityae/JNIHandler"));
		pushBuffit=(*env)->GetStaticMethodID(env, pushClazz, "buffit", "([BI)V");
		flushId=(*env)->GetStaticMethodID(env, pushClazz, "flushIt", "()V");
		buffId=(*env)->GetStaticMethodID(env, pushClazz, "bufferSize", "()I");
		controlId=(*env)->GetStaticMethodID(env, pushClazz, "controlMe", "(I)V");
		buffId=(*env)->GetStaticMethodID(env, pushClazz, "bufferSize", "()I");
		rateId=(*env)->GetStaticMethodID(env, pushClazz, "getRate", "()I");
		finishId=(*env)->GetStaticMethodID(env, pushClazz, "finishIt", "()V");
		seekInitId=(*env)->GetStaticMethodID(env, pushClazz, "initSeeker", "(I)V");
		updateSeekId=(*env)->GetStaticMethodID(env, pushClazz, "updateSeeker", "(II)V");
		pushLyricId=(*env)->GetStaticMethodID(env, pushClazz, "updateLyrics", "([B)V");
		updateMaxChanId=(*env)->GetStaticMethodID(env, pushClazz, "updateMaxChannels", "(I)V");
		updateProgId=(*env)->GetStaticMethodID(env, pushClazz, "updateProgramInfo", "(II)V");
		updateVolId=(*env)->GetStaticMethodID(env, pushClazz, "updateVolInfo", "(II)V");
		updateDrumId=(*env)->GetStaticMethodID(env, pushClazz, "updateDrumInfo", "(II)V");
		updateTempoId=(*env)->GetStaticMethodID(env, pushClazz, "updateTempo", "(II)V");
		updateMaxVoiceId=(*env)->GetStaticMethodID(env, pushClazz, "updateMaxVoice", "(I)V");
		updateKeyId=(*env)->GetStaticMethodID(env, pushClazz, "updateKey", "(I)V");
	}

	mono = (int)jmono;
	sixteen = (int)jsixteen;
	shouldFreeInsts = (int)jfreeInsts;
	jboolean isCopy;
	configFile=(char*)(*env)->GetStringUTFChars(env, config, &isCopy); 
	configFile2=(char*)(*env)->GetStringUTFChars(env, config2, &isCopy); 
	int err=0;
    //timidity_start_initialize();
	(*timidity_start)();

    if ((err = (*timidity_preload)()) != 0)
	return err;
    err += (*timidity_postload)();
    if (err) {
	 return -121;
    }
	
	*preserve_silence = (int)jPresSil;
	//__android_log_print(ANDROID_LOG_DEBUG, "TIMIDITY", "Preserve Silence: %d %d", *preserve_silence, jPresSil);
    	(*timidity_initplayer)();
	(*set_resamp)(jcustResamp);
	(*env)->ReleaseStringUTFChars(env, config, configFile);
	(*env)->ReleaseStringUTFChars(env, config2, configFile2);

	return 0;
}
Ejemplo n.º 6
0
extern jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv *env;
    mJavaVM = vm;
    if ((*mJavaVM)->GetEnv(mJavaVM, (void**) &env, JNI_VERSION_1_4) != JNI_OK)
    {
        return -1;
    }
    /*
     * Create mThreadKey so we can keep track of the JNIEnv assigned to each thread
     * Refer to http://developer.android.com/guide/practices/design/jni.html for the rationale behind this
     */
        Android_JNI_SetupThread();

    return JNI_VERSION_1_4;
}
Ejemplo n.º 7
0
extern DECLSPEC void Android_JNI_InitImports(JNIEnv* env, jclass cls)
{
    LOGI("Android_JNI_InitImports()");

    Android_JNI_SetupThread();

    mActivityClass = (jclass) env->NewGlobalRef(cls);

    midStateCallback          = env->GetStaticMethodID(mActivityClass, "stateCallback",          "(II)V");
    midGetHardwareType        = env->GetStaticMethodID(mActivityClass, "getHardwareType",        "()I");
    midGetCustomPolygonOffset = env->GetStaticMethodID(mActivityClass, "getCustomPolygonOffset", "()F");

    if (!midStateCallback || !midGetHardwareType || !midGetCustomPolygonOffset)
    {
        LOGE("Couldn't locate Java callbacks, check that they're named and typed correctly");
    }
}
Ejemplo n.º 8
0
// Library init
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv *env;
    mJavaVM = vm;
    LOGI("JNI_OnLoad called");
    if (mJavaVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
        LOGE("Failed to get the environment using GetEnv()");
        return -1;
    }
    /*
     * Create mThreadKey so we can keep track of the JNIEnv assigned to each thread
     * Refer to http://developer.android.com/guide/practices/design/jni.html for the rationale behind this
     */
    if (pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed)) {
        __android_log_print(ANDROID_LOG_ERROR, "SDL", "Error initializing pthread key");
    }
    else {
        Android_JNI_SetupThread();
    }

    return JNI_VERSION_1_4;
}
Ejemplo n.º 9
0
extern "C" int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames)
{
    int audioBufferFrames;

    int status;
    JNIEnv *env = Android_JNI_GetEnv();

    if (!env) {
        LOGE("callback_handler: failed to attach current thread");
    }
    Android_JNI_SetupThread();

    
    __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device");
    audioBuffer16Bit = is16Bit;
    audioBufferStereo = channelCount > 1;

    audioBuffer = env->CallStaticObjectMethod(mActivityClass, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames);

    if (audioBuffer == NULL) {
        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: didn't get back a good audio buffer!");
        return 0;
    }
    audioBuffer = env->NewGlobalRef(audioBuffer);

    jboolean isCopy = JNI_FALSE;
    if (audioBuffer16Bit) {
        audioBufferPinned = env->GetShortArrayElements((jshortArray)audioBuffer, &isCopy);
        audioBufferFrames = env->GetArrayLength((jshortArray)audioBuffer);
    } else {
        audioBufferPinned = env->GetByteArrayElements((jbyteArray)audioBuffer, &isCopy);
        audioBufferFrames = env->GetArrayLength((jbyteArray)audioBuffer);
    }
    if (audioBufferStereo) {
        audioBufferFrames /= 2;
    }
 
    return audioBufferFrames;
}
Ejemplo n.º 10
0
// Library init
extern jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv *env;
    mJavaVM = vm;
    if (mJavaVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
    {
        return -1;
    }
    /*
     * Create mThreadKey so we can keep track of the JNIEnv assigned to each thread
     * Refer to http://developer.android.com/guide/practices/design/jni.html for the rationale behind this
     */
    if (pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed))
    {
        LOGE("Error initializing pthread key");
    }
    else
    {
        Android_JNI_SetupThread();
    }

    return JNI_VERSION_1_4;
}
Ejemplo n.º 11
0
EXPORT jint CALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
    __android_log_print(ANDROID_LOG_INFO, "jniBridge", "JNI_OnLoad called");
    g_JavaVM = vm;

    JNIEnv *env;
    if (g_JavaVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
    {
        __android_log_print(ANDROID_LOG_ERROR, "jniBridge", "Failed to get the environment using GetEnv()");
        return -1;
    }
    /*
    * Create mThreadKey so we can keep track of the JNIEnv assigned to each thread
    * Refer to http://developer.android.com/guide/practices/design/jni.html for the rationale behind this
    */
    if (pthread_key_create(&g_ThreadKey, Android_JNI_ThreadDestroyed) != 0)
    {
        __android_log_print(ANDROID_LOG_ERROR, "jniBridge", "Error initializing pthread key");
    }
    Android_JNI_SetupThread();

    return JNI_VERSION_1_4;
}