]> git.mxchange.org Git - flightgear.git/blob - src/Sound/beacon.cxx
Get rid of the double comma's for the file section of the generic protocol also.
[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 - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #include "beacon.hxx"
25
26
27 // constructor
28 FGBeacon::FGBeacon() :
29     inner(NULL),
30     middle(NULL),
31     outer(NULL)
32 {
33 }
34
35 // destructor
36 FGBeacon::~FGBeacon() {
37     delete inner;
38     delete middle;
39     delete outer;
40 }
41
42
43 // allocate and initialize sound samples
44 bool FGBeacon::init() {
45     int i;
46     int len;
47     unsigned char *ptr;
48
49     unsigned char inner_buf[ INNER_SIZE ] ;
50     unsigned char middle_buf[ MIDDLE_SIZE ] ;
51     unsigned char outer_buf[ OUTER_SIZE ] ;
52
53     // Make inner marker beacon sound
54     len= (int)(INNER_DIT_LEN / 2.0 );
55     unsigned char inner_dit[INNER_DIT_LEN];
56     make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN,
57                TRANSITION_BYTES );
58
59     ptr = inner_buf;
60     for ( i = 0; i < 6; ++i ) {
61         memcpy( ptr, inner_dit, INNER_DIT_LEN );
62         ptr += INNER_DIT_LEN;
63     }
64
65     inner = new SGSoundSample( inner_buf, INNER_SIZE, BYTES_PER_SECOND, false );
66     inner->set_reference_dist( 10.0 );
67     inner->set_max_dist( 20.0 );
68
69     // Make middle marker beacon sound
70     len= (int)(MIDDLE_DIT_LEN / 2.0 );
71     unsigned char middle_dit[MIDDLE_DIT_LEN];
72     make_tone( middle_dit, MIDDLE_FREQ, len, MIDDLE_DIT_LEN,
73                TRANSITION_BYTES );
74
75     len= (int)(MIDDLE_DAH_LEN * 3 / 4.0 );
76     unsigned char middle_dah[MIDDLE_DAH_LEN];
77     make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
78                TRANSITION_BYTES );
79
80     ptr = middle_buf;
81     memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
82     ptr += MIDDLE_DIT_LEN;
83     memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
84
85     middle = new SGSoundSample( middle_buf, MIDDLE_SIZE, BYTES_PER_SECOND,
86                                 false );
87     middle->set_reference_dist( 10.0 );
88     middle->set_max_dist( 20.0 );
89
90     // Make outer marker beacon sound
91     len= (int)(OUTER_DAH_LEN * 3.0 / 4.0 );
92     unsigned char outer_dah[OUTER_DAH_LEN];
93     make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
94                TRANSITION_BYTES );
95     
96     ptr = outer_buf;
97     memcpy( ptr, outer_dah, OUTER_DAH_LEN );
98     ptr += OUTER_DAH_LEN;
99     memcpy( ptr, outer_dah, OUTER_DAH_LEN );
100
101     outer = new SGSoundSample( outer_buf, OUTER_SIZE, BYTES_PER_SECOND, false );
102     outer->set_reference_dist( 10.0 );
103     outer->set_max_dist( 20.0 );
104
105     return true;
106 }