memento-mori
June 7th, 2010, 12:04 AM
Hello all,
I was attempting to write a mini OpenAL app on my 10.04 system performing basic playback and I've become a little stuck and was hoping one of you nice folks would be able to help out.
Short problem description:
--------------------------------
My application appears to run and terminate without problem but there appears to be no audio coming from my speakers.
--------------------------------
Longer version
--------------------------------
The data from the wave file I'm trying to play appears to read in OK (and has been shown to work previously when originally coded on a windows box a few years ago, so I've ruled this out as the problem).
The OpenAL device and context respectively open and create OK, the buffers and sources generate without error (and populate without error in the case of the buffer).
The device I'm opening is the default device which appears to be "OSS Software".
This is the only result from the following function call, which as I understand is meant to list all the devices present (separated by 0x00, and terminated by 0x00, 0x00):
alcGetString( NULL, ALC_DEVICE_SPECIFIER )
--------------------------------
I have a horrible feeling this will be a device related problem, and probably something to do with pulseaudio.
I've tried playing with /etc/libao.conf
setting the content to:
default_driver=pulse
instead of:
default_driver=alsa
and I've tried playing with /etc/openal/alsoft.conf
enabling the line:
drivers = pulse,alsa,oss,solaris,dsound,winmm,port,wave
and changing it to:
drivers = pulse,alsa
...with no luck unfortunately.
Although admittedly, I have no idea what these files configure directly, I read elsewhere that this solved a similar problem so I gave it a bash (and thought I'd mention it for some reason or other).
I've included the example's code block below for completeness - but this should mostly be OK.
int main( void )
{
unsigned char * pBuffer = 0;
unsigned char * pData = 0;
unsigned int uiSize = 0;
Wave::WaveFMT formatChunk;
// pBuffer = data buffer for entire wav file
// pData = pointer to the start of the audio data
bool success = Wave::LoadWav( "test.wav", &pBuffer, uiSize, &pData, formatChunk );
if( success )
{
const ALCchar *default_device;
default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
// start openal
ALCdevice* pDevice = alcOpenDevice( default_device ); // first sound device
if( pDevice == 0 )
return 1;
ALCcontext* pContext = alcCreateContext( pDevice, NULL );
alcMakeContextCurrent( pContext );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
//
// open the audio
//
// sound effect vars
unsigned int uiSource;
// get the openAL format
ALenum openAlFormat = AL_UNDETERMINED;
if( formatChunk.channels == 1 )
{
if( formatChunk.bits_per_sample == 8 )
openAlFormat = AL_FORMAT_MONO8;
else if( formatChunk.bits_per_sample == 16 )
openAlFormat = AL_FORMAT_MONO16;
}
else if( formatChunk.channels == 2 )
{
if( formatChunk.bits_per_sample == 8 )
openAlFormat = AL_FORMAT_STEREO8;
else if( formatChunk.bits_per_sample == 16 )
openAlFormat = AL_FORMAT_STEREO16;
}
// a supported format was not acquired
if( openAlFormat == AL_UNDETERMINED )
{
// only [mono,stereo] [8,16] bit sound effects are supported.
Wave::FreeWavBuffer( &pBuffer );
return 1;
}
// Create an OpenAL data buffer
ALuint openal_buffer_id = 0;
alGenBuffers( 1, &openal_buffer_id );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
// Add the data to the buffer
alBufferData( openal_buffer_id, openAlFormat, (ALvoid*)(pData), (ALsizei)uiSize, (ALsizei)formatChunk.sample_rate );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
// we've copied the data - unload the buffer data
Wave::FreeWavBuffer( &pBuffer );
//
// Play the audio
//
alGenSources( 1, &uiSource );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
alSourcei( uiSource, AL_BUFFER, openal_buffer_id );
alSourcef( uiSource, AL_GAIN, 1.0f );
alSource3f( uiSource, AL_POSITION, 0.f, 0.f, 0.f );
alSource3f( uiSource, AL_VELOCITY, 0.f, 0.f, 0.f );
alSourcei( uiSource, AL_LOOPING, AL_TRUE );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
alSourcePlay( uiSource );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
sleep( 6 );
alSourceStop( uiSource );
alDeleteSources( 1, &uiSource );
alDeleteBuffers( 1, &openal_buffer_id );
alcMakeContextCurrent(NULL);
alcDestroyContext(pContext);
alcCloseDevice(pDevice);
}
return 0;
}
Any thoughts on what's wrong here would be gratefully received.
Many thanks in advance,
I was attempting to write a mini OpenAL app on my 10.04 system performing basic playback and I've become a little stuck and was hoping one of you nice folks would be able to help out.
Short problem description:
--------------------------------
My application appears to run and terminate without problem but there appears to be no audio coming from my speakers.
--------------------------------
Longer version
--------------------------------
The data from the wave file I'm trying to play appears to read in OK (and has been shown to work previously when originally coded on a windows box a few years ago, so I've ruled this out as the problem).
The OpenAL device and context respectively open and create OK, the buffers and sources generate without error (and populate without error in the case of the buffer).
The device I'm opening is the default device which appears to be "OSS Software".
This is the only result from the following function call, which as I understand is meant to list all the devices present (separated by 0x00, and terminated by 0x00, 0x00):
alcGetString( NULL, ALC_DEVICE_SPECIFIER )
--------------------------------
I have a horrible feeling this will be a device related problem, and probably something to do with pulseaudio.
I've tried playing with /etc/libao.conf
setting the content to:
default_driver=pulse
instead of:
default_driver=alsa
and I've tried playing with /etc/openal/alsoft.conf
enabling the line:
drivers = pulse,alsa,oss,solaris,dsound,winmm,port,wave
and changing it to:
drivers = pulse,alsa
...with no luck unfortunately.
Although admittedly, I have no idea what these files configure directly, I read elsewhere that this solved a similar problem so I gave it a bash (and thought I'd mention it for some reason or other).
I've included the example's code block below for completeness - but this should mostly be OK.
int main( void )
{
unsigned char * pBuffer = 0;
unsigned char * pData = 0;
unsigned int uiSize = 0;
Wave::WaveFMT formatChunk;
// pBuffer = data buffer for entire wav file
// pData = pointer to the start of the audio data
bool success = Wave::LoadWav( "test.wav", &pBuffer, uiSize, &pData, formatChunk );
if( success )
{
const ALCchar *default_device;
default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
// start openal
ALCdevice* pDevice = alcOpenDevice( default_device ); // first sound device
if( pDevice == 0 )
return 1;
ALCcontext* pContext = alcCreateContext( pDevice, NULL );
alcMakeContextCurrent( pContext );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
//
// open the audio
//
// sound effect vars
unsigned int uiSource;
// get the openAL format
ALenum openAlFormat = AL_UNDETERMINED;
if( formatChunk.channels == 1 )
{
if( formatChunk.bits_per_sample == 8 )
openAlFormat = AL_FORMAT_MONO8;
else if( formatChunk.bits_per_sample == 16 )
openAlFormat = AL_FORMAT_MONO16;
}
else if( formatChunk.channels == 2 )
{
if( formatChunk.bits_per_sample == 8 )
openAlFormat = AL_FORMAT_STEREO8;
else if( formatChunk.bits_per_sample == 16 )
openAlFormat = AL_FORMAT_STEREO16;
}
// a supported format was not acquired
if( openAlFormat == AL_UNDETERMINED )
{
// only [mono,stereo] [8,16] bit sound effects are supported.
Wave::FreeWavBuffer( &pBuffer );
return 1;
}
// Create an OpenAL data buffer
ALuint openal_buffer_id = 0;
alGenBuffers( 1, &openal_buffer_id );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
// Add the data to the buffer
alBufferData( openal_buffer_id, openAlFormat, (ALvoid*)(pData), (ALsizei)uiSize, (ALsizei)formatChunk.sample_rate );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
// we've copied the data - unload the buffer data
Wave::FreeWavBuffer( &pBuffer );
//
// Play the audio
//
alGenSources( 1, &uiSource );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
alSourcei( uiSource, AL_BUFFER, openal_buffer_id );
alSourcef( uiSource, AL_GAIN, 1.0f );
alSource3f( uiSource, AL_POSITION, 0.f, 0.f, 0.f );
alSource3f( uiSource, AL_VELOCITY, 0.f, 0.f, 0.f );
alSourcei( uiSource, AL_LOOPING, AL_TRUE );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
alSourcePlay( uiSource );
assert( ALC_NO_ERROR == alcGetError( pDevice ) );
sleep( 6 );
alSourceStop( uiSource );
alDeleteSources( 1, &uiSource );
alDeleteBuffers( 1, &openal_buffer_id );
alcMakeContextCurrent(NULL);
alcDestroyContext(pContext);
alcCloseDevice(pDevice);
}
return 0;
}
Any thoughts on what's wrong here would be gratefully received.
Many thanks in advance,