OpenAL issues

I'm trying to integrate OpenAL into my application to play some wave files.

This is where I'm stuck:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <AL/al.h>
#include <AL/alc.h>
#include <iostream>

int main()
{
  ALCdevice* m_device = alcOpenDevice(NULL);

  if ( !m_device )
    std::cout << "Couldn't open default OpenAL device." << std::endl;

  return 0;
}
$ make
g++ -c -I/usr/local/include -o obj/main.o src/main.cpp
g++ -g -o bin/main obj/main.o -L/usr/local/lib -lopenal
$ ./bin/main
AL lib: (EE) oss_open_playback: Could not open /dev/dsp: No such file or directory
Couldn't open default OpenAL device.


It seems like I have sound driver issues, but everything else I have installed works fine. My /etc/openal/alsoft.conf contains this line:
drivers = alsa,pulseaudio,pulse,core,oss,solaris,sndio,mmdevapi,dsound,winmm,port,opensl,null,wave.
So OSS is not nearly the first driver to be checked (I think ALSA is the one working right now for everything). I must have something wrong with the OpenAL installation. This is what I did:
1. Download the package 1.15.1 from http://openal-soft.org/
2. Extract to /usr/local/src/
3. Run cmake, then make
4. Binaries are in /usr/local/lib (libopenal.so) and headers are in /usr/local/include
-- Inlcude the lib and include directory in my makefile.
5. Compile and run my own project.

Not sure what's going on! I'm running Mint 14 (kernel 3.5.0.17). I've been native in Linux for about 18 months, but still code at work in Windows. This is my first attempt at linking libraries in Linux. Note /dev/dsp does not exist, but /dev/snd contains quite a few devices.

Thanks,
Last edited on
Maybe try installing openAL itself.

http://stackoverflow.com/questions/3907064/installing-opengl-and-openal-in-ubuntu

Then maybe try installing openAL dev sdk from command line if it still doesn't work

sudo apt-get install libalut-dev
sudo apt-get install libopenal-dev
Last edited on
Already had libopenal-dev installed. Managed to get libalut-dev installed, but that didn't change anything. Where can I find the headers/libs for the newly installed package?

In another attempt to get it running, I ran cmake again and saw this in the output:
Looking for alsa/asoundlib.h - not found
...
-- Building OpenAL with support for the following backends:
-- OSS, WaveFile, Null


Do you know the name of the alsa-dev package or if I need to find a .deb or .tar file somewhere online?
Maybe libasound2-dev?
I mean install the shared library, not the dev package. I think it was already installed on my linux machine, but you might try anyways.

sudo apt-get install libopenal1
sudo apt-get install libopenal-data
sudo apt-get install libalut0 


And if that doesn't work, then try installing all of openAL softs dependencies. They are listed in the link below.

http://packages.ubuntu.com/source/precise/openal-soft
Last edited on
Perfect! Thanks.

I went through the "related" packages. This solved my issue:
1
2
3
4
sudo apt-get install portaudio19-dev
sudo apt-get install libpulse-dev
sudo apt-get install roar-dev
sudo apt-get install libsndio-dev


Now I get this during cmake:
-- Building OpenAL with support for the following backends:
-- ALSA, OSS, SndIO (linked), PortAudio, PulseAudio, WaveFile, Null


And when I run the application below I get this:
$ ./main 
AL lib: (EE) alc_cleanup: 1 device not closed


Which makes complete sense in this context.

Now my wave files play. This was how I wrapped OpenAL for my application if anyone is interested:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "wave.hpp"
#include <AL/al.h>
#include <AL/alc.h>

class SoundSys
{
public:
  SoundSys() { Init(); }
  ~SoundSys() { Close(); }

  void Init();
  void Close();

  void Play(const Wave* const wave );
  typedef std::string SoundExcept;
private:
  ALCdevice*  m_device;
  ALCcontext* m_ctx; 
};

void SoundSys::Init()
{
  m_ctx = 0;

  m_device = alcOpenDevice(NULL);
  if ( !m_device )
    throw SoundExcept("Couldn't open default OpenAL device.");

  m_ctx = alcCreateContext(m_device, NULL);
  if ( !m_ctx )
  {
    alcCloseDevice(m_device);
    throw SoundExcept("Could not create context.");
  }

}

void SoundSys::Play( const Wave* const wave )
{
  if ( !m_ctx || !m_device )
    throw SoundExcept("SoundSys not initialized");

  if ( !wave )
    throw SoundExcept("Wave not available for play");

  const PCM_Wave& w = wave->Peek();

  if (w.data.cksize < 1)
    throw SoundExcept("Empty file will not be played");

  ALCcontext* old_ctx = alcGetCurrentContext();
  alcMakeContextCurrent(m_ctx);

  ALuint buf_id = 0;
  alGenBuffers(1, &buf_id);

  if ( !buf_id ) 
  {
    if ( old_ctx ) alcMakeContextCurrent(old_ctx);
    throw SoundExcept("Could not generate OpenAL buffer");
  }

  alBufferData(buf_id, w.format.wBitsPerSample == 16 ? 
       (w.format.nChannels == 2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16):
       (w.format.nChannels == 2 ? AL_FORMAT_STEREO8  : AL_FORMAT_MONO8 ),
       w.data.data, w.data.cksize, w.format.nSamplesPerSec);

  ALuint src;
  alGenSources(1, &src);

  ALfloat zero[3] = { 0 };
  alSourcei ( src, AL_BUFFER  , buf_id );
  alSourcef ( src, AL_PITCH   , 1.0f   );
  alSourcef ( src, AL_GAIN    , 1.0f   );
  alSourcei ( src, AL_LOOPING , 0      );
  alSourcefv( src, AL_POSITION, zero   );
  alSourcefv( src, AL_VELOCITY, zero   );

  alSourcePlay( src );

  if ( old_ctx ) alcMakeContextCurrent(old_ctx);
}

void SoundSys::Close()
{
  if (m_ctx   ) alcDestroyContext(m_ctx   );
  if (m_device) alcCloseDevice(m_device); 

  m_ctx = 0;
  m_device = 0;
}
Last edited on
Topic archived. No new replies allowed.