From df472fe0f5542d570feab42ce9ac1076a07419eb Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 24 Apr 2004 19:28:12 +0000 Subject: [PATCH] Changes to go along with small interface changes in simgear/sound/libsgsound (which is now written on top of OpenAL.) --- configure.ac | 14 +++++++++++++ src/ATC/AIPlane.cxx | 4 ++-- src/ATC/ATC.cxx | 4 ++-- src/ATC/ATCVoice.cxx | 16 +++++++++------ src/ATC/ATCVoice.hxx | 6 +++--- src/Cockpit/kr_87.cxx | 4 ++-- src/Cockpit/marker_beacon.cxx | 6 +++--- src/Cockpit/navcom.cxx | 6 +++--- src/Main/Makefile.am | 2 +- src/Main/fg_init.cxx | 37 +++++++++++++++++------------------ src/Main/fg_props.cxx | 2 +- src/Sound/beacon.cxx | 6 +++--- src/Sound/beacon.hxx | 14 ++++++------- src/Sound/fg_fx.cxx | 4 ++-- src/Sound/fg_fx.hxx | 4 ++-- src/Sound/morse.cxx | 13 ++++++------ src/Sound/morse.hxx | 11 ++++------- 17 files changed, 84 insertions(+), 69 deletions(-) diff --git a/configure.ac b/configure.ac index a16421615..8ab5c3f99 100644 --- a/configure.ac +++ b/configure.ac @@ -314,7 +314,21 @@ esac opengl_LIBS="$LIBS" LIBS="$base_LIBS" +dnl check for OpenAL libraries +case "${host}" in +*) + dnl default unix style machines + + AC_SEARCH_LIBS(alGenBuffers, openal) + ;; + +esac + +openal_LIBS="$LIBS" +LIBS="$base_LIBS" + AC_SUBST(base_LIBS) +AC_SUBST(openal_LIBS) AC_SUBST(opengl_LIBS) AC_SUBST(thread_LIBS) AC_SUBST(network_LIBS) diff --git a/src/ATC/AIPlane.cxx b/src/ATC/AIPlane.cxx index 32cea572b..a7f021c61 100644 --- a/src/ATC/AIPlane.cxx +++ b/src/ATC/AIPlane.cxx @@ -22,7 +22,7 @@ #include
#include #include -#include +#include #include #include SG_USING_STD(string); @@ -189,7 +189,7 @@ void FGAIPlane::Render(string refname, bool repeating) { int len; unsigned char* buf = vPtr->WriteMessage((char*)pending_transmission.c_str(), len, voice); if(voice) { - SGSimpleSound* simple = new SGSimpleSound(buf, len); + SGSoundSample* simple = new SGSoundSample(buf, len, 8000); // TODO - at the moment the volume is always set off comm1 // and can't be changed after the transmission has started. simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume")); diff --git a/src/ATC/ATC.cxx b/src/ATC/ATC.cxx index ca6e99e30..f17700c67 100644 --- a/src/ATC/ATC.cxx +++ b/src/ATC/ATC.cxx @@ -22,7 +22,7 @@ # include #endif -#include +#include #include
#include
@@ -223,7 +223,7 @@ void FGATC::Render(string msg, string refname, bool repeating) { int len; unsigned char* buf = vPtr->WriteMessage((char*)msg.c_str(), len, voice); if(voice) { - SGSimpleSound* simple = new SGSimpleSound(buf, len); + SGSoundSample* simple = new SGSoundSample(buf, len, 8000); // TODO - at the moment the volume is always set off comm1 // and can't be changed after the transmission has started. simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume")); diff --git a/src/ATC/ATCVoice.cxx b/src/ATC/ATCVoice.cxx index 71d9f5fc8..6751f93e8 100644 --- a/src/ATC/ATCVoice.cxx +++ b/src/ATC/ATCVoice.cxx @@ -37,21 +37,25 @@ FGATCVoice::FGATCVoice() { } FGATCVoice::~FGATCVoice() { - delete SoundData; + // delete SoundData; } // Load the two voice files - one containing the raw sound data (.wav) and one containing the word positions (.vce). // Return true if successful. bool FGATCVoice::LoadVoice(string voice) { + // FIXME CLO: disabled to try to see if this is causign problemcs + // return false; + ifstream fin; SGPath path = globals->get_fg_root(); - string soundPath = "ATC/" + voice + ".wav"; - path.append(soundPath); + path.append( "ATC" ); + + string file = voice + ".wav"; - SoundData = new slSample( (char*)path.c_str() ); - rawDataSize = SoundData->getLength(); - rawSoundData = (char*)SoundData->getBuffer(); + SoundData = new SGSoundSample( path.c_str(), file.c_str() ); + rawDataSize = SoundData->get_size(); + rawSoundData = SoundData->get_data(); path = globals->get_fg_root(); string wordPath = "ATC/" + voice + ".vce"; diff --git a/src/ATC/ATCVoice.hxx b/src/ATC/ATCVoice.hxx index 657e5ecb2..9d9fb7d92 100644 --- a/src/ATC/ATCVoice.hxx +++ b/src/ATC/ATCVoice.hxx @@ -21,8 +21,6 @@ #ifndef _FG_ATC_VOICE #define _FG_ATC_VOICE -#include - #include #if defined( SG_HAVE_STD_INCLUDES ) || defined( __BORLANDC__ ) || (__APPLE__) @@ -37,6 +35,8 @@ #include #include +#include + SG_USING_STD(map); SG_USING_STD(list); SG_USING_STD(string); @@ -77,7 +77,7 @@ private: // the sound and word position data char* rawSoundData; unsigned int rawDataSize; - slSample* SoundData; + SGSoundSample *SoundData; // A map of words vs. byte position and length in rawSoundData atc_word_map_type wordMap; diff --git a/src/Cockpit/kr_87.cxx b/src/Cockpit/kr_87.cxx index dc84a4592..81c0224c0 100644 --- a/src/Cockpit/kr_87.cxx +++ b/src/Cockpit/kr_87.cxx @@ -444,7 +444,7 @@ void FGKR_87::update( double dt ) { // play station ident via audio system if on + ant mode, // otherwise turn it off if ( vol_btn >= 0.01 && audio_btn ) { - SGSimpleSound *sound; + SGSoundSample *sound; sound = globals->get_soundmgr()->find( "adf-ident" ); if ( sound != NULL ) { if ( !adf_btn ) { @@ -513,7 +513,7 @@ void FGKR_87::search() { if ( globals->get_soundmgr()->exists( "adf-ident" ) ) { globals->get_soundmgr()->remove( "adf-ident" ); } - SGSimpleSound *sound; + SGSoundSample *sound; sound = morse.make_ident( trans_ident, LO_FREQUENCY ); sound->set_volume( 0.3 ); globals->get_soundmgr()->add( sound, "adf-ident" ); diff --git a/src/Cockpit/marker_beacon.cxx b/src/Cockpit/marker_beacon.cxx index 88e3e0370..efe73b664 100644 --- a/src/Cockpit/marker_beacon.cxx +++ b/src/Cockpit/marker_beacon.cxx @@ -192,7 +192,7 @@ void FGMarkerBeacon::search() // cout << "OUTER MARKER" << endl; if ( last_beacon != FGMkrBeacon::OUTER ) { if ( ! globals->get_soundmgr()->exists( "outer-marker" ) ) { - SGSimpleSound *sound = beacon.get_outer(); + SGSoundSample *sound = beacon.get_outer(); sound->set_volume( 0.3 ); globals->get_soundmgr()->add( sound, "outer-marker" ); } @@ -209,7 +209,7 @@ void FGMarkerBeacon::search() // cout << "MIDDLE MARKER" << endl; if ( last_beacon != FGMkrBeacon::MIDDLE ) { if ( ! globals->get_soundmgr()->exists( "middle-marker" ) ) { - SGSimpleSound *sound = beacon.get_middle(); + SGSoundSample *sound = beacon.get_middle(); sound->set_volume( 0.3 ); globals->get_soundmgr()->add( sound, "middle-marker" ); } @@ -226,7 +226,7 @@ void FGMarkerBeacon::search() // cout << "INNER MARKER" << endl; if ( last_beacon != FGMkrBeacon::INNER ) { if ( ! globals->get_soundmgr()->exists( "inner-marker" ) ) { - SGSimpleSound *sound = beacon.get_inner(); + SGSoundSample *sound = beacon.get_inner(); sound->set_volume( 0.3 ); globals->get_soundmgr()->add( sound, "inner-marker" ); } diff --git a/src/Cockpit/navcom.cxx b/src/Cockpit/navcom.cxx index 03fae8220..929f81191 100644 --- a/src/Cockpit/navcom.cxx +++ b/src/Cockpit/navcom.cxx @@ -541,7 +541,7 @@ FGNavCom::update(double dt) if ( power_btn && (bus_power->getDoubleValue() > 1.0) && nav_ident_btn && audio_btn ) { - SGSimpleSound *sound; + SGSoundSample *sound; sound = globals->get_soundmgr()->find( nav_fx_name ); if ( sound != NULL ) { sound->set_volume( nav_vol_btn ); @@ -653,7 +653,7 @@ void FGNavCom::search() if ( globals->get_soundmgr()->exists( nav_fx_name ) ) { globals->get_soundmgr()->remove( nav_fx_name ); } - SGSimpleSound *sound; + SGSoundSample *sound; sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY ); sound->set_volume( 0.3 ); globals->get_soundmgr()->add( sound, nav_fx_name ); @@ -703,7 +703,7 @@ void FGNavCom::search() if ( globals->get_soundmgr()->exists( nav_fx_name ) ) { globals->get_soundmgr()->remove( nav_fx_name ); } - SGSimpleSound *sound; + SGSoundSample *sound; sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY ); sound->set_volume( 0.3 ); if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) { diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index 774999354..f3f801463 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -94,7 +94,7 @@ fgfs_LDADD = \ $(network_LIBS) \ -lz \ $(opengl_LIBS) \ - $(audio_LIBS) + $(openal_LIBS) metar_SOURCES = metar_main.cxx diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 6e1197735..daf286844 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1622,6 +1622,24 @@ bool fgInitSubsystems() { } #endif +#ifdef ENABLE_AUDIO_SUPPORT + //////////////////////////////////////////////////////////////////// + // Initialize the sound subsystem. + //////////////////////////////////////////////////////////////////// + + globals->set_soundmgr(new SGSoundMgr); + globals->get_soundmgr()->init(); + globals->get_soundmgr()->bind(); + + + //////////////////////////////////////////////////////////////////// + // Initialize the sound-effects subsystem. + //////////////////////////////////////////////////////////////////// + + globals->add_subsystem("fx", new FGFX); + +#endif + //////////////////////////////////////////////////////////////////// // Initialise ATC display system //////////////////////////////////////////////////////////////////// @@ -1646,7 +1664,6 @@ bool fgInitSubsystems() { globals->set_AI_mgr(new FGAIMgr); globals->get_AI_mgr()->init(); - //////////////////////////////////////////////////////////////////// // Initialise the AI Model Manager //////////////////////////////////////////////////////////////////// @@ -1655,24 +1672,6 @@ bool fgInitSubsystems() { globals->add_subsystem("ai_model", new FGAIManager); -#ifdef ENABLE_AUDIO_SUPPORT - //////////////////////////////////////////////////////////////////// - // Initialize the sound subsystem. - //////////////////////////////////////////////////////////////////// - - globals->set_soundmgr(new SGSoundMgr); - globals->get_soundmgr()->init(); - globals->get_soundmgr()->bind(); - - - //////////////////////////////////////////////////////////////////// - // Initialize the sound-effects subsystem. - //////////////////////////////////////////////////////////////////// - - globals->add_subsystem("fx", new FGFX); - -#endif - globals->add_subsystem("instrumentation", new FGInstrumentMgr); globals->add_subsystem("systems", new FGSystemMgr); diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index 66a9086fb..2c93ad36c 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include STL_IOSTREAM diff --git a/src/Sound/beacon.cxx b/src/Sound/beacon.cxx index 3da3843f9..6fad631e5 100644 --- a/src/Sound/beacon.cxx +++ b/src/Sound/beacon.cxx @@ -51,7 +51,7 @@ bool FGBeacon::init() { ptr += INNER_DIT_LEN; } - inner = new SGSimpleSound( inner_buf, INNER_SIZE ); + inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND ); // Make middle marker beacon sound len= (int)(MIDDLE_DIT_LEN / 2.0 ); @@ -69,7 +69,7 @@ bool FGBeacon::init() { ptr += MIDDLE_DIT_LEN; memcpy( ptr, middle_dah, MIDDLE_DAH_LEN ); - middle = new SGSimpleSound( middle_buf, MIDDLE_SIZE ); + middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND ); // Make outer marker beacon sound len= (int)(OUTER_DAH_LEN * 3.0 / 4.0 ); @@ -82,7 +82,7 @@ bool FGBeacon::init() { ptr += OUTER_DAH_LEN; memcpy( ptr, outer_dah, OUTER_DAH_LEN ); - outer = new SGSimpleSound( outer_buf, OUTER_SIZE ); + outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND ); return true; } diff --git a/src/Sound/beacon.hxx b/src/Sound/beacon.hxx index 3b9a6e3c0..6d6807622 100644 --- a/src/Sound/beacon.hxx +++ b/src/Sound/beacon.hxx @@ -31,7 +31,7 @@ #endif #include -#include +#include #include #include @@ -100,9 +100,9 @@ private: unsigned char middle_buf[ MIDDLE_SIZE ] ; unsigned char outer_buf[ OUTER_SIZE ] ; - SGSimpleSound *inner; - SGSimpleSound *middle; - SGSimpleSound *outer; + SGSoundSample *inner; + SGSoundSample *middle; + SGSoundSample *outer; public: @@ -112,9 +112,9 @@ public: // allocate and initialize sound samples bool init(); - SGSimpleSound *get_inner() { return inner; } - SGSimpleSound *get_middle() { return middle; } - SGSimpleSound *get_outer() { return outer; } + SGSoundSample *get_inner() { return inner; } + SGSoundSample *get_middle() { return middle; } + SGSoundSample *get_outer() { return outer; } }; diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 93e8b779b..6b1a16eb3 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -32,7 +32,7 @@ #endif #include #include -#include +#include #include
@@ -76,7 +76,7 @@ FGFX::init() node = root.getNode("fx"); for (i = 0; i < node->nChildren(); i++) { - SGSound *sound = new SGSound(); + SGXmlSound *sound = new SGXmlSound(); sound->init(globals->get_props(), node->getChild(i), globals->get_soundmgr(), globals->get_fg_root()); diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index 0cc29dc39..5c43db42d 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -26,7 +26,7 @@ #include -class SGSound; +class SGXmlSound; /** * Generator for FlightGear sound effects. @@ -51,7 +51,7 @@ public: private: - vector _sound; + vector _sound; }; diff --git a/src/Sound/morse.cxx b/src/Sound/morse.cxx index aaec7f50e..ef0b43fa7 100644 --- a/src/Sound/morse.cxx +++ b/src/Sound/morse.cxx @@ -87,7 +87,7 @@ void make_tone( unsigned char *buf, int freq, int i, j; for ( i = 0; i < trans_len; ++i ) { - float level = ( sin( (double) i * 2.0 * SGD_PI / (8000.0 / freq) ) ) + float level = ( sin( (double) i * 2.0 * SGD_PI / (BYTES_PER_SECOND / freq) ) ) * ((double)i / trans_len) / 2.0 + 0.5; /* Convert to unsigned byte */ @@ -95,7 +95,7 @@ void make_tone( unsigned char *buf, int freq, } for ( i = trans_len; i < len - trans_len; ++i ) { - float level = ( sin( (double) i * 2.0 * SGD_PI / (8000.0 / freq) ) ) + float level = ( sin( (double) i * 2.0 * SGD_PI / (BYTES_PER_SECOND / freq) ) ) / 2.0 + 0.5; /* Convert to unsigned byte */ @@ -103,7 +103,7 @@ void make_tone( unsigned char *buf, int freq, } j = trans_len; for ( i = len - trans_len; i < len; ++i ) { - float level = ( sin( (double) i * 2.0 * SGD_PI / (8000.0 / freq) ) ) + float level = ( sin( (double) i * 2.0 * SGD_PI / (BYTES_PER_SECOND / freq) ) ) * ((double)j / trans_len) / 2.0 + 0.5; --j; @@ -165,8 +165,8 @@ bool FGMorse::cust_init(const int freq ) { } -// make a SGSimpleSound morse code transmission for the specified string -SGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) { +// make a SGSoundSample morse code transmission for the specified string +SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) { char *idptr = (char *)id.c_str(); int length = 0; @@ -260,7 +260,8 @@ SGSimpleSound *FGMorse::make_ident( const string& id, const int freq ) { buf_ptr += SPACE_SIZE; // 4. create the simple sound and return - SGSimpleSound *sample = new SGSimpleSound( buffer, length ); + SGSoundSample *sample = new SGSoundSample( buffer, length, + BYTES_PER_SECOND ); return sample; } diff --git a/src/Sound/morse.hxx b/src/Sound/morse.hxx index 6166e7475..bd0f1aec1 100644 --- a/src/Sound/morse.hxx +++ b/src/Sound/morse.hxx @@ -29,10 +29,7 @@ #endif #include -#include - -#include -#include +#include // Quoting from http://www.kluft.com/~ikluft/ham/morse-intro.html by @@ -88,7 +85,7 @@ static const char DA = '2'; static const char DAH = '2'; static const char end = '0'; -static const int BYTES_PER_SECOND = 8000; +static const int BYTES_PER_SECOND = 22050; // static const int BEAT_LENGTH = 240; // milleseconds (5 wpm) static const int BEAT_LENGTH = 92; // milleseconds (13 wpm) static const int TRANSITION_BYTES = (int)(0.005 * BYTES_PER_SECOND); @@ -124,8 +121,8 @@ public: bool init(); // make a SimpleSound morse code transmission for the specified string - SGSimpleSound *make_ident( const string& id, - const int freq = LO_FREQUENCY ); + SGSoundSample *make_ident( const string& id, + const int freq = LO_FREQUENCY ); };