Add OpenAL stuff to Makefile, make it compile and work (no streaming sound yet)

It works \o/
It's still hacky so it needs more work.
And streaming sound (OGG music, sound from videos) is still missing.
This commit is contained in:
Daniel Gibson 2012-04-22 00:24:50 +00:00
parent 7e0a44825e
commit f4d5040a73
5 changed files with 86 additions and 47 deletions

View file

@ -134,9 +134,9 @@ client:
build/client/%.o: %.c
@echo '===> CC $<'
${Q}mkdir -p $(@D)
${Q}$(CC) -c $(CFLAGS) $(X11CFLAGS) $(SDLCFLAGS) $(INCLUDE) -o $@ $<
${Q}$(CC) -c $(CFLAGS) $(X11CFLAGS) $(SDLCFLAGS) $(INCLUDE) -DUSE_OPENAL -DDEFAULT_OPENAL_DRIVER='"libopenal.so.1"' -o $@ $<
release/quake2 : LDFLAGS += -lvorbis -lvorbisfile -logg -lz
release/quake2 : LDFLAGS += -lvorbis -lvorbisfile -logg -lz -lopenal
# ----------
@ -262,6 +262,8 @@ CLIENT_OBJS_ := \
src/client/menu/menu.o \
src/client/menu/qmenu.o \
src/client/menu/videomenu.o \
src/client/sound/qal_api.o \
src/client/sound/snd_al.o \
src/client/sound/snd_dma.o \
src/client/sound/snd_mem.o \
src/client/sound/snd_mix.o \

View file

@ -20,9 +20,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "common.h"
#include "../../common/header/common.h"
#include "header/qal_api.h"
#include <AL/alc.h>
#include <dlfcn.h>
#define QALC_IMP \
QAL( LPALCCREATECONTEXT, alcCreateContext ); \
@ -77,23 +78,26 @@ QALC_IMP
QAL_IMP
#undef QAL
Sys_FreeLibrary( handle );
//Sys_FreeLibrary( handle );
dlclose(handle);
handle = NULL;
al_driver->flags &= ~CVAR_SOUND;
al_device->flags &= ~CVAR_SOUND;
al_driver->flags &= ~CVAR_ARCHIVE;
al_device->flags &= ~CVAR_ARCHIVE;
}
qboolean QAL_Init( void ) {
al_driver = Cvar_Get( "al_driver", DEFAULT_OPENAL_DRIVER, CVAR_SOUND );
al_device = Cvar_Get( "al_device", "", CVAR_SOUND );
// DEFAULT_OPENAL_DRIVER is a define from the Makefile
al_driver = Cvar_Get( "al_driver", DEFAULT_OPENAL_DRIVER, CVAR_ARCHIVE );
al_device = Cvar_Get( "al_device", "", CVAR_ARCHIVE );
Sys_LoadLibrary( al_driver->string, NULL, &handle );
handle = dlopen( al_driver->string, RTLD_LAZY );
//Sys_LoadLibrary( al_driver->string, NULL, &handle );
if( !handle ) {
return false;
}
#define QAL(type,func) q##func = Sys_GetProcAddress( handle, #func );
#define QAL(type,func) q##func = dlsym( handle, #func );
QALC_IMP
QAL_IMP
#undef QAL
@ -118,8 +122,8 @@ QAL_IMP
}
Com_DPrintf( "ok\n" );
al_driver->flags |= CVAR_SOUND;
al_device->flags |= CVAR_SOUND;
al_driver->flags |= CVAR_ARCHIVE;
al_device->flags |= CVAR_ARCHIVE;
return true;

View file

