DLLEXP void JNICALL Java_hcm_ssj_mobileSSI_SSI_transformFlush(JNIEnv *env, jobject thisObj, jlong ssiobj, jobjectArray ssj_stream_in_array, jobject ssj_stream_out) { using namespace ssi; ITransformer* transformer = (ITransformer*) ssiobj; ssi_size_t num_streams = (ssi_size_t)env->GetArrayLength(ssj_stream_in_array); if(num_streams < 1) { __android_log_print(ANDROID_LOG_WARN, "SSJ_SSI_BRIDGE", "invalid input stream number"); return; } jobject ssj_stream_in = env->GetObjectArrayElement(ssj_stream_in_array, 0); jclass ssj_stream_class = env->GetObjectClass(ssj_stream_in); /* * CREATE STREAM IN */ ssi_stream_t ssi_stream_in; createStream(env, ssj_stream_class, ssj_stream_in, ssi_stream_in); /* * CREATE XTRA STREAM IN ARRAY */ ssi_stream_t* ssi_stream_in_xtra = NULL; if(num_streams > 1) { ssi_stream_in_xtra = new ssi_stream_t[num_streams-1]; for(int i = 1; i < num_streams; i++) createStream(env, ssj_stream_class, env->GetObjectArrayElement(ssj_stream_in_array, i), ssi_stream_in_xtra[i-1]); } /* * CREATE STREAM OUT */ ssi_stream_t ssi_stream_out; ssi_stream_init(ssi_stream_out, 0, transformer->getSampleDimensionOut(ssi_stream_in.dim), transformer->getSampleBytesOut(ssi_stream_in.byte), transformer->getSampleTypeOut(ssi_stream_in.type), env->GetDoubleField(ssj_stream_out, env->GetFieldID(ssj_stream_class, "sr", "D"))); ssi_stream_out.num = transformer->getSampleNumberOut(ssi_stream_in.num); /* * TRANSFORM THE DATA */ transformer->transform_flush(ssi_stream_in, ssi_stream_out, num_streams-1, ssi_stream_in_xtra); if(ssi_stream_in_xtra != NULL) delete[] ssi_stream_in_xtra; }
void SignalTools::Transform (ssi_stream_t &from, ssi_stream_t &to, ITransformer &transformer, ssi_size_t frame_size, ssi_size_t delta_size, bool call_enter, bool call_flush) { if (frame_size <= 0) { ssi_time_t sample_rate_in = from.sr; ssi_size_t sample_number_in = from.num; ssi_size_t sample_dimension_in = from.dim; ssi_size_t sample_bytes_in = from.byte; ssi_type_t sample_type_in = from.type; ssi_size_t sample_number_out = sample_number_in == 0 ? 0 : transformer.getSampleNumberOut (sample_number_in); ssi_size_t sample_dimension_out = transformer.getSampleDimensionOut (sample_dimension_in); ssi_size_t sample_bytes_out = transformer.getSampleBytesOut (sample_bytes_in); ssi_type_t sample_type_out = transformer.getSampleTypeOut (sample_type_in); ssi_time_t sample_rate_out = sample_number_in == 0 ? 0 : (ssi_cast (ssi_time_t, sample_number_out) / ssi_cast (ssi_time_t, sample_number_in)) * sample_rate_in; ssi_stream_init (to, 0, sample_dimension_out, sample_bytes_out, sample_type_out, sample_rate_out); if (sample_number_out > 0) { ssi_stream_adjust (to, sample_number_out); if (call_enter) { transformer.transform_enter (from, to, 0, 0); } ITransformer::info tinfo; tinfo.delta_num = 0; tinfo.frame_num = from.num; tinfo.time = 0; transformer.transform (tinfo, from, to, 0, 0); if (call_flush) { transformer.transform_flush (from, to, 0, 0); } } } else { ssi_time_t sample_rate_in = from.sr; ssi_size_t from_num = from.num; ssi_size_t from_tot = from.tot; SSI_ASSERT (from_num > frame_size + delta_size); ssi_size_t max_shift = (from_num - delta_size) / frame_size; ssi_size_t sample_number_in = frame_size + delta_size; ssi_size_t sample_number_out = transformer.getSampleNumberOut (frame_size); ssi_size_t sample_dimension_in = from.dim; ssi_size_t sample_dimension_out = transformer.getSampleDimensionOut (sample_dimension_in); ssi_size_t sample_bytes_in = from.byte; ssi_size_t sample_bytes_out = transformer.getSampleBytesOut (sample_bytes_in); ssi_type_t sample_type_in = from.type; ssi_type_t sample_type_out = transformer.getSampleTypeOut (sample_type_in); ssi_time_t sample_rate_out = (ssi_cast (ssi_time_t, sample_number_out) / ssi_cast (ssi_time_t, frame_size)) * sample_rate_in; ssi_size_t to_num = max_shift * sample_number_out; ssi_stream_init (to, 0, sample_dimension_out, sample_bytes_out, sample_type_out, sample_rate_out); ssi_stream_adjust (to, to_num); ssi_size_t to_tot = to.tot; ssi_byte_t *from_ptr = from.ptr; ssi_byte_t *to_ptr = to.ptr; from.num = sample_number_in; to.num = sample_number_out; ssi_size_t byte_shift_in = sample_bytes_in * sample_dimension_in * frame_size; from.tot = byte_shift_in; ssi_size_t byte_shift_out = sample_bytes_out * sample_dimension_out * sample_number_out; to.tot = byte_shift_out; if (call_enter) { transformer.transform_enter (from, to, 0, 0); } ITransformer::info tinfo; tinfo.delta_num = delta_size; tinfo.frame_num = frame_size; tinfo.time = 0; for (ssi_size_t i = 0; i < max_shift; i++) { transformer.transform (tinfo, from, to, 0, 0); tinfo.time += frame_size / sample_rate_in; from.ptr += byte_shift_in; to.ptr += byte_shift_out; } if (call_flush) { transformer.transform_flush (from, to, 0, 0); } from.ptr = from_ptr; from.num = from_num; from.tot = from_tot; to.ptr = to_ptr; to.num = to_num; to.tot = to_tot; } }
void SignalTools::Transform_Xtra (ssi_stream_t &from, ssi_stream_t &to, ITransformer &transformer, ssi_size_t frame_size, ssi_size_t delta_size, bool call_enter, bool call_flush, ssi_size_t xtra_stream_in_num, ssi_stream_t xtra_stream_in[]){ if (frame_size <= 0) { ssi_time_t sample_rate_in = from.sr; ssi_size_t sample_number_in = from.num; ssi_size_t sample_dimension_in = from.dim; ssi_size_t sample_bytes_in = from.byte; ssi_type_t sample_type_in = from.type; ssi_size_t sample_number_out = sample_number_in == 0 ? 0 : transformer.getSampleNumberOut (sample_number_in); ssi_size_t sample_dimension_out = transformer.getSampleDimensionOut (sample_dimension_in); ssi_size_t sample_bytes_out = transformer.getSampleBytesOut (sample_bytes_in); ssi_type_t sample_type_out = transformer.getSampleTypeOut (sample_type_in); ssi_time_t sample_rate_out = sample_number_in == 0 ? 0 : (ssi_cast (ssi_time_t, sample_number_out) / ssi_cast (ssi_time_t, sample_number_in)) * sample_rate_in; ssi_stream_init (to, 0, sample_dimension_out, sample_bytes_out, sample_type_out, sample_rate_out); if (sample_number_out > 0) { ssi_stream_adjust (to, sample_number_out); if (call_enter) { transformer.transform_enter (from, to, xtra_stream_in_num, xtra_stream_in); } ITransformer::info tinfo; tinfo.delta_num = 0; tinfo.frame_num = from.num; tinfo.time = 0; transformer.transform (tinfo, from, to, xtra_stream_in_num, xtra_stream_in); if (call_flush) { transformer.transform_flush (from, to, xtra_stream_in_num, xtra_stream_in); } } } else { ssi_time_t sample_rate_in = from.sr; ssi_size_t n_froms = n_froms = 1 + xtra_stream_in_num;; ssi_real_t *from_nums = new ssi_real_t[n_froms]; ssi_size_t *from_tots = new ssi_size_t[n_froms]; ssi_size_t from_num_min = 0; from_nums[0] = (ssi_real_t)from.num; from_tots[0] = from.tot; for(ssi_size_t i = 1; i < n_froms; i++){ from_nums[i] = (ssi_real_t)xtra_stream_in[i-1].num; from_tots[i] = xtra_stream_in[i-1].tot; } if(n_froms > 1){ ssi_real_t maxval = 0; ssi_real_t minval = 0; ssi_size_t maxpos = 0; ssi_size_t minpos = 0; ssi_minmax(n_froms, 1, from_nums, &minval, &minpos, &maxval, &maxpos); from_num_min = (ssi_size_t)minval; } else { from_num_min = (ssi_size_t)from_nums[0]; } SSI_ASSERT (from_num_min > frame_size + delta_size); ssi_size_t max_shift = (from_num_min - delta_size) / frame_size; ssi_size_t sample_number_out = transformer.getSampleNumberOut (frame_size); ssi_size_t sample_dimension_in = from.dim; ssi_size_t sample_dimension_out = transformer.getSampleDimensionOut (sample_dimension_in); ssi_size_t sample_byte_in = from.byte; ssi_size_t sample_bytes_out = transformer.getSampleBytesOut (sample_byte_in); ssi_type_t sample_type_in = from.type; ssi_type_t sample_type_out = transformer.getSampleTypeOut (sample_type_in); ssi_time_t sample_rate_out = (ssi_cast (ssi_time_t, sample_number_out) / ssi_cast (ssi_time_t, frame_size)) * sample_rate_in; ssi_size_t to_num = max_shift * sample_number_out; ssi_stream_init (to, 0, sample_dimension_out, sample_bytes_out, sample_type_out, sample_rate_out); ssi_stream_adjust (to, to_num); ssi_size_t to_tot = to.tot; ssi_byte_t **from_ptrs = new ssi_byte_t*[n_froms]; from_ptrs[0] = from.ptr; for(ssi_size_t i = 1; i < n_froms; i++){ from_ptrs[i] = xtra_stream_in[i-1].ptr; } ssi_byte_t *to_ptr = to.ptr; ssi_size_t byte_shift_out = sample_bytes_out * sample_dimension_out * sample_number_out; to.tot = byte_shift_out; to.num = sample_number_out;//! ssi_size_t sample_number_in = frame_size + delta_size; from.num = sample_number_in; ssi_size_t byte_shift_in = sample_byte_in * sample_dimension_in * frame_size; from.tot = byte_shift_in; ssi_time_t from_secs = 0; ssi_time_t to_secs = 0; if (call_enter) { for(ssi_size_t k = 1; k < n_froms; k++){ xtra_stream_in[k-1].ptr = 0; xtra_stream_in[k-1].num = 0; xtra_stream_in[k-1].tot = 0; } transformer.transform_enter (from, to, xtra_stream_in_num, xtra_stream_in); } for (ssi_size_t i = 0; i < max_shift; i++) { ITransformer::info tinfo; tinfo.delta_num = delta_size; tinfo.frame_num = frame_size; tinfo.time = 0; from_secs = (i * frame_size) / from.sr; to_secs = from_secs + (frame_size + delta_size)/from.sr; ssi_size_t from_num, n_num; for(ssi_size_t k = 1; k < n_froms; k++){ from_num = (ssi_size_t)(from_secs * xtra_stream_in[k-1].sr + 0.5); n_num = (ssi_size_t)((to_secs - from_secs) * xtra_stream_in[k-1].sr + 0.5); xtra_stream_in[k-1].ptr = from_ptrs[k] + from_num * xtra_stream_in[k-1].dim * xtra_stream_in[k-1].byte; xtra_stream_in[k-1].num = n_num; xtra_stream_in[k-1].tot = n_num * xtra_stream_in[k-1].dim * xtra_stream_in[k-1].byte; SSI_ASSERT( (from_num + n_num) <= xtra_stream_in[k-1].num_real); } transformer.transform (tinfo, from, to, xtra_stream_in_num, xtra_stream_in); tinfo.time += frame_size / sample_rate_in; from.ptr += byte_shift_in; to.ptr += byte_shift_out; } if (call_flush) { from_secs = (0 * frame_size) / from.sr; to_secs = from_secs + (frame_size + delta_size)/from.sr; for(ssi_size_t k = 1; k < n_froms; k++){ xtra_stream_in[k-1].ptr = 0; xtra_stream_in[k-1].num = 0; xtra_stream_in[k-1].tot = 0; } transformer.transform_flush (from, to, xtra_stream_in_num, xtra_stream_in); } from.ptr = from_ptrs[0]; from.num = (ssi_size_t)from_nums[0]; from.tot = from_tots[0]; for(ssi_size_t i = 1; i < n_froms; i++){ xtra_stream_in[i-1].ptr = from_ptrs[i]; xtra_stream_in[i-1].num = (ssi_size_t)from_nums[i]; xtra_stream_in[i-1].tot = from_tots[i]; } to.ptr = to_ptr; to.num = to_num; to.tot = to_tot; delete [] from_nums; from_nums = 0; delete [] from_tots; from_tots = 0; delete [] from_ptrs; from_ptrs = 0; } }
DLLEXP jint JNICALL Java_hcm_ssj_mobileSSI_SSI_getSampleNumberOut(JNIEnv *env, jobject thisObj, jlong ssiobj, jint sample_number_in) { using namespace ssi; ITransformer* transformer = (ITransformer*) ssiobj; return transformer->getSampleNumberOut((ssi_size_t)sample_number_in); }
DLLEXP void JNICALL Java_hcm_ssj_mobileSSI_SSI_transform(JNIEnv *env, jobject thisObj, jlong ssiobj, jobjectArray ssj_stream_in_array, jobject ssj_stream_out) { using namespace ssi; ITransformer* transformer = (ITransformer*) ssiobj; ssi_size_t num_streams = (ssi_size_t)env->GetArrayLength(ssj_stream_in_array); if(num_streams < 1) { __android_log_print(ANDROID_LOG_WARN, "SSJ_SSI_BRIDGE", "invalid input stream number"); return; } jobject ssj_stream_in = env->GetObjectArrayElement(ssj_stream_in_array, 0); jclass ssj_stream_class = env->GetObjectClass(ssj_stream_in); /* * CREATE STREAM IN */ ssi_stream_t ssi_stream_in; createStream(env, ssj_stream_class, ssj_stream_in, ssi_stream_in); copyData(env, ssj_stream_class, ssj_stream_in, ssi_stream_in); /* * CREATE XTRA STREAM IN ARRAY */ ssi_stream_t* ssi_stream_in_xtra = NULL; if(num_streams > 1) { ssi_stream_in_xtra = new ssi_stream_t[num_streams-1]; for(int i = 1; i < num_streams; i++) { jobject ssj_stream = env->GetObjectArrayElement(ssj_stream_in_array, i); createStream(env, ssj_stream_class, ssj_stream, ssi_stream_in_xtra[i - 1]); copyData(env, ssj_stream_class, ssj_stream, ssi_stream_in_xtra[i - 1]); } } /* * CREATE STREAM OUT */ ssi_stream_t ssi_stream_out; jdouble sr_out = env->GetDoubleField(ssj_stream_out, env->GetFieldID(ssj_stream_class, "sr", "D")); ssi_stream_init(ssi_stream_out, transformer->getSampleNumberOut(ssi_stream_in.num), transformer->getSampleDimensionOut(ssi_stream_in.dim), transformer->getSampleBytesOut(ssi_stream_in.byte), transformer->getSampleTypeOut(ssi_stream_in.type), sr_out); /* * TRANSFORM THE DATA */ ITransformer::info tinfo; tinfo.frame_num = (ssi_size_t)env->GetIntField(ssj_stream_in, env->GetFieldID(ssj_stream_class, "num_frame", "I")); tinfo.delta_num = (ssi_size_t)env->GetIntField(ssj_stream_in, env->GetFieldID(ssj_stream_class, "num_delta", "I")); tinfo.time = ssi_stream_in.time; transformer->transform(tinfo, ssi_stream_in, ssi_stream_out, num_streams-1, ssi_stream_in_xtra); /* * PASS DATA BACK TO SSJ */ copyData(env, ssj_stream_class, ssi_stream_out, ssj_stream_out); if(ssi_stream_in_xtra != NULL) delete[] ssi_stream_in_xtra; }