PortAudio: how to generate multiple sounds I have simple wave generator in PortAudio. I'm creating single sine wave, and then I use a lookup sine to play it. Now I've stucked here. I have no idea how I can add another sine sound. Is it possible to somehow add new channel with another sound?

Here is my code:

soundengine.cpp

#include "soundengine.h"
#include &lt;QDebug&gt;

void SoundEngine::run()
{
    PaStreamParameters outputParameters;
    int i;
    double t;
    turnOFF = false;
    isPressed = false;

    static unsigned long n=0;
    for( i=0; i&lt;TABLE_SIZE; i++, n++ )
    {
        t = (double)i/(double)SAMPLE_RATE;
        data.sine[i] = 0.80f * (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
    }
    data.phase = 0;
    data.phase_increment = CalcPhaseIncrement(0);


    err = Pa_Initialize();
    if(err != paNoError) qDebug()&lt;&lt;"Błąd przy inicjalizacji strumienia:"&lt;&lt;Pa_GetErrorText(err);

    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
    if (outputParameters.device == paNoDevice) qDebug()&lt;&lt;"Błąd: Brak domyślnego urządzenia wyjścia!";

    outputParameters.channelCount = 2;       /* stereo output */
    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )-&gt;defaultLowOutputLatency;
    outputParameters.hostApiSpecificStreamInfo = NULL;

    err = Pa_OpenStream(
              &amp;stream,
              NULL, /* no input */
              &amp;outputParameters,
              SAMPLE_RATE,
              FRAMES_PER_BUFFER,
              paClipOff|paDitherOff,      /*paNoFlag we won't output out of range samples so don't bother clipping them */
              patestCallback,
              &amp;data );
    if(err != paNoError) qDebug()&lt;&lt;"Błąd przy otwieraniu strumienia:"&lt;&lt;Pa_GetErrorText(err);
    err = Pa_StartStream( stream );
    if(err != paNoError) qDebug()&lt;&lt;"Błąd przy starcie strumienia:"&lt;&lt;Pa_GetErrorText(err);

    while (turnOFF == false) {
        Pa_Sleep(500);
    }

    err = Pa_StopStream( stream );
    if(err != paNoError) qDebug()&lt;&lt;"Błąd przy zatrzymywaniu strumienia:"&lt;&lt;Pa_GetErrorText(err);
    err = Pa_CloseStream( stream );
    if(err != paNoError) qDebug()&lt;&lt;"Błąd przy zamykaniu strumienia:"&lt;&lt;Pa_GetErrorText(err);
    Pa_Terminate();
}

float SoundEngine::LookupSine( paTestData *data, float phase )
{
    float fIndex = phase*TABLE_SIZE;
    int   index = (int) fIndex;
    float fract = fIndex - index;
    float lo = data-&gt;sine[index];
    float hi = data-&gt;sine[index+1];
    float val = lo + fract*(hi-lo);
    return val;
}

int SoundEngine::patestCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
{
    paTestData *callData = (paTestData*)userData;
    float *out = (float*)outputBuffer;
    float sample;
    unsigned long i;

    (void) timeInfo; /* Prevent unused variable warnings. */
    (void) statusFlags;
    (void) inputBuffer;

    for( i=0; i&lt;framesPerBuffer; i++ )
    {
            sample = LookupSine(callData, callData-&gt;phase);
            *out++ = sample;  /* left */
            *out++ = sample;  /* right */

        callData-&gt;phase += callData-&gt;phase_increment;
        if( callData-&gt;phase &gt;= 1.0f ) callData-&gt;phase -= 1.0f;
    }

    return paContinue;
}

void SoundEngine::generateSine()
{
    if(isPressed == false)
    {
        data.phase_increment = CalcPhaseIncrement(220.0);
        isPressed = true;
    }


}

void SoundEngine::removeSine()
{
            data.phase_increment = CalcPhaseIncrement(0.0);
            isPressed = false;
}


To play sound I use generateSine() method. Maybe is there better way to play sound at given frequency, using one method(like generateSine() in my example). I would like to play two sounds by using generateSine() method twice.
The beauty of PCM (pulse-coded modulation, i.e. time samples of audio) is that the mathematical sum of two signals sounds like the acoustical superposition.

So, just add your two sines sample-wise.