multiPlay from buffer through the audioRequested?


If i want to do several playback via audioRequested at a same time, what do i do?

For multiple playback, first, i made a class for recording&playback

and when i’ve built it, i could hear only the last track.

all other tracks are not played. i don’t know why they aren’t played.

I’d appreciate your help.

codes in testApp is here;

void testApp::audioRequested(float * output, int bufferSize, int nChannels){  
	for(int i=0;i<NUM_TRACK;i++){  

and codes in tracks class is here;

float* play(float* output_, int bufferSize_, int nChannels_){  
		//checking for mode  
		if (mode == 2&&recPos!=xp) {  
			//buffer array to output buffer  
			for (int i = 0; i < bufferSize_*nChannels_; i++) {  
				//checking current playPos  
					//buffer array to output buffer  
					output_[i] = buffer[int(playPos)] * audioLevel;  
					//playPos update with play speed that decided by finger  
					playPos +=playSpeed;  
					//when playPos has overed EndTime , go back(Loop)  
					playPos = xp;  
                    return output_;  

something like this should work (at least it works for most of my synths :slight_smile: ):

//in testApp::audioRequested  
//first I create a float array of bufferSize elements and I zero it every time audioRequested is called  
for(int i=0;i<bufferSize;i++){  
//then I stuff in my sonicBuffer all my voices   
for(int n=0;n<NUM_TRACK;i++){  
   for(int i=0;i<bufferSize;i++){  
      sonicBuffer[i]+=tracks[i].getSample(); //where getSample return a float just like in the audio output example  
//finally I play sonicBuffer  
for(int i=0;i<bufferSize;i++){  
   output[i*nChannels]    =sonicBuffer[i]*volume;  

wow,thank you very much “naus3a” .

i still don’t know how does it work exactly…

But,Codes are worked with your suggestion.

Thank you again! :smiley:

lol, glad it works for you.

in order to try to explain why it works: it’s just a quick and dirt additive synthesis of the different voices :slight_smile:

Oh…It’s interesting that uses a way of additive synthesis.

I feel little bit difficult to handle audioRequested.

Anyway, i seem to have to study more. ~0~

Thank U for helping me!!