@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../header/client.h"
#include "header/local.h"
#include "qal_api.h"
#include "header/qal_api.h"
// translates from AL coordinate system to quake
#define AL_UnpackVector(v) -v[1],v[2],-v[0]
@ -49,13 +49,13 @@ qboolean AL_Init( void ) {
int i;
if( !QAL_Init() ) {
Com_EPrintf( "OpenAL failed to initialize.\n" );
Com_Printf( "ERROR: OpenAL failed to initialize.\n" );
return false;
}
// check for linear distance extension
if( !qalIsExtensionPresent( "AL_EXT_LINEAR_DISTANCE" ) ) {
Com_EPrintf( "Required AL_EXT_LINEAR_DISTANCE extension is missing.\n" );
Com_Printf( "ERROR: Required AL_EXT_LINEAR_DISTANCE extension is missing.\n" );
goto fail;
}
@ -69,7 +69,7 @@ qboolean AL_Init( void ) {
}
if( i < MIN_CHANNELS ) {
Com_EPrintf( "Required at least %d sources, but got %d.\n", MIN_CHANNELS, i );
Com_Printf( "ERROR: Required at least %d sources, but got %d.\n", MIN_CHANNELS, i );
goto fail;
}
@ -116,7 +116,7 @@ sfxcache_t *AL_UploadSfx( sfx_t *s, wavinfo_t *s_info, byte *data ) {
}
// allocate placeholder sfxcache
sc = s->cache = S_Malloc( sizeof( *sc ) );
sc = s->cache = Z_TagMalloc(sizeof(*sc), 0); // FIXME: TAG_SOUND instead of 0 - this possibly leaks!
sc->length = s_info->samples * 1000 / s_info->rate; // in msec
sc->loopstart = s_info->loopstart;
sc->width = s_info->width;
@ -235,25 +235,25 @@ static void AL_AddLoopSounds( void ) {
int num;
entity_state_t *ent;
if( cls.state != ca_active || sv_paused->value || !s_ambient->value ) {
if( cls.state != ca_active || !s_ambient->value ) { // FIXME: sv_paused->value ||
return;
}
S_BuildSoundList( sounds );
for( i = 0; i < cl.frame.numEntities; i++ ) {
for( i = 0; i < cl.frame.num_entities; i++ ) {
if (!sounds[i])
continue;
sfx = S_SfxForHandle( cl.sound_precache[sounds[i]] );
sfx = cl.sound_precache[sounds[i]];
if (!sfx)
continue; // bad sound effect
sc = sfx->cache;
if (!sc)
continue;
num = ( cl.frame.firstEntity + i ) & (MAX_PARSE_ENTITIES-1);
ent = &cl.entityStates[num];
num = ( cl.frame.parse_entities + i ) & ( MAX_PARSE_ENTITIES - 1 );
ent = &cl_parse_entities [ num ];
ch = AL_FindLoopingSound( ent->number, sfx );
if( ch ) {
@ -291,6 +291,34 @@ static void AL_IssuePlaysounds( void ) {
break;
S_IssuePlaysound (ps);
}
// TODO: streaming sounds from s_rawsamples, equivalent to code below - see also ioq3's code
#if 0
/* clear the paint buffer */
if ( s_rawend < paintedtime )
{
memset( paintbuffer, 0, ( end - paintedtime ) * sizeof ( portable_samplepair_t ) );
}
else
{
/* copy from the streaming sound source */
int s;
int stop;
stop = ( end < s_rawend ) ? end : s_rawend;
for ( i = paintedtime; i < stop; i++ )
{
s = i & ( MAX_RAW_SAMPLES - 1 );
paintbuffer [ i - paintedtime ] = s_rawsamples [ s ];
}
for ( ; i < end; i++ )
{
paintbuffer [ i - paintedtime ].left = paintbuffer [ i - paintedtime ].right = 0;
}
}
#endif
}
void AL_Update( void ) {

View file

@ -216,7 +216,6 @@ S_Shutdown ( void )
memset( known_sfx, 0, sizeof ( known_sfx ) );
num_sfx = 0;
sound_started = SS_NOT;
OGG_Shutdown();
@ -228,6 +227,7 @@ S_Shutdown ( void )
#endif
SNDDMA_Shutdown();
sound_started = SS_NOT;
s_numchannels = 0;
Cmd_RemoveCommand( "soundlist" );
@ -983,7 +983,7 @@ S_AddLoopSounds ( void )
return;
}
if ( !cl.sound_prepped || !s_ambient->value || sv_paused->value )
if ( !cl.sound_prepped || !s_ambient->value ) // FIXME: || sv_paused->value )
{
return;
}
@ -1101,12 +1101,16 @@ S_RawSamples ( int samples, int rate, int width, int channels, byte *data, float
return;
}
// FIXME!!
if( sound_started == SS_OAL )
return;
if ( s_rawend < paintedtime )
{
s_rawend = paintedtime;
}
scale = (float) rate / dma.speed;
scale = (float) rate / dma.speed; // FIXME: dma.speed is not available (0) when using openal
intVolume = (int) (256 * volume);
if ( ( channels == 2 ) && ( width == 2 ) )

View file

@ -170,32 +170,33 @@ S_LoadSound ( sfx_t *s )
FS_FreeFile( data );
return ( NULL );
}
if (sound_started != SS_OAL) {
stepscale = (float) info.rate / dma.speed;
len = (int) ( info.samples / stepscale );
stepscale = (float) info.rate / dma.speed;
len = (int) ( info.samples / stepscale );
if ( ( info.samples == 0 ) || ( len == 0 ) )
{
Com_Printf( "WARNING: Zero length sound encountered: %s\n", s->name );
FS_FreeFile( data );
return ( NULL );
}
if ( ( info.samples == 0 ) || ( len == 0 ) )
{
Com_Printf( "WARNING: Zero length sound encountered: %s\n", s->name );
FS_FreeFile( data );
return ( NULL );
len = len * info.width * info.channels;
sc = s->cache = Z_Malloc( len + sizeof ( sfxcache_t ) );
if ( !sc )
{
FS_FreeFile( data );
return ( NULL );
}
sc->length = info.samples;
sc->loopstart = info.loopstart;
sc->speed = info.rate;
sc->width = info.width;
sc->stereo = info.channels;
}
len = len * info.width * info.channels;
sc = s->cache = Z_Malloc( len + sizeof ( sfxcache_t ) );
if ( !sc )
{
FS_FreeFile( data );
return ( NULL );
}
sc->length = info.samples;
sc->loopstart = info.loopstart;
sc->speed = info.rate;
sc->width = info.width;
sc->stereo = info.channels;
#if USE_OPENAL
if (sound_started == SS_OAL)
sc = AL_UploadSfx(s, &info, data + info.dataofs);