2001-03-28 07:12:11 +00:00
|
|
|
// beacon.cxx -- Morse code generation class
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started March 2001.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
|
2001-03-28 07:12:11 +00:00
|
|
|
//
|
|
|
|
// 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
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-03-28 07:12:11 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#include "beacon.hxx"
|
|
|
|
|
2006-02-12 19:57:57 +00:00
|
|
|
#include <simgear/structure/exception.hxx>
|
2001-03-28 07:12:11 +00:00
|
|
|
|
|
|
|
// constructor
|
2006-01-24 14:45:13 +00:00
|
|
|
FGBeacon::FGBeacon()
|
2004-05-10 21:24:30 +00:00
|
|
|
{
|
2001-03-28 07:12:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// destructor
|
|
|
|
FGBeacon::~FGBeacon() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// allocate and initialize sound samples
|
|
|
|
bool FGBeacon::init() {
|
|
|
|
int i;
|
|
|
|
int len;
|
|
|
|
unsigned char *ptr;
|
|
|
|
|
2009-10-19 14:10:31 +00:00
|
|
|
std::auto_ptr<unsigned char>inner_buf( new unsigned char[ INNER_SIZE ] );
|
|
|
|
std::auto_ptr<unsigned char>middle_buf( new unsigned char[ MIDDLE_SIZE ] );
|
|
|
|
std::auto_ptr<unsigned char>outer_buf( new unsigned char[ OUTER_SIZE ] );
|
2004-05-10 21:24:30 +00:00
|
|
|
|
2001-03-28 07:12:11 +00:00
|
|
|
// Make inner marker beacon sound
|
|
|
|
len= (int)(INNER_DIT_LEN / 2.0 );
|
|
|
|
unsigned char inner_dit[INNER_DIT_LEN];
|
|
|
|
make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN,
|
|
|
|
TRANSITION_BYTES );
|
|
|
|
|
2009-10-19 14:10:31 +00:00
|
|
|
ptr = inner_buf.get();
|
2001-03-28 07:12:11 +00:00
|
|
|
for ( i = 0; i < 6; ++i ) {
|
|
|
|
memcpy( ptr, inner_dit, INNER_DIT_LEN );
|
|
|
|
ptr += INNER_DIT_LEN;
|
|
|
|
}
|
|
|
|
|
2006-02-12 19:57:57 +00:00
|
|
|
try {
|
|
|
|
inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND );
|
|
|
|
inner->set_reference_dist( 10.0 );
|
|
|
|
inner->set_max_dist( 20.0 );
|
|
|
|
|
|
|
|
// Make middle marker beacon sound
|
|
|
|
len= (int)(MIDDLE_DIT_LEN / 2.0 );
|
|
|
|
unsigned char middle_dit[MIDDLE_DIT_LEN];
|
|
|
|
make_tone( middle_dit, MIDDLE_FREQ, len, MIDDLE_DIT_LEN,
|
|
|
|
TRANSITION_BYTES );
|
|
|
|
|
|
|
|
len= (int)(MIDDLE_DAH_LEN * 3 / 4.0 );
|
|
|
|
unsigned char middle_dah[MIDDLE_DAH_LEN];
|
|
|
|
make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
|
|
|
|
TRANSITION_BYTES );
|
|
|
|
|
2009-10-19 14:10:31 +00:00
|
|
|
ptr = middle_buf.get();
|
2006-02-12 19:57:57 +00:00
|
|
|
memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
|
|
|
|
ptr += MIDDLE_DIT_LEN;
|
|
|
|
memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
|
|
|
|
|
|
|
|
middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND );
|
|
|
|
middle->set_reference_dist( 10.0 );
|
|
|
|
middle->set_max_dist( 20.0 );
|
|
|
|
|
|
|
|
// Make outer marker beacon sound
|
|
|
|
len= (int)(OUTER_DAH_LEN * 3.0 / 4.0 );
|
|
|
|
unsigned char outer_dah[OUTER_DAH_LEN];
|
|
|
|
make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
|
|
|
|
TRANSITION_BYTES );
|
|
|
|
|
2009-10-19 14:10:31 +00:00
|
|
|
ptr = outer_buf.get();
|
2006-02-12 19:57:57 +00:00
|
|
|
memcpy( ptr, outer_dah, OUTER_DAH_LEN );
|
|
|
|
ptr += OUTER_DAH_LEN;
|
|
|
|
memcpy( ptr, outer_dah, OUTER_DAH_LEN );
|
|
|
|
|
2009-10-04 13:52:53 +00:00
|
|
|
outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND );
|
2006-02-12 19:57:57 +00:00
|
|
|
outer->set_reference_dist( 10.0 );
|
|
|
|
outer->set_max_dist( 20.0 );
|
|
|
|
} catch ( sg_io_exception &e ) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
|
|
|
|
}
|
2001-03-28 07:12:11 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|