void mix_and_play( struct hvl_tune *ht ) { if( need_wait[nextbuf] ) IExec->WaitIO( (struct IORequest *)ahi_io[nextbuf] ); hvl_DecodeFrame( ht, audiobuffer[nextbuf], audiobuffer[nextbuf]+sizeof( int16 ), 4 ); ahi_io[nextbuf]->ahir_Std.io_Command = CMD_WRITE; ahi_io[nextbuf]->ahir_Std.io_Data = audiobuffer[nextbuf]; ahi_io[nextbuf]->ahir_Std.io_Length = audiobuflen; ahi_io[nextbuf]->ahir_Std.io_Offset = 0; ahi_io[nextbuf]->ahir_Type = AHIST_S16S; ahi_io[nextbuf]->ahir_Frequency = FREQ; ahi_io[nextbuf]->ahir_Volume = 0x10000; ahi_io[nextbuf]->ahir_Position = 0x8000; ahi_io[nextbuf]->ahir_Link = prev_req; IExec->SendIO( (struct IORequest *)ahi_io[nextbuf] ); prev_req = ahi_io[nextbuf]; need_wait[nextbuf] = TRUE; nextbuf ^= 1; if( ( need_wait[nextbuf] == TRUE ) && ( IExec->CheckIO( (struct IORequest *)ahi_io[nextbuf] ) != NULL ) ) { IExec->WaitIO( (struct IORequest *)ahi_io[nextbuf] ); need_wait[nextbuf] = FALSE; } if( need_wait[nextbuf] == FALSE ) { hvl_DecodeFrame( ht, audiobuffer[nextbuf], audiobuffer[nextbuf]+sizeof( int16 ), 4 ); ahi_io[nextbuf]->ahir_Std.io_Command = CMD_WRITE; ahi_io[nextbuf]->ahir_Std.io_Data = audiobuffer[nextbuf]; ahi_io[nextbuf]->ahir_Std.io_Length = audiobuflen; ahi_io[nextbuf]->ahir_Std.io_Offset = 0; ahi_io[nextbuf]->ahir_Type = AHIST_S16S; ahi_io[nextbuf]->ahir_Frequency = FREQ; ahi_io[nextbuf]->ahir_Volume = 0x10000; ahi_io[nextbuf]->ahir_Position = 0x8000; ahi_io[nextbuf]->ahir_Link = prev_req; IExec->SendIO( (struct IORequest *)ahi_io[nextbuf] ); prev_req = ahi_io[nextbuf]; need_wait[nextbuf] = TRUE; nextbuf ^= 1; } }
JNIEXPORT jint JNICALL Java_com_ssb_droidsound_plugins_HivelyPlugin_N_1getSoundData(JNIEnv *env, jobject obj, jlong song, jshortArray bArray, int size) { struct hvl_tune *tune = (struct hvl_tune *)song; jshort *dest = env->GetShortArrayElements(bArray, NULL); int8 *ptr = (int8 *)dest; int len = ((44100*2)/5); for(int i=0; i<10; i++) { //__android_log_print(ANDROID_LOG_VERBOSE, "HivelyPlugin", "mixing to %p", ptr); hvl_DecodeFrame(tune, ptr, ptr+2, 4); ptr += ((44100*2*2)/50); } //for(int i=0; i<len; i++) { // int x = ((uint16_t*)dest)[i]; // dest[i] = (jshort)(x - 0x8000); //} env->ReleaseShortArrayElements(bArray, dest, 0); return len; }
void mix_and_play( struct hvl_tune *ht, uint8 *stream, int length ) { int16 *out; //int16 *buf1, *buf2; int i; size_t streamPos = 0; length = length >> 1; if(tune) { // Mix to 16bit interleaved stereo out = (int16*) stream; // Flush remains of previous frame for(i = hivelyIndex; i < (HIVELY_LEN); i++) { out[streamPos++] = hivelyLeft[i]; out[streamPos++] = hivelyRight[i]; } while(streamPos < length) { hvl_DecodeFrame( tune, (int8 *) hivelyLeft, (int8 *) hivelyRight, 2 ); for(i = 0; i < (HIVELY_LEN) && streamPos < length; i++) { out[streamPos++] = hivelyLeft[i]; out[streamPos++] = hivelyRight[i]; } } hivelyIndex = i; } }
int getSamples(int16_t *target, int noSamples) override { const int frameSize = ((44100*2)/50); int8_t *ptr = (int8_t*)target; int len = 0; while(len < noSamples-frameSize) { hvl_DecodeFrame(tune, ptr, ptr+2, 4); ptr += frameSize*2; len += frameSize; } return len; }
JNIEXPORT jint JNICALL Java_com_ssb_droidsound_plugins_HivelyPlugin_N_1getSoundData(JNIEnv *env, jobject obj, jlong song, jshortArray bArray, int size) { struct hvl_tune *tune = (struct hvl_tune *)song; jshort *dest = env->GetShortArrayElements(bArray, NULL); int8 *ptr = (int8 *)dest; int len = ((44100*2)/5); for(int i=0; i<10; i++) { hvl_DecodeFrame(tune, ptr, ptr+2, 4); ptr += ((44100*2*2)/50); } env->ReleaseShortArrayElements(bArray, dest, 0); return len; }