Re: [Flightgear-devel] [PATCH] Re: SEGV with ATIS

2005-11-12 Thread Erik Hofman

Pigeon wrote:

Figured out the problem with ATIS voice. It's in SimGear with the
code for OpenAL/Alut 1.1, whereby with in sample_openal.cxx,
alutCreateBufferFromFile() does not give us the raw sound data, and
ATCVoice depends on it, which leaves the data and the data size
uninitialized.


Good catch (and bad practice).


The patch used alutLoadMemoryFromFile() instead, pretty much the new
version of the old deprecated alutLoadWAVFile().


I've made a much clearer separation between loading the data and sending 
it to the sound driver. This prevents data to be loaded into 
main/sound-card memory when it's not needed.


Erik

___
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d


[Flightgear-devel] [PATCH] Re: SEGV with ATIS

2005-11-11 Thread Pigeon

Figured out the problem with ATIS voice. It's in SimGear with the
code for OpenAL/Alut 1.1, whereby with in sample_openal.cxx,
alutCreateBufferFromFile() does not give us the raw sound data, and
ATCVoice depends on it, which leaves the data and the data size
uninitialized.

The patch used alutLoadMemoryFromFile() instead, pretty much the new
version of the old deprecated alutLoadWAVFile().

Also someone might know a better, more portable way of converting an
ALfloat to an ALsizei. I'm simply casting it at the moment.


Thanks.


Pigeon.

Index: simgear/sound/sample_openal.cxx
===
RCS file: /var/cvs/SimGear-0.3/source/simgear/sound/sample_openal.cxx,v
retrieving revision 1.19
diff -u -r1.19 sample_openal.cxx
--- simgear/sound/sample_openal.cxx 25 Oct 2005 18:05:23 -  1.19
+++ simgear/sound/sample_openal.cxx 11 Nov 2005 22:27:50 -
@@ -67,6 +67,7 @@
 // constructor
 SGSoundSample::SGSoundSample( const char *path, const char *file,
   bool cleanup ) :
+size(0),
 data(NULL),
 buffer(0),
 source(0),
@@ -77,6 +78,8 @@
 loop(AL_FALSE),
 playing(false)
 {
+ALfloat freqf;   
+
 SGPath samplepath( path );
 if ( strlen(file) ) {
 samplepath.append( file );
@@ -105,11 +108,24 @@
 // Load the sample file
 #if defined(ALUT_API_MAJOR_VERSION)  ALUT_API_MAJOR_VERSION = 1
 
-  buffer = alutCreateBufferFromFile(samplepath.c_str());
-  if (buffer == AL_NONE) {
- ALenum error = alutGetError ();
- print_openal_error(constructor (alutCreateBufferFromFile));
- throw sg_exception(Failed to load wav file: +string(alutGetErrorString 
(error)));
+  data = alutLoadMemoryFromFile( samplepath.c_str(),
+   format, size, freqf );
+  if ( data == NULL ) {
+throw sg_exception(Failed to load wav file.);
+  }
+
+  freq = (ALsizei) freqf;
+
+  alBufferData( buffer, format, data, size, freq );
+  if ( print_openal_error(constructor (alBufferData)) ) {
+  free( data );
+  data = NULL;
+  throw sg_exception(Failed to buffer data.);
+  }
+  
+  if ( cleanup ) {
+  free( data );
+  data = NULL;
   }
 
 #else
___
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d