]> git.mxchange.org Git - flightgear.git/blob - src/Sound/beacon.cxx
Fix the temperature computation.
[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 "beacon.hxx"
25
26 #include <simgear/structure/exception.hxx>
27 #include <Main/fg_props.hxx>
28 #include <Main/globals.hxx>
29
30 // constructor
31 FGBeacon::FGBeacon()
32 {
33 }
34
35 // destructor
36 FGBeacon::~FGBeacon() {
37 }
38
39
40 // allocate and initialize sound samples
41 bool FGBeacon::init() {
42     int i;
43     int len;
44     unsigned char *ptr;
45
46     if (globals->get_soundmgr()->is_working() == false) {
47        return false;
48     }
49
50     unsigned char inner_buf[ INNER_SIZE ] ;
51     unsigned char middle_buf[ MIDDLE_SIZE ] ;
52     unsigned char outer_buf[ OUTER_SIZE ] ;
53
54     // Make inner marker beacon sound
55     len= (int)(INNER_DIT_LEN / 2.0 );
56     unsigned char inner_dit[INNER_DIT_LEN];
57     make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN,
58                TRANSITION_BYTES );
59
60     ptr = inner_buf;
61     for ( i = 0; i < 6; ++i ) {
62         memcpy( ptr, inner_dit, INNER_DIT_LEN );
63         ptr += INNER_DIT_LEN;
64     }
65
66     try {
67         inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND );
68         inner->set_reference_dist( 10.0 );
69         inner->set_max_dist( 20.0 );
70
71         // Make middle marker beacon sound
72         len= (int)(MIDDLE_DIT_LEN / 2.0 );
73         unsigned char middle_dit[MIDDLE_DIT_LEN];
74         make_tone( middle_dit, MIDDLE_FREQ, len, MIDDLE_DIT_LEN,
75                     TRANSITION_BYTES );
76
77         len= (int)(MIDDLE_DAH_LEN * 3 / 4.0 );
78         unsigned char middle_dah[MIDDLE_DAH_LEN];
79         make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
80                     TRANSITION_BYTES );
81
82         ptr = middle_buf;
83         memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
84         ptr += MIDDLE_DIT_LEN;
85         memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
86
87         middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND );
88         middle->set_reference_dist( 10.0 );
89         middle->set_max_dist( 20.0 );
90
91         // Make outer marker beacon sound
92         len= (int)(OUTER_DAH_LEN * 3.0 / 4.0 );
93         unsigned char outer_dah[OUTER_DAH_LEN];
94         make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
95                     TRANSITION_BYTES );
96            
97         ptr = outer_buf;
98         memcpy( ptr, outer_dah, OUTER_DAH_LEN );
99         ptr += OUTER_DAH_LEN;
100         memcpy( ptr, outer_dah, OUTER_DAH_LEN );
101
102         outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND);
103         outer->set_reference_dist( 10.0 );
104         outer->set_max_dist( 20.0 );
105     } catch ( sg_io_exception &e ) {
106         SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
107     }
108
109     return true;
110 }