代码之家  ›  专栏  ›  技术社区  ›  Linus Unnebäck

C++和pulseaudio“未在此范围内声明”

  •  0
  • Linus Unnebäck  · 技术社区  · 17 年前

    我试图使用pulseaudio来播放vorbis流的比赛,但遇到了问题。基本上,我被告知:

    ‘pa_simple’ was not declared in this scope
    ‘pa_simple_new’ was not declared in this scope
    ‘pa_simple_write’ was not declared in this scope
    

    下面显示了一些代码:

    #include <pulse/pulseaudio.h>
    

    pa_simple *s;
    pa_sample_spec ss;
    
    ss.format = PA_SAMPLE_S16NE;
    ss.channels = 2;
    ss.rate = 44100;
    
    s = pa_simple_new(
        NULL,               // Use the default server.
        "Fooapp",           // Our application's name.
        PA_STREAM_PLAYBACK, // Playback
        NULL,               // Use the default device.
        "Music",            // Description of our stream.
        &ss,                // Our sample format.
        NULL,               // Use default channel map
        NULL,               // Use default buffering attributes.
        NULL,               // Ignore error code.
    );
    

    while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0){
        int j;
        int bout=(samples<convsize?samples:convsize);
        cout << "D" << endl;
        for(i=0;i<vi.channels;i++){
            ogg_int16_t *ptr=convbuffer+i;
            float  *mono=pcm[i];
            for(j=0;j<bout;j++){
                int val=floor(mono[j]*32767.f+.5f);
                *ptr=val;
                ptr+=vi.channels;
            }
        }
        cout << "E" << endl;
        #ifdef PulseAudio
        pa_simple_write(s,convbuffer,2*vi.channels,NULL);
        #else
        fwrite(convbuffer,2*vi.channels,bout,output);
        #endif
        vorbis_synthesis_read(&vd,bout);
        cout << "F" << endl;
    }
    

    1 回复  |  直到 7 年前
        1
  •  5
  •   VoteyDisciple    17 年前

    这些东西都定义在 简单。h ,因此添加一个新 #include 到文件顶部:

    #include <pulse/simple.h>