Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "com_hlcam_video_managers_VideoScorer.h"
- /*
- * Class: com_hlcam_video_services_ScoreService
- * Method: scoreFile
- * Signature: (Ljava/lang/String;Ljava/lang/String;)I
- */
- #include <hlcam/scorer/audio_reading.h>
- #include <hlcam-common.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- using namespace std;
- //jobjectArray make_row(JNIEnv *env, jsize count, float elements[])
- //{
- // jclass floatClass = (env)->FindClass("java/lang/Float");
- // jobjectArray row = env->NewObjectArray( count, floatClass, 0);
- // jsize i;
- //
- // for (i = 0; i < count; ++i) {
- // jobject floatObj = elements[i];
- // env->SetObjectArrayElement(row, i, floatObj);
- // }
- //
- // return row;
- //}
- /*
- * Class: com_hlcam_video_services_ScoreService
- * Method: scoreAudioFile
- * Signature: (Ljava/lang/String;)I
- * Takes in the location of the audio (WAV) file for scoring. returns a list of lists representing the scores
- */
- JNIEXPORT jobject JNICALL Java_com_hlcam_video_managers_VideoScorer_scoreAudioFile
- (JNIEnv *env, jobject jobj, jstring filePath, jint videoFps)
- {
- AudioScores aud_scores;
- const char *src= env->GetStringUTFChars(filePath, NULL);
- ReadAudio(src, videoFps, &aud_scores);
- jclass clazz = (env)->FindClass("com/hlcam/video/data/RawAudioScores");
- jmethodID midConstructor = env->GetMethodID(clazz, "<init>", "()V");
- jobject audioScores = env->NewObject( clazz, midConstructor);
- DLOG("Is there an exception %d:" , env->ExceptionCheck());
- env->ExceptionDescribe();
- env->ExceptionClear();
- DLOG("getting vadScores Field Id");
- jfieldID jVadScoresId = env->GetFieldID(clazz, "vadScores", "[D");
- DLOG("Is there an exception %d:" , env->ExceptionCheck());
- env->ExceptionDescribe();
- env->ExceptionClear();
- DLOG("getting audioLevel Field Id");
- jfieldID jAudioLevelId = env->GetFieldID(clazz, "audioLevel", "[D");
- DLOG("Is there an exception %d:" , env->ExceptionCheck());
- env->ExceptionDescribe();
- env->ExceptionClear();
- jobject audioData = env->GetObjectField( audioScores, jAudioLevelId);
- DLOG("Is there an exception %d:" , env->ExceptionCheck());
- env->ExceptionDescribe();
- env->ExceptionClear();
- jdoubleArray* audioLevelArr = reinterpret_cast<jdoubleArray *>(&audioData);
- jsize vadScoreSize = aud_scores.vad_scores.size();
- jsize offset = 0;
- jsize audioLevelSize = sizeof(aud_scores.audio_level);
- DLOG("Retrieving vad reference");
- jdoubleArray vadArray = (jdoubleArray) env->GetObjectField(audioScores, jVadScoresId);
- DLOG("Is there an exception %d:" , env->ExceptionCheck());
- env->ExceptionDescribe();
- env->ExceptionClear();
- DLOG("Setting Double Array Region for Audio Level");
- DLOG("size of audio scores: %d (%f)", aud_scores.audio_level.size(), audioLevelArr);
- for (int i = 0; i < aud_scores.audio_level.size(); ++i ) {
- DLOG("(%d) %f", i, aud_scores.audio_level[i]);
- }
- env->SetDoubleArrayRegion( *audioLevelArr, offset, audioLevelSize, &aud_scores.audio_level[0]);
- DLOG("Setting Double Array Region for Vad Scores");
- env->SetDoubleArrayRegion( vadArray, offset, vadScoreSize, &aud_scores.vad_scores[0]);
- return audioScores;
- }
- #ifdef __cplusplus
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement