//This is the portaudio callback function, the audio is processed
//in the for loop.
int portAudio::paCallback( const void *inputBuffer, void *outputBuffer,
                      unsigned long framesPerBuffer,
                      const PaStreamCallbackTimeInfo* timeInfo,
                      PaStreamCallbackFlags statusFlags,
                                 void *userData ) {
    
    /* Cast data passed through stream to our structure. */
    Buffer *theBuffer = (Buffer*)userData;
    float *out = (float*)outputBuffer;
    unsigned int i;
    
    (void) inputBuffer; /* Prevent unused variable warning. */
    
    //This is the audio data buffered from Pd.  We get it in chunks of 64,
    //since we are using stereo, the outbuf gets two chucks, or 128 numbers
    libpd_process_double(1, theBuffer->inbuf, theBuffer->outbuf);
    
    //dsp perform routine, channels are interlaced (e.g out[0] = left, out[1] = right, etc.)
    for( i=0; i<framesPerBuffer*2; i++ )
    {
        if(i % 2)
            *out++ = theBuffer->outbuf[i]; // right channel
        else
            *out++ = theBuffer->outbuf[i]; // left channel
    }
    
    return 0;

}
Exemple #2
0
JNIEXPORT jint JNICALL Java_org_puredata_core_PdBase_process__I_3D_3D
(JNIEnv *env, jclass cls, jint ticks,
    jdoubleArray inBuffer, jdoubleArray outBuffer) {
  if (!inBuffer || !outBuffer) return -10;
  double *pIn = (*env)->GetDoubleArrayElements(env, inBuffer, NULL);
  double *pOut = (*env)->GetDoubleArrayElements(env, outBuffer, NULL);
  pthread_mutex_lock(&mutex);
  jint err = libpd_process_double((int) ticks, pIn, pOut);
  pthread_mutex_unlock(&mutex);
  (*env)->ReleaseDoubleArrayElements(env, inBuffer, pIn, 0);
  (*env)->ReleaseDoubleArrayElements(env, outBuffer, pOut, 0);
  return err;
}
Exemple #3
0
bool PdBase::processDouble(int ticks, double* inBuffer, double* outBuffer) {
    return libpd_process_double(ticks, inBuffer, outBuffer) == 0;
}
Exemple #4
0
bool PdBase::processDouble(int ticks, const double* inBuffer, double* outBuffer) {
    _LOCK();
    bool ret = libpd_process_double(ticks, inBuffer, outBuffer) == 0;
    _UNLOCK();
    return ret;
}