#include "fg_io.hxx"
#include "globals.hxx"
#include "keyboard.hxx"
+#include "morse.hxx"
#include "splash.hxx"
#ifdef ENABLE_AUDIO_SUPPORT
<< " 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
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;
}
// 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;
// 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;
}
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
bool init();
// make a FGSimpleSound morse code transmission for the specified string
- FGSimpleSound make_ident( const string& id );
+ FGSimpleSound *make_ident( const string& id );
};
// $Id$
+#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
#include "globals.hxx"
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