Portaudio MULTIPLE CALLBACK

时间:2016-09-17 20:43:26

标签: callback portaudio

可以取悦有人给我编写一个内部回调的例子 回调"或者给我一些参考? 例如,同时具有正弦和输入。 我试图在回调中使用一个函数,但是出了点问题...... 这是代码:

#include <stdio.h>
#include <math.h>
#include "portaudio.h"

#define NUM_SECONDS   (1)
#define SAMPLE_RATE   (192000)
#define FRAMES_PER_BUFFER  (2048)

#ifndef M_PI
#define M_PI  (3.14159265)
#endif
#define TWOPI (2.0 * M_PI)

float freq = 220.0;
float curphase = 0.0;

float FUNZIONE (float a)          // CUSTOM FUNCTION
{
    return tan(a);
}

typedef struct
{
float (*F)(float);                // DECLARATION OF POINTER (TO CUSTOM FUNCTION)
}

paTestData;

F = FUNZIONE;                     // ASSIGN CUSTOM FUNCTION TO POINTER


                                  // GENERATION OF A SINE

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

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

float incr = freq * TWOPI / SAMPLE_RATE;

for( i=0; i<framesPerBuffer; i++ )
{
    *out++ = data->F( sin(curphase) ); // USE OF CUSTOM FUNCTION (BY POINTER)
                                       // ON LEFT OUTPUT
    *out++ = sin(curphase);

    curphase += incr;

    if (curphase >= TWOPI){
        curphase -= TWOPI;
    }

    if (curphase < 0.0){
        curphase += TWOPI;
    }
}

return paContinue;
}

/*******************************************************************/

int main(void)
{
PaStreamParameters outputParameters;
PaStream *stream;
paTestData data;

Pa_Initialize();

outputParameters.device = Pa_GetDefaultOutputDevice(); 
outputParameters.channelCount = 2;       
outputParameters.sampleFormat = paFloat32; 

outputParameters.suggestedLatency = 
Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;

outputParameters.hostApiSpecificStreamInfo = NULL;

Pa_OpenStream(
          &stream,
          NULL, /* no input */
          &outputParameters,
          SAMPLE_RATE,
          FRAMES_PER_BUFFER,
          paClipOff,      
          patestCallback,
          &data );

Pa_StartStream( stream );

Pa_Sleep( NUM_SECONDS * 1000 );

Pa_StopStream( stream );

Pa_CloseStream( stream );

Pa_Terminate();

Pa_Terminate();

return 0;

}


ERROR MESSAGE FROM COMPILER:

||=== Build: Debug in 1 (compiler: GNU GCC Compiler) ===|   
C:\Users\1\Desktop\NEW\SINE.c|29|warning: data definition has no type
or storage class|
C:\Users\1\Desktop\NEW\SINE.c|29|warning: type defaults to 'int' in
declaration of 'F' [-Wimplicit-int]|
C:\Users\1\Desktop\NEW\SINE.c|29|warning: initialization makes integer
from pointer without a cast|
C:\Users\1\Desktop\NEW\SINE.c||In function 'patestCallback':|
C:\Users\1\Desktop\NEW\SINE.c|52|error: expected identifier before '*' token|
C:\Users\1\Desktop\NEW\SINE.c|37|warning: variable 'data' set but not
used [-Wunused-but-set-variable]|
||=== Build failed: 1 error(s), 4 warning(s) (0 minute(s), 0 second(s)) ===|

非常感谢。

0 个答案:

没有答案