Refactor morse and beacon as singleton
This commit is contained in:
parent
587895bf2b
commit
9cef27f5ca
17 changed files with 202 additions and 117 deletions
|
@ -3229,6 +3229,14 @@
|
||||||
RelativePath="..\..\..\src\Sound\sample_queue.hxx"
|
RelativePath="..\..\..\src\Sound\sample_queue.hxx"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\src\Sound\soundgenerator.cxx"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\src\Sound\soundgenerator.hxx"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\src\Sound\voice.cxx"
|
RelativePath="..\..\..\src\Sound\voice.cxx"
|
||||||
>
|
>
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include <Navaids/navlist.hxx>
|
#include <Navaids/navlist.hxx>
|
||||||
|
|
||||||
#include "adf.hxx"
|
#include "adf.hxx"
|
||||||
|
#include <Sound/morse.hxx>
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -110,8 +112,6 @@ ADF::init ()
|
||||||
_sgr = smgr->find("avionics", true);
|
_sgr = smgr->find("avionics", true);
|
||||||
_sgr->tie_to_listener();
|
_sgr->tie_to_listener();
|
||||||
|
|
||||||
morse.init();
|
|
||||||
|
|
||||||
std::ostringstream temp;
|
std::ostringstream temp;
|
||||||
temp << _name << _num;
|
temp << _name << _num;
|
||||||
_adf_ident = temp.str();
|
_adf_ident = temp.str();
|
||||||
|
@ -252,7 +252,7 @@ ADF::search (double frequency_khz, double longitude_rad,
|
||||||
}
|
}
|
||||||
|
|
||||||
SGSoundSample *sound;
|
SGSoundSample *sound;
|
||||||
sound = morse.make_ident( ident, LO_FREQUENCY );
|
sound = FGMorse::instance()->make_ident( ident, LO_FREQUENCY );
|
||||||
sound->set_volume(_last_volume = 0);
|
sound->set_volume(_last_volume = 0);
|
||||||
_sgr->add( sound, _adf_ident );
|
_sgr->add( sound, _adf_ident );
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
|
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
#include <Sound/morse.hxx>
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -93,7 +92,6 @@ private:
|
||||||
SGVec3d _transmitter_cart;
|
SGVec3d _transmitter_cart;
|
||||||
double _transmitter_range_nm;
|
double _transmitter_range_nm;
|
||||||
|
|
||||||
FGMorse morse;
|
|
||||||
int _ident_count;
|
int _ident_count;
|
||||||
time_t _last_ident_time;
|
time_t _last_ident_time;
|
||||||
float _last_volume;
|
float _last_volume;
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include "kr_87.hxx"
|
#include "kr_87.hxx"
|
||||||
|
|
||||||
|
#include <Sound/morse.hxx>
|
||||||
#include <string>
|
#include <string>
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -119,7 +120,6 @@ void FGKR_87::init () {
|
||||||
SGSoundMgr *smgr = globals->get_soundmgr();
|
SGSoundMgr *smgr = globals->get_soundmgr();
|
||||||
_sgr = smgr->find("avionics", true);
|
_sgr = smgr->find("avionics", true);
|
||||||
_sgr->tie_to_listener();
|
_sgr->tie_to_listener();
|
||||||
morse.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ void FGKR_87::search() {
|
||||||
_sgr->remove( "adf-ident" );
|
_sgr->remove( "adf-ident" );
|
||||||
}
|
}
|
||||||
SGSoundSample *sound;
|
SGSoundSample *sound;
|
||||||
sound = morse.make_ident( trans_ident, LO_FREQUENCY );
|
sound = FGMorse::instance()->make_ident( trans_ident, LO_FREQUENCY );
|
||||||
sound->set_volume( 0.3 );
|
sound->set_volume( 0.3 );
|
||||||
_sgr->add( sound, "adf-ident" );
|
_sgr->add( sound, "adf-ident" );
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,11 @@
|
||||||
#include <simgear/timing/timestamp.hxx>
|
#include <simgear/timing/timestamp.hxx>
|
||||||
|
|
||||||
#include <Navaids/navlist.hxx>
|
#include <Navaids/navlist.hxx>
|
||||||
#include <Sound/morse.hxx>
|
|
||||||
|
|
||||||
class SGSampleGroup;
|
class SGSampleGroup;
|
||||||
|
|
||||||
class FGKR_87 : public SGSubsystem
|
class FGKR_87 : public SGSubsystem
|
||||||
{
|
{
|
||||||
FGMorse morse;
|
|
||||||
|
|
||||||
SGPropertyNode_ptr lon_node;
|
SGPropertyNode_ptr lon_node;
|
||||||
SGPropertyNode_ptr lat_node;
|
SGPropertyNode_ptr lat_node;
|
||||||
SGPropertyNode_ptr alt_node;
|
SGPropertyNode_ptr alt_node;
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <Navaids/navlist.hxx>
|
#include <Navaids/navlist.hxx>
|
||||||
|
|
||||||
#include "marker_beacon.hxx"
|
#include "marker_beacon.hxx"
|
||||||
|
#include <Sound/beacon.hxx>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -120,8 +121,6 @@ FGMarkerBeacon::init ()
|
||||||
_sgr = smgr->find("avionics", true);
|
_sgr = smgr->find("avionics", true);
|
||||||
_sgr->tie_to_listener();
|
_sgr->tie_to_listener();
|
||||||
|
|
||||||
morse.init();
|
|
||||||
beacon.init();
|
|
||||||
blink.stamp();
|
blink.stamp();
|
||||||
|
|
||||||
outer_marker = middle_marker = inner_marker = false;
|
outer_marker = middle_marker = inner_marker = false;
|
||||||
|
@ -317,7 +316,7 @@ void FGMarkerBeacon::search()
|
||||||
// cout << "OUTER MARKER" << endl;
|
// cout << "OUTER MARKER" << endl;
|
||||||
if ( last_beacon != OUTER ) {
|
if ( last_beacon != OUTER ) {
|
||||||
if ( ! _sgr->exists( current_sound_name ) ) {
|
if ( ! _sgr->exists( current_sound_name ) ) {
|
||||||
SGSoundSample *sound = beacon.get_outer();
|
SGSoundSample *sound = FGBeacon::instance()->get_outer();
|
||||||
if ( sound ) {
|
if ( sound ) {
|
||||||
_sgr->add( sound, current_sound_name );
|
_sgr->add( sound, current_sound_name );
|
||||||
}
|
}
|
||||||
|
@ -336,7 +335,7 @@ void FGMarkerBeacon::search()
|
||||||
// cout << "MIDDLE MARKER" << endl;
|
// cout << "MIDDLE MARKER" << endl;
|
||||||
if ( last_beacon != MIDDLE ) {
|
if ( last_beacon != MIDDLE ) {
|
||||||
if ( ! _sgr->exists( current_sound_name ) ) {
|
if ( ! _sgr->exists( current_sound_name ) ) {
|
||||||
SGSoundSample *sound = beacon.get_middle();
|
SGSoundSample *sound = FGBeacon::instance()->get_middle();
|
||||||
if ( sound ) {
|
if ( sound ) {
|
||||||
_sgr->add( sound, current_sound_name );
|
_sgr->add( sound, current_sound_name );
|
||||||
}
|
}
|
||||||
|
@ -355,7 +354,7 @@ void FGMarkerBeacon::search()
|
||||||
// cout << "INNER MARKER" << endl;
|
// cout << "INNER MARKER" << endl;
|
||||||
if ( last_beacon != INNER ) {
|
if ( last_beacon != INNER ) {
|
||||||
if ( ! _sgr->exists( current_sound_name ) ) {
|
if ( ! _sgr->exists( current_sound_name ) ) {
|
||||||
SGSoundSample *sound = beacon.get_inner();
|
SGSoundSample *sound = FGBeacon::instance()->get_inner();
|
||||||
if ( sound ) {
|
if ( sound ) {
|
||||||
_sgr->add( sound, current_sound_name );
|
_sgr->add( sound, current_sound_name );
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,16 +32,10 @@
|
||||||
#include <simgear/math/interpolater.hxx>
|
#include <simgear/math/interpolater.hxx>
|
||||||
#include <simgear/timing/timestamp.hxx>
|
#include <simgear/timing/timestamp.hxx>
|
||||||
|
|
||||||
#include <Sound/beacon.hxx>
|
|
||||||
#include <Sound/morse.hxx>
|
|
||||||
|
|
||||||
class SGSampleGroup;
|
class SGSampleGroup;
|
||||||
|
|
||||||
class FGMarkerBeacon : public SGSubsystem
|
class FGMarkerBeacon : public SGSubsystem
|
||||||
{
|
{
|
||||||
FGBeacon beacon;
|
|
||||||
FGMorse morse;
|
|
||||||
|
|
||||||
SGInterpTable *term_tbl;
|
SGInterpTable *term_tbl;
|
||||||
SGInterpTable *low_tbl;
|
SGInterpTable *low_tbl;
|
||||||
SGInterpTable *high_tbl;
|
SGInterpTable *high_tbl;
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include <Airports/runways.hxx>
|
#include <Airports/runways.hxx>
|
||||||
#include <Navaids/navlist.hxx>
|
#include <Navaids/navlist.hxx>
|
||||||
#include <Main/util.hxx>
|
#include <Main/util.hxx>
|
||||||
|
#include <Sound/morse.hxx>
|
||||||
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -175,8 +176,6 @@ FGNavRadio::init ()
|
||||||
_sgr = smgr->find("avionics", true);
|
_sgr = smgr->find("avionics", true);
|
||||||
_sgr->tie_to_listener();
|
_sgr->tie_to_listener();
|
||||||
|
|
||||||
morse.init();
|
|
||||||
|
|
||||||
SGPropertyNode* node = _radio_node.get();
|
SGPropertyNode* node = _radio_node.get();
|
||||||
bus_power_node =
|
bus_power_node =
|
||||||
fgGetNode(("/systems/electrical/outputs/" + _name).c_str(), true);
|
fgGetNode(("/systems/electrical/outputs/" + _name).c_str(), true);
|
||||||
|
@ -1014,7 +1013,7 @@ void FGNavRadio::audioNavidChanged()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
string trans_ident(_navaid->get_trans_ident());
|
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 );
|
sound->set_volume( 0.3 );
|
||||||
if (!_sgr->add( sound, nav_fx_name )) {
|
if (!_sgr->add( sound, nav_fx_name )) {
|
||||||
SG_LOG(SG_COCKPIT, SG_WARN, "Failed to add v1-vor-ident sound");
|
SG_LOG(SG_COCKPIT, SG_WARN, "Failed to add v1-vor-ident sound");
|
||||||
|
@ -1024,7 +1023,7 @@ void FGNavRadio::audioNavidChanged()
|
||||||
_sgr->remove( dme_fx_name );
|
_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 );
|
sound->set_volume( 0.3 );
|
||||||
_sgr->add( sound, dme_fx_name );
|
_sgr->add( sound, dme_fx_name );
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include "Sound/morse.hxx"
|
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
|
@ -41,8 +40,6 @@ typedef SGSharedPtr<FGNavRecord> FGNavRecordPtr;
|
||||||
|
|
||||||
class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener
|
class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener
|
||||||
{
|
{
|
||||||
FGMorse morse;
|
|
||||||
|
|
||||||
SGInterpTable *term_tbl;
|
SGInterpTable *term_tbl;
|
||||||
SGInterpTable *low_tbl;
|
SGInterpTable *low_tbl;
|
||||||
SGInterpTable *high_tbl;
|
SGInterpTable *high_tbl;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
include(FlightGearComponent)
|
include(FlightGearComponent)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
|
soundgenerator.cxx
|
||||||
beacon.cxx
|
beacon.cxx
|
||||||
fg_fx.cxx
|
fg_fx.cxx
|
||||||
morse.cxx
|
morse.cxx
|
||||||
|
@ -10,6 +11,7 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
|
soundgenerator.hxx
|
||||||
beacon.hxx
|
beacon.hxx
|
||||||
fg_fx.hxx
|
fg_fx.hxx
|
||||||
morse.hxx
|
morse.hxx
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
noinst_LIBRARIES = libSound.a
|
noinst_LIBRARIES = libSound.a
|
||||||
|
|
||||||
libSound_a_SOURCES = \
|
libSound_a_SOURCES = \
|
||||||
|
soundgenerator.cxx soundgenerator.hxx \
|
||||||
beacon.cxx beacon.hxx \
|
beacon.cxx beacon.hxx \
|
||||||
fg_fx.cxx fg_fx.hxx \
|
fg_fx.cxx fg_fx.hxx \
|
||||||
morse.cxx morse.hxx \
|
morse.cxx morse.hxx \
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -104,3 +102,14 @@ bool FGBeacon::init() {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FGBeacon * FGBeacon::_instance = NULL;
|
||||||
|
|
||||||
|
FGBeacon * FGBeacon::instance()
|
||||||
|
{
|
||||||
|
if( _instance == NULL ) {
|
||||||
|
_instance = new FGBeacon();
|
||||||
|
_instance->init();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
|
@ -20,24 +20,17 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _BEACON_HXX
|
#ifndef _BEACON_HXX
|
||||||
#define _BEACON_HXX
|
#define _BEACON_HXX
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include "soundgenerator.hxx"
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include <simgear/sound/soundmgr_openal.hxx>
|
#include <simgear/sound/soundmgr_openal.hxx>
|
||||||
#include <simgear/structure/SGReferenced.hxx>
|
#include <simgear/structure/SGReferenced.hxx>
|
||||||
#include <simgear/structure/SGSharedPtr.hxx>
|
#include <simgear/structure/SGSharedPtr.hxx>
|
||||||
|
|
||||||
#include "morse.hxx"
|
|
||||||
|
|
||||||
|
|
||||||
// Quoting from http://www.smartregs.com/data/sa326.htm
|
// Quoting from http://www.smartregs.com/data/sa326.htm
|
||||||
// Smart REGS Glossary - marker beacon
|
// Smart REGS Glossary - marker beacon
|
||||||
//
|
//
|
||||||
|
@ -77,35 +70,35 @@
|
||||||
// (See instrument landing system) (Refer to AIM.)
|
// (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
|
// manages everything we need to know for an individual sound sample
|
||||||
class FGBeacon {
|
class FGBeacon : public FGSoundGenerator {
|
||||||
|
|
||||||
private:
|
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> inner;
|
||||||
SGSharedPtr<SGSoundSample> middle;
|
SGSharedPtr<SGSoundSample> middle;
|
||||||
SGSharedPtr<SGSoundSample> outer;
|
SGSharedPtr<SGSoundSample> outer;
|
||||||
|
|
||||||
|
// allocate and initialize sound samples
|
||||||
|
bool init();
|
||||||
|
static FGBeacon * _instance;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGBeacon();
|
FGBeacon();
|
||||||
~FGBeacon();
|
~FGBeacon();
|
||||||
|
static FGBeacon * instance();
|
||||||
// allocate and initialize sound samples
|
|
||||||
bool init();
|
|
||||||
|
|
||||||
SGSoundSample *get_inner() { return inner; }
|
SGSoundSample *get_inner() { return inner; }
|
||||||
SGSoundSample *get_middle() { return middle; }
|
SGSoundSample *get_middle() { return middle; }
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
|
||||||
|
|
||||||
|
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
|
@ -79,44 +78,6 @@ FGMorse::~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
|
|
||||||
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
|
// allocate and initialize sound samples
|
||||||
bool FGMorse::init() {
|
bool FGMorse::init() {
|
||||||
// Make Low DIT
|
// Make Low DIT
|
||||||
|
@ -270,3 +231,14 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) {
|
||||||
|
|
||||||
return sample;
|
return sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FGMorse * FGMorse::_instance = NULL;
|
||||||
|
|
||||||
|
FGMorse * FGMorse::instance()
|
||||||
|
{
|
||||||
|
if( _instance == NULL ) {
|
||||||
|
_instance = new FGMorse();
|
||||||
|
_instance->init();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
|
@ -18,16 +18,12 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
//
|
//
|
||||||
// $Id$
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _MORSE_HXX
|
#ifndef _MORSE_HXX
|
||||||
#define _MORSE_HXX
|
#define _MORSE_HXX
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include "soundgenerator.hxx"
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
#include <simgear/sound/soundmgr_openal.hxx>
|
#include <simgear/sound/soundmgr_openal.hxx>
|
||||||
|
|
||||||
|
@ -97,7 +93,7 @@ static const int LO_FREQUENCY = 1020; // AIM 1-1-7 (f) specified in Hz
|
||||||
static const int HI_FREQUENCY = 1350; // AIM 1-1-7 (f) specified in Hz
|
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
|
// manages everything we need to know for an individual sound sample
|
||||||
class FGMorse {
|
class FGMorse : public FGSoundGenerator {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -110,15 +106,18 @@ private:
|
||||||
unsigned char cust_dit[ DIT_SIZE ] ;
|
unsigned char cust_dit[ DIT_SIZE ] ;
|
||||||
unsigned char cust_dah[ DAH_SIZE ] ;
|
unsigned char cust_dah[ DAH_SIZE ] ;
|
||||||
|
|
||||||
|
static FGMorse * _instance;
|
||||||
|
|
||||||
bool cust_init( const int freq );
|
bool cust_init( const int freq );
|
||||||
|
// allocate and initialize sound samples
|
||||||
|
bool init();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGMorse();
|
FGMorse();
|
||||||
~FGMorse();
|
~FGMorse();
|
||||||
|
|
||||||
// allocate and initialize sound samples
|
static FGMorse * instance();
|
||||||
bool init();
|
|
||||||
|
|
||||||
// make a SimpleSound morse code transmission for the specified string
|
// make a SimpleSound morse code transmission for the specified string
|
||||||
SGSoundSample *make_ident( const string& id,
|
SGSoundSample *make_ident( const string& id,
|
||||||
|
@ -126,20 +125,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \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
|
#endif // _MORSE_HXX
|
||||||
|
|
||||||
|
|
64
src/Sound/soundgenerator.cxx
Normal file
64
src/Sound/soundgenerator.cxx
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
// soundgenerator.cxx -- simple sound generation
|
||||||
|
//
|
||||||
|
// Written by Curtis Olson, started March 2001.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "soundgenerator.hxx"
|
||||||
|
#include <simgear/constants.h>
|
||||||
|
|
||||||
|
FGSoundGenerator::~FGSoundGenerator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 FGSoundGenerator::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 ) ;
|
||||||
|
}
|
||||||
|
}
|
67
src/Sound/soundgenerator.hxx
Normal file
67
src/Sound/soundgenerator.hxx
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
// soundgenerator.hxx -- simple sound generation
|
||||||
|
//
|
||||||
|
// Written by Curtis Olson, started March 2001.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _FGSOUNDGENERATOR_HXX
|
||||||
|
#define _FGSOUNDGENERATOR_HXX
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class FGSoundGenerator {
|
||||||
|
|
||||||
|
public:
|
||||||
|
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);
|
||||||
|
static const int COUNT_SIZE = BYTES_PER_SECOND * BEAT_LENGTH / 1000;
|
||||||
|
static const int DIT_SIZE = 2 * COUNT_SIZE; // 2 counts
|
||||||
|
static const int DAH_SIZE = 4 * COUNT_SIZE; // 4 counts
|
||||||
|
static const int SPACE_SIZE = 3 * COUNT_SIZE; // 3 counts
|
||||||
|
static const int LO_FREQUENCY = 1020; // AIM 1-1-7 (f) specified in Hz
|
||||||
|
static const int HI_FREQUENCY = 1350; // AIM 1-1-7 (f) specified in Hz
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* \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"
|
||||||
|
*/
|
||||||
|
static void make_tone( unsigned char *buf, int freq,
|
||||||
|
int len, int total_len, int trans_len );
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~FGSoundGenerator();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _FGSOUNDGENERATOR_HXX
|
Loading…
Add table
Reference in a new issue