28#include <simgear/sound/sample.hxx>
29#include <simgear/structure/exception.hxx>
30#include <simgear/debug/logstream.hxx>
43bool FGBeacon::init() {
47 auto inner_buf = std::unique_ptr<
unsigned char,
decltype(free)*>{
48 reinterpret_cast<unsigned char*
>( malloc( INNER_SIZE ) ),
51 auto middle_buf = std::unique_ptr<
unsigned char,
decltype(free)*>{
52 reinterpret_cast<unsigned char*
>( malloc( MIDDLE_SIZE ) ),
55 auto outer_buf = std::unique_ptr<
unsigned char,
decltype(free)*>{
56 reinterpret_cast<unsigned char*
>( malloc( OUTER_SIZE ) ),
61 len= (int)(INNER_DIT_LEN / 2.0 );
62 unsigned char inner_dit[INNER_DIT_LEN];
65 ptr = inner_buf.get();
66 for (
i = 0;
i < 6; ++
i ) {
67 memcpy( ptr, inner_dit, INNER_DIT_LEN );
72 inner =
new SGSoundSample( std::move(inner_buf),
74 inner->set_reference_dist( 10.0 );
75 inner->set_max_dist( 20.0 );
78 len= (int)(MIDDLE_DIT_LEN / 2.0 );
79 unsigned char middle_dit[MIDDLE_DIT_LEN];
80 make_tone( middle_dit, MIDDLE_FREQ, len, MIDDLE_DIT_LEN,
83 len= (int)(MIDDLE_DAH_LEN * 3 / 4.0 );
84 unsigned char middle_dah[MIDDLE_DAH_LEN];
85 make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
88 ptr = (
unsigned char*)middle_buf.get();
89 memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
90 ptr += MIDDLE_DIT_LEN;
91 memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
93 middle =
new SGSoundSample( std::move(middle_buf),
95 middle->set_reference_dist( 10.0 );
96 middle->set_max_dist( 20.0 );
99 len= (int)(OUTER_DAH_LEN * 3.0 / 4.0 );
100 unsigned char outer_dah[OUTER_DAH_LEN];
101 make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
104 ptr = (
unsigned char*)outer_buf.get();
105 memcpy( ptr, outer_dah, OUTER_DAH_LEN );
106 ptr += OUTER_DAH_LEN;
107 memcpy( ptr, outer_dah, OUTER_DAH_LEN );
109 outer =
new SGSoundSample( std::move(outer_buf), OUTER_SIZE,
111 outer->set_reference_dist( 10.0 );
112 outer->set_max_dist( 20.0 );
113 }
catch ( sg_io_exception &e ) {
114 SG_LOG(SG_SOUND, SG_ALERT, e.getFormattedMessage());
120FGBeacon * FGBeacon::_instance = NULL;
124 if( _instance == NULL ) {
137 const uint64_t ditLen = INNER_DIT_LEN *
sizeToUSec;
147 const uint64_t ditLen = MIDDLE_DIT_LEN *
sizeToUSec;
148 const uint64_t dahLen = MIDDLE_DAH_LEN *
sizeToUSec;
161 const uint64_t dahLen = OUTER_DAH_LEN *
sizeToUSec;
static const uint64_t sizeToUSec
-- Provides marker beacon audio generation.
BeaconTiming getTimingForOuter() const
BeaconTiming getTimingForInner() const
static FGBeacon * instance()
BeaconTiming getTimingForMiddle() const
static const int TRANSITION_BYTES
static void make_tone(unsigned char *buf, int freq, int len, int total_len, int trans_len)
Make a tone of specified freq and total_len with trans_len ramp in and out and only the first len byt...
static const int BYTES_PER_SECOND
std::array< uint64_t, 4 > periodsUSec