Output in PortAudio

て烟熏妆下的殇ゞ 提交于 2021-01-29 08:26:37

问题


I am trying to learn PortAudio, I am following the tutorials in doc/src/tutorials, this is the code in writing_a_callback.dox:

typedef struct
{
    float left_phase;
    float right_phase;
}   
paTestData;

/* This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free().
*/ 
static int patestCallback( const void *inputBuffer, void *outputBuffer,
                           unsigned long framesPerBuffer,
                           const PaStreamCallbackTimeInfo* timeInfo,
                           PaStreamCallbackFlags statusFlags,
                           void *userData )
{
    /* Cast data passed through stream to our structure. */
    paTestData *data = (paTestData*)userData; 
    float *out = (float*)outputBuffer;
    unsigned int i;
    (void) inputBuffer; /* Prevent unused variable warning. */
    
    for( i=0; i<framesPerBuffer; i++ )
    {
        *out++ = data->left_phase;  /* left */
        *out++ = data->right_phase;  /* right */

        /* Generate simple sawtooth phaser that ranges between -1.0 and 1.0. */
        data->left_phase += 0.01f;
        /* When signal reaches top, drop back down. */
        if( data->left_phase >= 1.0f ) data->left_phase -= 2.0f;

        /* higher pitch so we can distinguish left and right. */
        data->right_phase += 0.03f;
        if( data->right_phase >= 1.0f ) data->right_phase -= 2.0f;
    }
    return 0;
}

It works fine, but I have a few questions:

  1. I have a struct with 2 float variables, but how does PortAudio know which is for the left speaker and which for the right
  2. In this example, what am I passing to the output buffer, frequency, volume or something else, and how can I tell PortAudio about the others, for example, if I am passing frequency then how can I tell it to adjust the volume

Probably I am missing something but... I don't know


Any attempt to help is appreciated

来源:https://stackoverflow.com/questions/65806332/output-in-portaudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!