src/core/android/SDL_android.c
changeset 12224 0582b4e1fa9f
parent 12201 8bdc4d340419
child 12242 df7260f149f2
     1.1 --- a/src/core/android/SDL_android.c	Tue Sep 25 19:53:16 2018 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Tue Sep 25 20:08:51 2018 -0700
     1.3 @@ -1046,8 +1046,8 @@
     1.4  
     1.5  int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames)
     1.6  {
     1.7 -    jboolean audioBufferStereo;
     1.8 -    int audioBufferFrames;
     1.9 +    jboolean isStereo;
    1.10 +    int numBufferFrames;
    1.11      jobject jbufobj = NULL;
    1.12      jboolean isCopy;
    1.13  
    1.14 @@ -1058,12 +1058,12 @@
    1.15      }
    1.16      Android_JNI_SetupThread();
    1.17  
    1.18 -    audioBufferStereo = channelCount > 1;
    1.19 +    isStereo = channelCount > 1;
    1.20  
    1.21      if (iscapture) {
    1.22          __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for capture");
    1.23          captureBuffer16Bit = is16Bit;
    1.24 -        if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) != 0) {
    1.25 +        if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureOpen, sampleRate, is16Bit, isStereo, desiredBufferFrames) != 0) {
    1.26              /* Error during audio initialization */
    1.27              __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioRecord initialization!");
    1.28              return 0;
    1.29 @@ -1071,7 +1071,7 @@
    1.30      } else {
    1.31          __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for output");
    1.32          audioBuffer16Bit = is16Bit;
    1.33 -        if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midAudioOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) != 0) {
    1.34 +        if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midAudioOpen, sampleRate, is16Bit, isStereo, desiredBufferFrames) != 0) {
    1.35              /* Error during audio initialization */
    1.36              __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioTrack initialization!");
    1.37              return 0;
    1.38 @@ -1082,14 +1082,14 @@
    1.39       * Android >= 4.2 due to a "stale global reference" error. So now we allocate this buffer directly from this side. */
    1.40  
    1.41      if (is16Bit) {
    1.42 -        jshortArray audioBufferLocal = (*env)->NewShortArray(env, desiredBufferFrames * (audioBufferStereo ? 2 : 1));
    1.43 +        jshortArray audioBufferLocal = (*env)->NewShortArray(env, desiredBufferFrames * (isStereo ? 2 : 1));
    1.44          if (audioBufferLocal) {
    1.45              jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal);
    1.46              (*env)->DeleteLocalRef(env, audioBufferLocal);
    1.47          }
    1.48      }
    1.49      else {
    1.50 -        jbyteArray audioBufferLocal = (*env)->NewByteArray(env, desiredBufferFrames * (audioBufferStereo ? 2 : 1));
    1.51 +        jbyteArray audioBufferLocal = (*env)->NewByteArray(env, desiredBufferFrames * (isStereo ? 2 : 1));
    1.52          if (audioBufferLocal) {
    1.53              jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal);
    1.54              (*env)->DeleteLocalRef(env, audioBufferLocal);
    1.55 @@ -1110,22 +1110,26 @@
    1.56      isCopy = JNI_FALSE;
    1.57  
    1.58      if (is16Bit) {
    1.59 -        if (!iscapture) {
    1.60 +        if (iscapture) {
    1.61 +            numBufferFrames = (*env)->GetArrayLength(env, (jshortArray)captureBuffer);
    1.62 +        } else {
    1.63              audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy);
    1.64 +            numBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer);
    1.65          }
    1.66 -        audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer);
    1.67      } else {
    1.68 -        if (!iscapture) {
    1.69 +        if (iscapture) {
    1.70 +            numBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer);
    1.71 +        } else {
    1.72              audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy);
    1.73 +            numBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer);
    1.74          }
    1.75 -        audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer);
    1.76      }
    1.77  
    1.78 -    if (audioBufferStereo) {
    1.79 -        audioBufferFrames /= 2;
    1.80 +    if (isStereo) {
    1.81 +        numBufferFrames /= 2;
    1.82      }
    1.83  
    1.84 -    return audioBufferFrames;
    1.85 +    return numBufferFrames;
    1.86  }
    1.87  
    1.88  int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi)