--- vegastrike-0.4.3/src/aldrv/al_init.cpp.alut 2004-05-20 03:04:26.000000000 +0200 +++ vegastrike-0.4.3/src/aldrv/al_init.cpp 2007-03-23 16:04:13.000000000 +0100 @@ -144,6 +144,9 @@ bool AUDInit () { g_game.sound_enabled = false; #ifdef HAVE_AL + /* Initialize Alut, this must always be done otherwise the sample loading + code segfaults */ + alutInitWithoutContext(NULL, NULL); usedoppler = XMLSupport::parse_bool (vs_config->getVariable ("audio","Doppler","false")); usepositional = XMLSupport::parse_bool (vs_config->getVariable ("audio","Positional","true")); --- vegastrike-0.4.3/src/aldrv/al_sound.cpp.alut 2005-01-08 02:25:32.000000000 +0100 +++ vegastrike-0.4.3/src/aldrv/al_sound.cpp 2007-03-23 16:26:49.000000000 +0100 @@ -37,216 +37,10 @@ #include #include #ifdef HAVE_AL -#ifdef HAVE_OGG - -#include -#endif std::vector dirtysounds; std::vector sounds; std::vector buffers; -static void convertToLittle(unsigned int tmp, char * data){ - data[0]=(char)(tmp%256); - data[1]=(char)((tmp/256)%256); - data[2]=(char)((tmp/65536)%256); - data[3]=(char)((tmp/65536)/256); -} -#ifdef HAVE_OGG -struct fake_file{ - char * data; - size_t size; - size_t loc; -}; -size_t mem_read(void * ptr, size_t size, size_t nmemb, void * datasource) { - fake_file * fp = (fake_file*)datasource; - if (fp->loc+size>fp->size) { - size_t tmp=fp->size-fp->loc; - if (tmp) - memcpy (ptr,fp->data+fp->loc,tmp); - fp->loc=fp->size; - return tmp; - }else { - memcpy(ptr,fp->data+fp->loc,size); - fp->loc+=size; - return size; - } -} -int mem_close(void*) { - return 0; -} - -long mem_tell (void *datasource){ - fake_file * fp = (fake_file*)datasource; - return (long)fp->loc; -} -int cant_seek (void * datasource, ogg_int64_t offset, int whence) { - return -1; -} -int mem_seek (void * datasource, ogg_int64_t offset, int whence) { - fake_file * fp = (fake_file*)datasource; - if (whence==SEEK_END) { - if (offset<0) { - if (fp->size<(size_t)-offset) { - return -1; - }else { - fp->loc = fp->size+offset; - return 0; - } - }else if (offset==0) { - fp->loc=fp->size; - }else return -1; - }else if (whence==SEEK_CUR) { - if (offset<0) { - if (fp->loc<(size_t)-offset) - return -1; - else { - fp->loc+=offset; - return 0; - } - }else { - if (fp->loc+offset>fp->size) { - return -1; - }else { - fp->loc+=offset; - return 0; - } - } - }else if (whence==SEEK_SET) { - if (offset>fp->size) - return -1; - fp->loc = offset; - return 0; - } - return -1; -} -#endif -static void ConvertFormat (vector& ogg ) { - vector converted; - - if (ogg.size()>4) { - if (ogg[0]=='O'&&ogg[1]=='g'&&ogg[2]=='g'&&ogg[3]=='S') { -#ifdef HAVE_OGG - OggVorbis_File vf; - ov_callbacks callbacks; - vorbis_info *info; - int bitstream = -1; - long samplesize; - long samples; - int read, to_read; - int must_close = 1; - int was_error = 1; - //FILE * tmpf=tmpfile(); - //fwrite(&ogg[0],ogg.size(),1,tmpf); - //fseek(tmpf,0,SEEK_SET); - fake_file ff; - ff.data=&ogg[0]; - ff.loc=0; - ff.size=ogg.size(); - callbacks.read_func=&mem_read; - callbacks.seek_func=&mem_seek; - callbacks.close_func=&mem_close; - callbacks.tell_func=&mem_tell; - if (ov_open_callbacks(&ff,&vf,NULL,0,callbacks) ){ - ogg.clear(); - }else { - int bigendian=0; - long bytesread=0; - vorbis_info *info=ov_info(&vf,-1); - //ogg_int64_t totalsize=ov_pcm_total(&vf,-1); - //long num_streams=ov_streams(&vf); - const int segmentsize=16384; - const int samples=16; - converted.push_back('R'); - converted.push_back('I'); - converted.push_back('F'); - converted.push_back('F'); - converted.push_back(0); - converted.push_back(0); - converted.push_back(0); - converted.push_back(0);//fill in with weight; - converted.push_back('W'); - converted.push_back('A'); - converted.push_back('V'); - converted.push_back('E'); - converted.push_back('f'); - converted.push_back('m'); - converted.push_back('t'); - converted.push_back(' '); - - converted.push_back(18);//size of header (16 bytes) - converted.push_back(0); - converted.push_back(0); - converted.push_back(0); - - converted.push_back(1);//compression code - converted.push_back(0); - - converted.push_back((char)(info->channels%256));//num channels; - converted.push_back((char)(info->channels/256)); - - converted.push_back(0);//sample rate - converted.push_back(0);//sample rate - converted.push_back(0);//sample rate - converted.push_back(0);//sample rate - convertToLittle(info->rate,&converted[converted.size()-4]); - - long byterate = info->rate*info->channels*samples/8; - converted.push_back(0);//bytes per second rate - converted.push_back(0); - converted.push_back(0); - converted.push_back(0); - convertToLittle(byterate,&converted[converted.size()-4]); - - converted.push_back((char)((info->channels*samples/8)%256));//num_channels*16 bits/8 - converted.push_back((char)((info->channels*samples/8)/256)); - - converted.push_back(samples);// 16 bit samples - converted.push_back(0); - converted.push_back(0); - converted.push_back(0); - - - // PCM header - converted.push_back('d'); - converted.push_back('a'); - converted.push_back('t'); - converted.push_back('a'); - - - converted.push_back(0); - converted.push_back(0); - converted.push_back(0); - converted.push_back(0); - ogg_int64_t pcmsizestart=converted.size(); - converted.resize(converted.size()+segmentsize); - int signedvalue=1; - int bitstream=0; - while ((bytesread=ov_read(&vf,&converted[converted.size()-segmentsize], segmentsize, 0, samples/8, signedvalue, &bitstream))>0){ - if (bytesreadOk) return -1; wavbuf = (ALuint *) malloc (sizeof (ALuint)); - alGenBuffers (1,wavbuf); -#ifdef SOUND_DEBUG - printf ("Sound %s created with and alBuffer %d\n",s.c_str(),*wavbuf); -#endif - ALsizei size; - ALsizei freq; - void *wave; - ALboolean looping; - ALboolean err=AL_TRUE; vector dat; dat.resize(f.Size()); f.Read( &dat[0], f.Size()); - ConvertFormat(dat); - if (dat.size()==0)//conversion messed up + f.Close(); + *wavbuf = alutCreateBufferFromFileImage(&dat[0], dat.size()); + if (*wavbuf == AL_NONE) + { + ALint err = alutGetError(); + if (err != ALUT_ERROR_NO_CURRENT_CONTEXT) + printf("loading: %s failed: %s\n", s.c_str(), + alutGetErrorString(err)); return -1; -#ifndef WIN32 -#ifdef __APPLE__ - ALint format; - // MAC OS X - err = false; - if( error<=Ok) - err=MacFixedLoadWAVFile( &dat[0], &format, &wave, &size, &freq); -#else - // LINUX - ALsizei format; - alutLoadWAVMemory((ALbyte *)&dat[0], &format, &wave, &size, &freq, &looping); -#endif -#else - ALint format; - // WIN32 - alutLoadWAVMemory(&dat[0], (int*)&format, &wave, &size, &freq, &looping); -#endif - - if(err == AL_FALSE) - { - alDeleteBuffers (1,wavbuf); - free (wavbuf); - return -1; - } - alBufferData( *wavbuf, format, wave, size, freq ); - alutUnloadWAV(format,wave,size,freq); + } + if (!music) { soundHash.Put (hashname,wavbuf); buffers.push_back (*wavbuf); } - f.Close(); } return LoadSound (*wavbuf,LOOP); } @@ -372,7 +138,7 @@ } int AUDCreateSoundMP3 (const std::string &s, const bool music, const bool LOOP){ -#ifdef HAVE_AL +#if 0 /* was #ifdef HAVE_AL, but we have no mp3 support in Fedora's alut */ if ((g_game.sound_enabled&&!music)||(g_game.music_enabled&&music)) { VSFile f; VSError error = f.OpenReadOnly( s.c_str(), SoundFile);