// Returns the number of bytes that can be read from the speed alteration
// object
jint Java_org_vinuxproject_sonic_Sonic_availableBytesNative(
    JNIEnv *env,
    jobject thiz,
    jlong sonicID)
{
    sonicStream stream = getInst(sonicID)->stream;
    LOGV("Reading samples available = %d", sonicSamplesAvailable(stream)*sizeof(short)*sonicGetNumChannels(stream));

    return sonicSamplesAvailable(stream)*sizeof(short)*sonicGetNumChannels(stream);
}
// Get bytes representing sped up/slowed down sound and put up to lenBytes
// into ret.
// Returns number of bytes read, or -1 if we run out of memory.
jint Java_org_vinuxproject_sonic_Sonic_receiveBytesNative(
    JNIEnv *env,
    jobject thiz,
    jlong sonicID,
    jbyteArray ret,
    jint lenBytes)
{
    sonicInst inst = getInst(sonicID);
    sonicStream stream = inst->stream;
    int available = sonicSamplesAvailable(stream)*sizeof(short)*sonicGetNumChannels(stream);
    int samplesRead, bytesRead;

    LOGV("Reading %d bytes from stream", lenBytes);
    if(lenBytes > available) {
        lenBytes = available;
    }
    if(lenBytes > inst->byteBufSize*sizeof(short)) {
        inst->byteBufSize = lenBytes*(2/sizeof(short));
        inst->byteBuf = (short *)realloc(inst->byteBuf, inst->byteBufSize*sizeof(short));
        if(inst->byteBuf == NULL) {
            return -1;
        }
    }
    //LOGV("Doing read %d", lenBytes);
    samplesRead = sonicReadShortFromStream(stream, inst->byteBuf,
	lenBytes/(sizeof(short)*sonicGetNumChannels(stream)));
    bytesRead = samplesRead*sizeof(short)*sonicGetNumChannels(stream); 
    //LOGV("Returning %d", samplesRead);
    (*env)->SetByteArrayRegion(env, ret, 0, bytesRead, (jbyte *)inst->byteBuf);
    return bytesRead;
}
示例#3
0
 void rate_controller::on_output()
 {
   int n=sonicSamplesAvailable(stream);
   if(n>0)
     {
       if(n>samples.size())
         samples.resize(n,0);
       sonicReadFloatFromStream(stream,&samples[0],n);
       output.assign(samples.begin(),samples.begin()+n);
     }
 }
示例#4
0
 bool speech_stream::read(speech_stream::buffer_type& buffer,int min_size)
 {
   if(sonic_stream)
     {
       if(min_size==0)
         flush_input_buffer();
       int nsamples=sonicSamplesAvailable(sonic_stream);
       if((nsamples==0)||(nsamples<min_size))
         return false;
       buffer.resize(nsamples,0);
       sonicReadShortFromStream(sonic_stream,&buffer[0],nsamples);
     }
   else
     {
       if(samples.empty()||(samples.size()<min_size))
         return false;
       buffer=samples;
       samples.clear();
     }
   return true;
 }