问题
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:
- I have a
struct
with 2float
variables, but how does PortAudio know which is for the left speaker and which for the right - 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