Advertisement
mnguyen

setDoubleArrayRegion

Aug 28th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include "com_hlcam_video_managers_VideoScorer.h"
  2. /*
  3.  * Class:     com_hlcam_video_services_ScoreService
  4.  * Method:    scoreFile
  5.  * Signature: (Ljava/lang/String;Ljava/lang/String;)I
  6.  */
  7. #include <hlcam/scorer/audio_reading.h>
  8. #include <hlcam-common.h>
  9.  
  10. #ifdef __cplusplus
  11. extern "C" {
  12.  
  13. #endif
  14.  
  15. using namespace std;
  16. //jobjectArray make_row(JNIEnv *env, jsize count, float elements[])
  17. //{
  18. //    jclass floatClass = (env)->FindClass("java/lang/Float");
  19. //    jobjectArray row = env->NewObjectArray( count, floatClass, 0);
  20. //    jsize i;
  21. //
  22. //    for (i = 0; i < count; ++i) {
  23. //        jobject floatObj = elements[i];
  24. //        env->SetObjectArrayElement(row, i, floatObj);
  25. //    }
  26. //
  27. //    return row;
  28. //}
  29.  
  30. /*
  31.  * Class:     com_hlcam_video_services_ScoreService
  32.  * Method:    scoreAudioFile
  33.  * Signature: (Ljava/lang/String;)I
  34.  * Takes in the location of the audio (WAV) file for scoring.  returns a list of lists representing the scores
  35.  */
  36. JNIEXPORT jobject JNICALL Java_com_hlcam_video_managers_VideoScorer_scoreAudioFile
  37. (JNIEnv *env, jobject jobj, jstring filePath, jint videoFps)
  38. {
  39.  
  40.     AudioScores aud_scores;
  41.     const char *src= env->GetStringUTFChars(filePath, NULL);
  42.     ReadAudio(src, videoFps, &aud_scores);
  43.  
  44.     jclass clazz = (env)->FindClass("com/hlcam/video/data/RawAudioScores");
  45.     jmethodID midConstructor = env->GetMethodID(clazz, "<init>", "()V");
  46.     jobject audioScores = env->NewObject( clazz, midConstructor);
  47.     DLOG("Is there an exception %d:" , env->ExceptionCheck());
  48.     env->ExceptionDescribe();
  49.     env->ExceptionClear();
  50.  
  51.     DLOG("getting vadScores Field Id");
  52.     jfieldID jVadScoresId = env->GetFieldID(clazz, "vadScores", "[D");
  53.     DLOG("Is there an exception %d:" , env->ExceptionCheck());
  54.     env->ExceptionDescribe();
  55.     env->ExceptionClear();
  56.  
  57.     DLOG("getting audioLevel Field Id");
  58.     jfieldID jAudioLevelId = env->GetFieldID(clazz, "audioLevel", "[D");
  59.     DLOG("Is there an exception %d:" , env->ExceptionCheck());
  60.     env->ExceptionDescribe();
  61.     env->ExceptionClear();
  62.  
  63.     jobject audioData = env->GetObjectField( audioScores, jAudioLevelId);
  64.     DLOG("Is there an exception %d:" , env->ExceptionCheck());
  65.     env->ExceptionDescribe();
  66.     env->ExceptionClear();
  67.  
  68.     jdoubleArray* audioLevelArr = reinterpret_cast<jdoubleArray *>(&audioData);
  69.  
  70.     jsize vadScoreSize = aud_scores.vad_scores.size();
  71.     jsize offset = 0;
  72.     jsize audioLevelSize = sizeof(aud_scores.audio_level);
  73.  
  74.     DLOG("Retrieving vad reference");
  75.     jdoubleArray vadArray = (jdoubleArray) env->GetObjectField(audioScores, jVadScoresId);
  76.  
  77.     DLOG("Is there an exception %d:" , env->ExceptionCheck());
  78.     env->ExceptionDescribe();
  79.     env->ExceptionClear();
  80.  
  81.     DLOG("Setting Double Array Region for Audio Level");
  82.     DLOG("size of audio scores: %d (%f)", aud_scores.audio_level.size(), audioLevelArr);
  83.     for (int i = 0; i < aud_scores.audio_level.size(); ++i ) {
  84.         DLOG("(%d) %f", i, aud_scores.audio_level[i]);
  85.     }
  86.  
  87.     env->SetDoubleArrayRegion( *audioLevelArr, offset, audioLevelSize, &aud_scores.audio_level[0]);
  88.     DLOG("Setting Double Array Region for Vad Scores");
  89.     env->SetDoubleArrayRegion( vadArray, offset, vadScoreSize,  &aud_scores.vad_scores[0]);
  90.  
  91.     return audioScores;
  92. }
  93.  
  94. #ifdef __cplusplus
  95. }
  96. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement