0

I successfully installed the OpenAL the with the following command:

  yum install freealut freealut-devel 

But the problem after this I add some c++ codes to work with this libraries as below:

     #include <AL/al.h>
     #include <AL/alc.h>
     #include <AL/alut.h>

    void init_al()
    {
        ALCdevice *dev = NULL;
        ALCcontext *ctx = NULL;

        const char *defname = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
        std::cout << "Default device: " << defname << std::endl;

        dev = alcOpenDevice(defname);
        ctx = alcCreateContext(dev, NULL);
        alcMakeContextCurrent(ctx);
        alGenBuffers(1, &buf);

        /* Fill buffer with Sine-Wave */
        freq = 1440.f;
        seconds = 0.2;
        sample_rate = 22050;
        buf_size = 6000;

        samples = new short[buf_size];
        for(int i=0; i<buf_size; ++i) {
            samples[i] = 32760 * sin( (2.f*float(M_PI)*freq)/sample_rate * i );
        }

        /* Download buffer to OpenAL */
        alBufferData(buf, AL_FORMAT_MONO16, samples, buf_size, sample_rate);


        /* Set-up sound source and play buffer */
         src = 0;
        alGenSources(1, &src);
        alSourcei(src, AL_BUFFER, buf);

        alGenBuffers(1, &buf);

        /* Fill buffer with Sine-Wave */
        freq = 1000.f;
        seconds = 0.2;
        sample_rate = 22050;
        buf_size = 12000;

        samples = new short[buf_size];
        float add=1;
        for(int i=0; i<buf_size; ++i) {
            samples[i] = 32760 * sin( (2.f*float(M_PI)*freq)/sample_rate * i );
        }

        /* Download buffer to OpenAL */
        alBufferData(buf, AL_FORMAT_MONO16, samples, buf_size, sample_rate);


        /* Set-up sound source and play buffer */
         src2 = 0;
        alGenSources(1, &src2);
        alSourcei(src2, AL_BUFFER, buf);

    }

I think my problem is on the linkers that can be added to the Eclipse project proprieties I include a linker alut but it also indicates an error. what could be my problem?

Clickmit Wg
  • 523
  • 2
  • 9
  • 25

1 Answers1

0

These are the standard openal headers - not sure why you're trying to use alut or freealut.

#include  <AL/al.h>
#include  <AL/alc.h>

//   #include <OpenAL/al.h>   // apple only
//   #include <OpenAL/alc.h>   // apple only

I use the standard openal where its linker flag is -lopenal
however I've not used freealut. Its linker flag is probably either

alut
or maybe  freealut

so its compile line flag would be the -l followed by flag as in -lalut

Your supplied code is not complete - its missing many var definitions so cannot compile at my end

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104