How to install OpenAL SDK on Ubuntu?
Asked Answered
L

3

5

I'm very new to Linux and programming on Linux. I'm trying to install OpenAL SDK on ubuntu ... My best guess is that I will need to download OpenAL from the CVS repo. I found a tutorial: http://www.edenwaith.com/products/pige/tutorials/openal.php

However, when I try to run the terminal command this is what happens:

steven@ubuntu:~$ cvs -d:pserver:[email protected]:/usr/local/cvs-repository login
Logging in to :pserver:[email protected]:2401/usr/local/cvs-repository
CVS password: 
cvs [login aborted]: connect to opensource.creative.com(124.246.64.74):2401 failed: No route to host

Any tips on how to get the OpenAL SDK installed?

Lipread answered 25/6, 2012 at 18:46 Comment(0)
P
3

Why do you download from cvs instead of simply running apt-get install libopenal-dev? This automatically downloads OpenAL and its dependency.

Polivy answered 25/6, 2012 at 21:10 Comment(1)
Maybe the package name has been changed? Use apt-get install libopenal-dev will install the package successfully, while apt-get install openal-dev will get a message "unable to locate package openal-dev".Occultism
S
18
sudo apt-get install libopenal-dev

will install OpenAL SDK and get you up and running ... alternatively if you want to compile from source ... the open source fork of openal lives at https://github.com/kcat/openal-soft (do a git log of the code once you do the git clone and you will see these two are source code mirrors )

install preliminary package to give you development tooling

sudo apt-get install build-essential

get current source :

#  git clone git://repo.or.cz/openal-soft.git  # both are same code
git clone [email protected]:kcat/openal-soft.git

cd openal-soft 
cd build
cmake ..   # get cmake using ...  sudo apt-get install cmake 
make

if no errors, then install :

sudo make install -j$(nproc)

totally feel free to post here any errors you encounter - ubuntu 12.04 or newer nicely offers apt-get install for all necessary libraries.

here are some optional upstream libs

sudo apt-get install libsdl-sound1.2-dev
sudo apt-get install  libmyth-dev # may not be needed YMMV

now that you have needed libraries installed compile your coding using

gcc -o my_cool_openal_binary   my_cool_code_openal.c  -lopenal -lm

assuming your own source code file in the c language is called

my_cool_code_openal.c

execute your new binary

./my_cool_openal_binary

for completeness save below to a file called my_cool_code_openal.c then compile below code using above steps

// gcc -o openal_play_monday   openal_play_monday.c  -lopenal -lm

#include <stdio.h>
#include <stdlib.h>    // gives malloc
#include <math.h>
#include <unistd.h>    // gives sleep


#ifdef __APPLE__
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#elif __linux
#include <AL/al.h>
#include <AL/alc.h>
#endif

ALCdevice  * openal_output_device;
ALCcontext * openal_output_context;

ALuint internal_buffer;
ALuint streaming_source[1];

int al_check_error(const char * given_label) {

    ALenum al_error;
    al_error = alGetError();

    if(AL_NO_ERROR != al_error) {

        printf("ERROR - %s  (%s)\n", alGetString(al_error), given_label);
        return al_error;
    }
    return 0;
}

void MM_init_al() {

    const char * defname = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);

    openal_output_device  = alcOpenDevice(defname);
    openal_output_context = alcCreateContext(openal_output_device, NULL);
    alcMakeContextCurrent(openal_output_context);

    // setup buffer and source

    alGenBuffers(1, & internal_buffer);
    al_check_error("failed call to alGenBuffers");
}

void MM_exit_al() {

    ALenum errorCode = 0;

    // Stop the sources
    alSourceStopv(1, & streaming_source[0]);        //      streaming_source
    int ii;
    for (ii = 0; ii < 1; ++ii) {
        alSourcei(streaming_source[ii], AL_BUFFER, 0);
    }
    // Clean-up
    alDeleteSources(1, &streaming_source[0]);
    alDeleteBuffers(16, &streaming_source[0]);
    errorCode = alGetError();
    alcMakeContextCurrent(NULL);
    errorCode = alGetError();
    alcDestroyContext(openal_output_context);
    alcCloseDevice(openal_output_device);
}

void MM_render_one_buffer() {

    /* Fill buffer with Sine-Wave */
    // float freq = 440.f;
    float freq = 100.f;
    float incr_freq = 0.1f;

    int seconds = 4;
    // unsigned sample_rate = 22050;
    unsigned sample_rate = 44100;
    double my_pi = 3.14159;
    size_t buf_size = seconds * sample_rate;

    // allocate PCM audio buffer        
    short * samples = malloc(sizeof(short) * buf_size);

   printf("\nhere is freq %f\n", freq);
    int i=0;
    for(; i<buf_size; ++i) {
        samples[i] = 32760 * sin( (2.f * my_pi * freq)/sample_rate * i );

        freq += incr_freq;
        // incr_freq += incr_freq;
        // freq *= factor_freq;

        if (100.0 > freq || freq > 5000.0) {

            incr_freq *= -1.0f;
        }
    }

    /* upload buffer to OpenAL */
    alBufferData( internal_buffer, AL_FORMAT_MONO16, samples, buf_size, sample_rate);
    al_check_error("populating alBufferData");

    free(samples);

    /* Set-up sound source and play buffer */
    // ALuint src = 0;
    // alGenSources(1, &src);
    // alSourcei(src, AL_BUFFER, internal_buffer);
    alGenSources(1, & streaming_source[0]);
    alSourcei(streaming_source[0], AL_BUFFER, internal_buffer);
    // alSourcePlay(src);
    alSourcePlay(streaming_source[0]);

    // ---------------------

    ALenum current_playing_state;
    alGetSourcei(streaming_source[0], AL_SOURCE_STATE, & current_playing_state);
    al_check_error("alGetSourcei AL_SOURCE_STATE");

    while (AL_PLAYING == current_playing_state) {

        printf("still playing ... so sleep\n");

        sleep(1);   // should use a thread sleep NOT sleep() for a more responsive finish

        alGetSourcei(streaming_source[0], AL_SOURCE_STATE, & current_playing_state);
        al_check_error("alGetSourcei AL_SOURCE_STATE");
    }

    printf("end of playing\n");

    /* Dealloc OpenAL */
    MM_exit_al();

}   //  MM_render_one_buffer

int main() {

    MM_init_al();

    MM_render_one_buffer();
}
Spectrometer answered 26/6, 2012 at 2:42 Comment(1)
The include path is most likely /usr/include/AL/ and you can link to your application with -lopenal. Note: you will probably also need freealut : sudo apt-get install libalut-dev and linking with -lalutSpencer
P
3

Why do you download from cvs instead of simply running apt-get install libopenal-dev? This automatically downloads OpenAL and its dependency.

Polivy answered 25/6, 2012 at 21:10 Comment(1)
Maybe the package name has been changed? Use apt-get install libopenal-dev will install the package successfully, while apt-get install openal-dev will get a message "unable to locate package openal-dev".Occultism
L
-1

New package name seems to be openal-soft-devel

Lefty answered 25/10, 2020 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.