]> git.mxchange.org Git - flightgear.git/blob - src/Sound/beacon.cxx
Merge branch 'next' of D:\Git_New\flightgear into next
[flightgear.git] / src / Sound / beacon.cxx
1 // beacon.cxx -- Morse code generation class
2 //
3 // Written by Curtis Olson, started March 2001.
4 //
5 // Copyright (C) 2001  Curtis L. Olson - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #include <stdlib.h>
25 #include <cstring>
26
27 #include "beacon.hxx"
28
29 #include <simgear/structure/exception.hxx>
30
31 // constructor
32 FGBeacon::FGBeacon()
33 {
34 }
35
36 // destructor
37 FGBeacon::~FGBeacon() {
38 }
39
40
41 // allocate and initialize sound samples
42 bool FGBeacon::init() {
43     unsigned char *ptr;
44     size_t i, len;
45
46     const unsigned char* inner_buf = (const unsigned char*)malloc( INNER_SIZE );
47     const unsigned char* middle_buf = (const unsigned char*)malloc(MIDDLE_SIZE);
48     const unsigned char* outer_buf = (const unsigned char*)malloc( OUTER_SIZE );
49
50     // Make inner marker beacon sound
51     len= (int)(INNER_DIT_LEN / 2.0 );
52     unsigned char inner_dit[INNER_DIT_LEN];
53     make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN,
54                TRANSITION_BYTES );
55
56     ptr = (unsigned char*)inner_buf;
57     for ( i = 0; i < 6; ++i ) {
58         memcpy( ptr, inner_dit, INNER_DIT_LEN );
59         ptr += INNER_DIT_LEN;
60     }
61
62     try {
63         inner = new SGSoundSample( &inner_buf, INNER_SIZE, BYTES_PER_SECOND );
64         inner->set_reference_dist( 10.0 );
65         inner->set_max_dist( 20.0 );
66
67         // Make middle marker beacon sound
68         len= (int)(MIDDLE_DIT_LEN / 2.0 );
69         unsigned char middle_dit[MIDDLE_DIT_LEN];
70         make_tone( middle_dit, MIDDLE_FREQ, len, MIDDLE_DIT_LEN,
71                     TRANSITION_BYTES );
72
73         len= (int)(MIDDLE_DAH_LEN * 3 / 4.0 );
74         unsigned char middle_dah[MIDDLE_DAH_LEN];
75         make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
76                     TRANSITION_BYTES );
77
78         ptr = (unsigned char*)middle_buf;
79         memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
80         ptr += MIDDLE_DIT_LEN;
81         memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
82
83         middle = new SGSoundSample( &middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND);
84         middle->set_reference_dist( 10.0 );
85         middle->set_max_dist( 20.0 );
86
87         // Make outer marker beacon sound
88         len= (int)(OUTER_DAH_LEN * 3.0 / 4.0 );
89         unsigned char outer_dah[OUTER_DAH_LEN];
90         make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
91                     TRANSITION_BYTES );
92            
93         ptr = (unsigned char*)outer_buf;
94         memcpy( ptr, outer_dah, OUTER_DAH_LEN );
95         ptr += OUTER_DAH_LEN;
96         memcpy( ptr, outer_dah, OUTER_DAH_LEN );
97
98         outer = new SGSoundSample( &outer_buf, OUTER_SIZE, BYTES_PER_SECOND );
99         outer->set_reference_dist( 10.0 );
100         outer->set_max_dist( 20.0 );
101     } catch ( sg_io_exception &e ) {
102         SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
103     }
104
105     return true;
106 }