I have 2 or more audio frames structured as:
int sample_rate; // The sample-rate of this buffer (48000 or 44100 normaly)
int no_channels; // The number of audio channels
int no_samples; // The number of audio samples per channel (n elements in data array)
float* p_data; // The audio data
to add 2 audio buffers togeder is quite simple: frameInput1; frameInput2;
frameOutput.sample_rate = 48000;
frameOutput.no_channel = 1;
frameOutput.no_sample = 1000;
frameOutput.p_data = (float*)malloc(frameOutput.no_sample * frameOutput.no_channel * sizeof(float))
for(int i=0; i<frameOutput.no_sample; i++){
frameOutput.p_data[i] = frameInput1.p_data[i] + frameInput2.p_data[i];
}
I created an audiobuffer with same sample, and I added the input frame for every sample in the data array
but if I have audio buffer with different no_sample, or different sample_rate?
for example:
input1.sample_rate = 48000hz; input1.no_sample = 1000 ;
input2.sample_rate = 44100hz; input2.no_sample = 600 ;
how do I add this two inputs?
Just scale the address in the buffer in respect to sample_rate:
Anyway, remember, that just adding "volume" values is wrong, you will easy get to overflow when loudness in both buffers will be at maximum. But this is another question and another problem you have ahead.