示例#1
0
文件: s_main.c 项目: bryansum/pdlib
void audioOutputCallbackFn(const AudioTimeStamp *inTimestamp) {
    
    if (sys_userCallbackFn) {
        (*sys_userCallbackFn)(inTimestamp);
    }
    
    sched_audio_callbackfn();
}
void ofxPd::renderAudio( float * input, float* output, int bufferSize, int nChannels ){
	// adapted from AudioOutputController by bryan summerset
	
	// sys_schedblocksize is How many frames we have per PD dsp_tick
    // inNumberFrames is how many frames have been requested
	int inNumberFrames = bufferSize;
    
    // Make sure we're dealing with evenly divisible numbers between
    // the number of frames requested vs the block size for a given PD dsp tick.
    //Otherwise this looping scheme we're doing below doesn't make much sense.
    assert(inNumberFrames % sys_schedblocksize == 0);
	
    // How many times to generate a DSP event in PD
    int times = inNumberFrames / sys_schedblocksize;
	
    for(int i = 0; i < times; i++) {
        
		
		for (int n = 0; n < sys_schedblocksize; n++) {
            for(int ch = 0; ch < sys_ninchannels; ch++) {
				sys_soundin[n+sys_schedblocksize*ch] =   input[(n*sys_ninchannels+ch) + // offset in iteration
															   i*sys_schedblocksize*sys_ninchannels]; // iteration starting address
				
				
            }        
        }
		
		
		// do one Pd DSP block
        sys_lock();
		sched_audio_callbackfn();
        sys_unlock();
		
        // This should cover sys_noutchannels channels. Turns non-interleaved into 
        // interleaved audio.
        for (int n = 0; n < sys_schedblocksize; n++) {
            for(int ch = 0; ch < sys_noutchannels; ch++) {
                t_sample fsample = CLAMP(sys_soundout[n+sys_schedblocksize*ch],-1,1);
                output[(n*sys_noutchannels+ch) + // offset in iteration
					   i*sys_schedblocksize*sys_noutchannels] // iteration starting address
				
				
				
				= fsample;
				//sys_soundin[n+sys_schedblocksize*ch] = ofRandom(-0.5,0.5); // iteration starting address
				
			}        
        }
        
        // After loading the samples, we need to clear them for the next iteration
        memset(sys_soundout, 0, sizeof(t_sample)*sys_noutchannels*sys_schedblocksize);        
    }
}