RelativePath="..\..\..\src\Sound\sample_queue.hxx"\r
>\r
</File>\r
+ <File\r
+ RelativePath="..\..\..\src\Sound\soundgenerator.cxx"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath="..\..\..\src\Sound\soundgenerator.hxx"\r
+ >\r
+ </File>\r
<File\r
RelativePath="..\..\..\src\Sound\voice.cxx"\r
>\r
#include <Navaids/navlist.hxx>
#include "adf.hxx"
+#include <Sound/morse.hxx>
+
#include <iostream>
#include <string>
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
- morse.init();
-
std::ostringstream temp;
temp << _name << _num;
_adf_ident = temp.str();
}
SGSoundSample *sound;
- sound = morse.make_ident( ident, LO_FREQUENCY );
+ sound = FGMorse::instance()->make_ident( ident, LO_FREQUENCY );
sound->set_volume(_last_volume = 0);
_sgr->add( sound, _adf_ident );
#include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
-#include <Sound/morse.hxx>
using std::string;
SGVec3d _transmitter_cart;
double _transmitter_range_nm;
- FGMorse morse;
int _ident_count;
time_t _last_ident_time;
float _last_volume;
#include "kr_87.hxx"
+#include <Sound/morse.hxx>
#include <string>
using std::string;
SGSoundMgr *smgr = globals->get_soundmgr();
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
- morse.init();
}
_sgr->remove( "adf-ident" );
}
SGSoundSample *sound;
- sound = morse.make_ident( trans_ident, LO_FREQUENCY );
+ sound = FGMorse::instance()->make_ident( trans_ident, LO_FREQUENCY );
sound->set_volume( 0.3 );
_sgr->add( sound, "adf-ident" );
#include <simgear/timing/timestamp.hxx>
#include <Navaids/navlist.hxx>
-#include <Sound/morse.hxx>
class SGSampleGroup;
class FGKR_87 : public SGSubsystem
{
- FGMorse morse;
-
SGPropertyNode_ptr lon_node;
SGPropertyNode_ptr lat_node;
SGPropertyNode_ptr alt_node;
#include <Navaids/navlist.hxx>
#include "marker_beacon.hxx"
+#include <Sound/beacon.hxx>
#include <string>
using std::string;
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
- morse.init();
- beacon.init();
blink.stamp();
outer_marker = middle_marker = inner_marker = false;
// cout << "OUTER MARKER" << endl;
if ( last_beacon != OUTER ) {
if ( ! _sgr->exists( current_sound_name ) ) {
- SGSoundSample *sound = beacon.get_outer();
+ SGSoundSample *sound = FGBeacon::instance()->get_outer();
if ( sound ) {
_sgr->add( sound, current_sound_name );
}
// cout << "MIDDLE MARKER" << endl;
if ( last_beacon != MIDDLE ) {
if ( ! _sgr->exists( current_sound_name ) ) {
- SGSoundSample *sound = beacon.get_middle();
+ SGSoundSample *sound = FGBeacon::instance()->get_middle();
if ( sound ) {
_sgr->add( sound, current_sound_name );
}
// cout << "INNER MARKER" << endl;
if ( last_beacon != INNER ) {
if ( ! _sgr->exists( current_sound_name ) ) {
- SGSoundSample *sound = beacon.get_inner();
+ SGSoundSample *sound = FGBeacon::instance()->get_inner();
if ( sound ) {
_sgr->add( sound, current_sound_name );
}
#include <simgear/math/interpolater.hxx>
#include <simgear/timing/timestamp.hxx>
-#include <Sound/beacon.hxx>
-#include <Sound/morse.hxx>
-
class SGSampleGroup;
class FGMarkerBeacon : public SGSubsystem
{
- FGBeacon beacon;
- FGMorse morse;
-
SGInterpTable *term_tbl;
SGInterpTable *low_tbl;
SGInterpTable *high_tbl;
#include <Airports/runways.hxx>
#include <Navaids/navlist.hxx>
#include <Main/util.hxx>
+#include <Sound/morse.hxx>
using std::string;
_sgr = smgr->find("avionics", true);
_sgr->tie_to_listener();
- morse.init();
-
SGPropertyNode* node = _radio_node.get();
bus_power_node =
fgGetNode(("/systems/electrical/outputs/" + _name).c_str(), true);
try {
string trans_ident(_navaid->get_trans_ident());
- SGSoundSample* sound = morse.make_ident(trans_ident, LO_FREQUENCY);
+ SGSoundSample* sound = FGMorse::instance()->make_ident(trans_ident, LO_FREQUENCY);
sound->set_volume( 0.3 );
if (!_sgr->add( sound, nav_fx_name )) {
SG_LOG(SG_COCKPIT, SG_WARN, "Failed to add v1-vor-ident sound");
_sgr->remove( dme_fx_name );
}
- sound = morse.make_ident( trans_ident, HI_FREQUENCY );
+ sound = FGMorse::instance()->make_ident( trans_ident, HI_FREQUENCY );
sound->set_volume( 0.3 );
_sgr->add( sound, dme_fx_name );
#include <Main/fg_props.hxx>
-#include "Sound/morse.hxx"
#include <simgear/compiler.h>
#include <simgear/structure/subsystem_mgr.hxx>
class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener
{
- FGMorse morse;
-
SGInterpTable *term_tbl;
SGInterpTable *low_tbl;
SGInterpTable *high_tbl;
include(FlightGearComponent)
set(SOURCES
+ soundgenerator.cxx
beacon.cxx
fg_fx.cxx
morse.cxx
)
set(HEADERS
+ soundgenerator.hxx
beacon.hxx
fg_fx.hxx
morse.hxx
voiceplayer.hxx
)
-flightgear_component(Sound "${SOURCES}" "${HEADERS}")
\ No newline at end of file
+flightgear_component(Sound "${SOURCES}" "${HEADERS}")
noinst_LIBRARIES = libSound.a
libSound_a_SOURCES = \
+ soundgenerator.cxx soundgenerator.hxx \
beacon.cxx beacon.hxx \
fg_fx.cxx fg_fx.hxx \
morse.cxx morse.hxx \
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
-// $Id$
-
#include <stdlib.h>
#include <cstring>
return true;
}
+
+FGBeacon * FGBeacon::_instance = NULL;\r
+\r
+FGBeacon * FGBeacon::instance()\r
+{\r
+ if( _instance == NULL ) {\r
+ _instance = new FGBeacon();\r
+ _instance->init();\r
+ }\r
+ return _instance;\r
+}\r
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
-// $Id$
-
#ifndef _BEACON_HXX
#define _BEACON_HXX
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include "soundgenerator.hxx"
#include <simgear/compiler.h>
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
-#include "morse.hxx"
-
-
// Quoting from http://www.smartregs.com/data/sa326.htm
// Smart REGS Glossary - marker beacon
//
// (See instrument landing system) (Refer to AIM.)
-static const int INNER_FREQ = 3000;
-static const int MIDDLE_FREQ = 1300;
-static const int OUTER_FREQ = 400;
-
-static const int INNER_SIZE = BYTES_PER_SECOND;
-static const int MIDDLE_SIZE = (int)(BYTES_PER_SECOND * 60 / 95 );
-static const int OUTER_SIZE = BYTES_PER_SECOND;
-
-static const int INNER_DIT_LEN = (int)(BYTES_PER_SECOND / 6.0);
-static const int MIDDLE_DIT_LEN = (int)(MIDDLE_SIZE / 3.0);
-static const int MIDDLE_DAH_LEN = (int)(MIDDLE_SIZE * 2 / 3.0);
-static const int OUTER_DAH_LEN = (int)(BYTES_PER_SECOND / 2.0);
-
// manages everything we need to know for an individual sound sample
-class FGBeacon {
+class FGBeacon : public FGSoundGenerator {
private:
+ static const int INNER_FREQ = 3000;
+ static const int MIDDLE_FREQ = 1300;
+ static const int OUTER_FREQ = 400;
+
+ static const int INNER_SIZE = BYTES_PER_SECOND;
+ static const int MIDDLE_SIZE = (int)(BYTES_PER_SECOND * 60 / 95 );
+ static const int OUTER_SIZE = BYTES_PER_SECOND;
+
+ static const int INNER_DIT_LEN = (int)(BYTES_PER_SECOND / 6.0);
+ static const int MIDDLE_DIT_LEN = (int)(MIDDLE_SIZE / 3.0);
+ static const int MIDDLE_DAH_LEN = (int)(MIDDLE_SIZE * 2 / 3.0);
+ static const int OUTER_DAH_LEN = (int)(BYTES_PER_SECOND / 2.0);
SGSharedPtr<SGSoundSample> inner;
SGSharedPtr<SGSoundSample> middle;
SGSharedPtr<SGSoundSample> outer;
+ // allocate and initialize sound samples
+ bool init();
+ static FGBeacon * _instance;
public:
FGBeacon();
~FGBeacon();
-
- // allocate and initialize sound samples
- bool init();
+ static FGBeacon * instance();
SGSoundSample *get_inner() { return inner; }
SGSoundSample *get_middle() { return middle; }
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
-// $Id$
#include <simgear/constants.h>
}
-// Make a tone of specified freq and total_len with trans_len ramp in
-// and out and only the first len bytes with sound, the rest with
-// silence
-void make_tone( unsigned char *buf, int freq,
- int len, int total_len, int trans_len )
-{
- int i, j;
-
- for ( i = 0; i < trans_len; ++i ) {
- float level = ( sin( (double) i * SGD_2PI / (BYTES_PER_SECOND / freq) ) )
- * ((double)i / trans_len) / 2.0 + 0.5;
-
- /* Convert to unsigned byte */
- buf[ i ] = (unsigned char) ( level * 255.0 ) ;
- }
-
- for ( i = trans_len; i < len - trans_len; ++i ) {
- float level = ( sin( (double) i * SGD_2PI / (BYTES_PER_SECOND / freq) ) )
- / 2.0 + 0.5;
-
- /* Convert to unsigned byte */
- buf[ i ] = (unsigned char) ( level * 255.0 ) ;
- }
- j = trans_len;
- for ( i = len - trans_len; i < len; ++i ) {
- float level = ( sin( (double) i * SGD_2PI / (BYTES_PER_SECOND / freq) ) )
- * ((double)j / trans_len) / 2.0 + 0.5;
- --j;
-
- /* Convert to unsigned byte */
- buf[ i ] = (unsigned char) ( level * 255.0 ) ;
- }
- for ( i = len; i < total_len; ++i ) {
- buf[ i ] = (unsigned char) ( 0.5 * 255.0 ) ;
- }
-}
-
-
// allocate and initialize sound samples
bool FGMorse::init() {
// Make Low DIT
return sample;
}
+
+FGMorse * FGMorse::_instance = NULL;
+
+FGMorse * FGMorse::instance()
+{
+ if( _instance == NULL ) {
+ _instance = new FGMorse();
+ _instance->init();
+ }
+ return _instance;
+}
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
-// $Id$
#ifndef _MORSE_HXX
#define _MORSE_HXX
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
+#include "soundgenerator.hxx"
#include <simgear/compiler.h>
#include <simgear/sound/soundmgr_openal.hxx>
static const int HI_FREQUENCY = 1350; // AIM 1-1-7 (f) specified in Hz
// manages everything we need to know for an individual sound sample
-class FGMorse {
+class FGMorse : public FGSoundGenerator {
private:
unsigned char cust_dit[ DIT_SIZE ] ;
unsigned char cust_dah[ DAH_SIZE ] ;
+ static FGMorse * _instance;
+
bool cust_init( const int freq );
+ // allocate and initialize sound samples
+ bool init();
public:
FGMorse();
~FGMorse();
- // allocate and initialize sound samples
- bool init();
+ static FGMorse * instance();
// make a SimpleSound morse code transmission for the specified string
SGSoundSample *make_ident( const string& id,
};
-/**
- * \relates FGMorse
- * Make a tone of specified freq and total_len with trans_len ramp in
- * and out and only the first len bytes with sound, the rest with
- * silence.
- * @param buf unsigned char pointer to sound buffer
- * @param freq desired frequency of tone
- * @param len length of tone within sound
- * @param total_len total length of sound (anything more than len is padded
- * with silence.
- * @param trans_len length of ramp up and ramp down to avoid audio "pop"
- */
-void make_tone( unsigned char *buf, int freq,
- int len, int total_len, int trans_len );
#endif // _MORSE_HXX
--- /dev/null
+// soundgenerator.cxx -- simple sound generation \r
+//\r
+// Written by Curtis Olson, started March 2001.\r
+//\r
+// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt\r
+//\r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License as\r
+// published by the Free Software Foundation; either version 2 of the\r
+// License, or (at your option) any later version.\r
+//\r
+// This program is distributed in the hope that it will be useful, but\r
+// WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+//\r
+\r
+#include "soundgenerator.hxx"\r
+#include <simgear/constants.h>\r
+\r
+FGSoundGenerator::~FGSoundGenerator()\r
+{\r
+}\r
+\r
+// Make a tone of specified freq and total_len with trans_len ramp in\r
+// and out and only the first len bytes with sound, the rest with\r
+// silence\r
+void FGSoundGenerator::make_tone( unsigned char *buf, int freq, \r
+ int len, int total_len, int trans_len )\r
+{\r
+ int i, j;\r
+\r
+ for ( i = 0; i < trans_len; ++i ) {\r
+ float level = ( sin( (double) i * SGD_2PI / (BYTES_PER_SECOND / freq) ) )\r
+ * ((double)i / trans_len) / 2.0 + 0.5;\r
+\r
+ /* Convert to unsigned byte */\r
+ buf[ i ] = (unsigned char) ( level * 255.0 ) ;\r
+ }\r
+\r
+ for ( i = trans_len; i < len - trans_len; ++i ) {\r
+ float level = ( sin( (double) i * SGD_2PI / (BYTES_PER_SECOND / freq) ) )\r
+ / 2.0 + 0.5;\r
+\r
+ /* Convert to unsigned byte */\r
+ buf[ i ] = (unsigned char) ( level * 255.0 ) ;\r
+ }\r
+ j = trans_len;\r
+ for ( i = len - trans_len; i < len; ++i ) {\r
+ float level = ( sin( (double) i * SGD_2PI / (BYTES_PER_SECOND / freq) ) )\r
+ * ((double)j / trans_len) / 2.0 + 0.5;\r
+ --j;\r
+\r
+ /* Convert to unsigned byte */\r
+ buf[ i ] = (unsigned char) ( level * 255.0 ) ;\r
+ }\r
+ for ( i = len; i < total_len; ++i ) {\r
+ buf[ i ] = (unsigned char) ( 0.5 * 255.0 ) ;\r
+ }\r
+}\r
--- /dev/null
+// soundgenerator.hxx -- simple sound generation \r
+//\r
+// Written by Curtis Olson, started March 2001.\r
+//\r
+// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt\r
+//\r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License as\r
+// published by the Free Software Foundation; either version 2 of the\r
+// License, or (at your option) any later version.\r
+//\r
+// This program is distributed in the hope that it will be useful, but\r
+// WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+//\r
+\r
+\r
+#ifndef _FGSOUNDGENERATOR_HXX\r
+#define _FGSOUNDGENERATOR_HXX\r
+\r
+#ifdef HAVE_CONFIG_H\r
+# include <config.h>\r
+#endif\r
+\r
+class FGSoundGenerator {\r
+\r
+public:\r
+ static const int BYTES_PER_SECOND = 22050;\r
+ // static const int BEAT_LENGTH = 240; // milleseconds (5 wpm)\r
+ static const int BEAT_LENGTH = 92; // milleseconds (13 wpm)\r
+ static const int TRANSITION_BYTES = (int)(0.005 * BYTES_PER_SECOND);\r
+ static const int COUNT_SIZE = BYTES_PER_SECOND * BEAT_LENGTH / 1000;\r
+ static const int DIT_SIZE = 2 * COUNT_SIZE; // 2 counts\r
+ static const int DAH_SIZE = 4 * COUNT_SIZE; // 4 counts\r
+ static const int SPACE_SIZE = 3 * COUNT_SIZE; // 3 counts\r
+ static const int LO_FREQUENCY = 1020; // AIM 1-1-7 (f) specified in Hz\r
+ static const int HI_FREQUENCY = 1350; // AIM 1-1-7 (f) specified in Hz\r
+\r
+protected:\r
+ /**\r
+ * \relates FGMorse\r
+ * Make a tone of specified freq and total_len with trans_len ramp in\r
+ * and out and only the first len bytes with sound, the rest with\r
+ * silence.\r
+ * @param buf unsigned char pointer to sound buffer\r
+ * @param freq desired frequency of tone\r
+ * @param len length of tone within sound\r
+ * @param total_len total length of sound (anything more than len is padded\r
+ * with silence.\r
+ * @param trans_len length of ramp up and ramp down to avoid audio "pop"\r
+ */\r
+ static void make_tone( unsigned char *buf, int freq, \r
+ int len, int total_len, int trans_len );\r
+\r
+public:\r
+\r
+ virtual ~FGSoundGenerator();\r
+};\r
+\r
+\r
+\r
+#endif // _FGSOUNDGENERATOR_HXX\r