1
0
Fork 0

More work on morse code ...

This commit is contained in:
curt 2001-03-05 14:11:25 +00:00
parent 040185f0fd
commit fbad3482fa
4 changed files with 66 additions and 7 deletions

View file

@ -117,6 +117,7 @@ int objc=0;
#include "fg_io.hxx"
#include "globals.hxx"
#include "keyboard.hxx"
#include "morse.hxx"
#include "splash.hxx"
#ifdef ENABLE_AUDIO_SUPPORT
@ -1191,8 +1192,11 @@ static void fgIdleFunction ( void ) {
<< " Bps = " << s1->get_sample()->getBps()
<< " Stereo = " << s1->get_sample()->getStereo() );
s2 = new FGSimpleSound( "Sounds/corflaps.wav" );
s2->set_volume( 2.0 );
// s2 = new FGSimpleSound( "Sounds/corflaps.wav" );
// s2->set_volume( 2.0 );
FGMorse mmm;
mmm.init();
s2 = mmm.make_ident( "JLI" );
globals->get_soundmgr()->add( s2, "flaps" );
}
#endif

View file

@ -38,7 +38,6 @@ bool FGMorse::init() {
int i, j;
// Make DIT
unsigned char dit[ DIT_SIZE ] ;
for ( i = 0; i < TRANSITION_BYTES; ++i ) {
float level = ( sin( (double) i * 2.0 * M_PI / (8000.0 / FREQUENCY)) )
* ((double)i / TRANSITION_BYTES) / 2.0 + 0.5;
@ -71,7 +70,6 @@ bool FGMorse::init() {
}
// Make DAH
unsigned char dah[ DAH_SIZE ] ;
for ( i = 0; i < TRANSITION_BYTES; ++i ) {
float level = ( sin( (double) i * 2.0 * M_PI / (8000.0 / FREQUENCY) ) )
* ((double)i / TRANSITION_BYTES) / 2.0 + 0.5;
@ -114,5 +112,56 @@ bool FGMorse::init() {
// make a FGSimpleSound morse code transmission for the specified string
FGSimpleSound FGMorse::make_ident( const string& id ) {
FGSimpleSound *FGMorse::make_ident( const string& id ) {
char *idptr = (char *)id.c_str();
int length = 0;
int i, j;
// 1. Determine byte length of message
for ( i = 0; i < (int)id.length(); ++i ) {
if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) {
char c = idptr[i] - 'A';
for ( j = 0; j < 4 || alphabet[c][j] == end; ++j ) {
if ( alphabet[c][j] == DIT ) {
length += DIT_SIZE;
} else if ( alphabet[c][j] == DAH ) {
length += DAH_SIZE;
}
}
length += SPACE_SIZE;
} else {
// skip unknown character
}
}
// 2. Allocate space for the message
unsigned char *buffer = new unsigned char[length];
// 3. Assemble the message;
unsigned char *bufptr = buffer;
for ( i = 0; i < (int)id.length(); ++i ) {
if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) {
char c = idptr[i] - 'A';
for ( j = 0; j < 4 || alphabet[c][j] == end; ++j ) {
if ( alphabet[c][j] == DIT ) {
memcpy( bufptr, dit, DIT_SIZE );
bufptr += DIT_SIZE;
} else if ( alphabet[c][j] == DAH ) {
memcpy( bufptr, dah, DAH_SIZE );
bufptr += DAH_SIZE;
}
}
memcpy( bufptr, space, SPACE_SIZE );
bufptr += SPACE_SIZE;
} else {
// skip unknown character
}
}
// 4. create the simple sound and return
FGSimpleSound *sample = new FGSimpleSound( buffer, length );
return sample;
}

View file

@ -91,7 +91,7 @@ static const char end = '0';
static const int BYTES_PER_SECOND = 8000;
static const int BEAT_LENGTH = 240; // milleseconds (5 wpm)
static const int TRANSITION_BYTES = 40;
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
@ -143,7 +143,7 @@ public:
bool init();
// make a FGSimpleSound morse code transmission for the specified string
FGSimpleSound make_ident( const string& id );
FGSimpleSound *make_ident( const string& id );
};

View file

@ -24,6 +24,7 @@
// $Id$
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
#include "globals.hxx"
@ -61,6 +62,11 @@ FGSimpleSound::~FGSimpleSound() {
FGSoundMgr::FGSoundMgr() {
audio_sched = new slScheduler( 8000 );
audio_mixer = new smMixer;
FG_LOG( FG_GENERAL, FG_INFO,
"Rate = " << audio_sched->getRate()
<< " Bps = " << audio_sched->getBps()
<< " Stereo = " << audio_sched->getStereo() );
}
// destructor