~ubuntu-branches/ubuntu/saucy/tlf/saucy

« back to all changes in this revision

Viewing changes to src/audio.c

  • Committer: Package Import Robot
  • Author(s): John T. Nogatch
  • Date: 2013-02-09 14:56:34 UTC
  • mfrom: (1.2.5) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130209145634-de47b40lyf5ntgsu
Tags: 1.1.5-1
* Update from upstream git
* LP: #854080, #514303

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Tlf - contest logging program for amateur radio operators
3
3
 * Copyright (C) 2001-2002-2003-2004-2005 Rein Couperus <pa0r@amsat.org>
 
4
 *                                   2012 Thomas Beierlein <tb@forth-ev.de>
4
5
 *
5
6
 * This program is free software; you can redistribute it and/or modify
6
7
 * it under the terms of the GNU General Public License as published by
18
19
 */
19
20
 
20
21
        /* ------------------------------------------------------------
21
 
        *      audio.c   soundcard input routine
22
 
        *
23
 
        *--------------------------------------------------------------*/
 
22
         *      audio.c   soundcard input routine
 
23
         *
 
24
         *--------------------------------------------------------------*/
24
25
 
25
26
#include "audio.h"
26
27
#include <math.h>
35
36
 
36
37
#define ABUFSIZE          4000
37
38
 
38
 
 void init_audio() {
39
 
 
40
 
        char afile[40];                     /* Audio device name */
41
 
        int sndfmt;                         /* Encoding of audio from */
42
 
        int channels;                       /* Number of channels to record */
43
 
        int speed;                          /* Sample rate of audio */
44
 
 
45
 
        sndfmt = AFMT_MU_LAW;
46
 
        channels = 1;
47
 
        speed = 8000;
 
39
void init_audio()
 
40
{
 
41
 
 
42
    char afile[40];             /* Audio device name */
 
43
    int sndfmt;                 /* Encoding of audio from */
 
44
    int channels;               /* Number of channels to record */
 
45
    int speed;                  /* Sample rate of audio */
 
46
 
 
47
    sndfmt = AFMT_MU_LAW;
 
48
    channels = 1;
 
49
    speed = 8000;
48
50
 
49
51
/* Audio device setup */
50
52
 
51
 
        strcpy (afile, sc_device);
52
 
 
53
 
        if ((afd = open(afile, O_RDONLY, 0)) == -1)
54
 
    {
55
 
        perror(afile);
56
 
        exit(errno);
57
 
    }
58
 
 
59
 
    if (ioctl(afd, SNDCTL_DSP_SETFMT, &sndfmt) == -1)
60
 
    {
61
 
        perror("mu law");
62
 
        exit(errno);
63
 
    }
64
 
 
65
 
    if (ioctl(afd, SNDCTL_DSP_CHANNELS, &channels) == -1)
66
 
    {
67
 
        perror("mono");
68
 
        exit(errno);
69
 
    }
70
 
 
71
 
    if (ioctl(afd, SNDCTL_DSP_SPEED, &speed) == -1)
72
 
    {
73
 
        perror("8000 sps");
74
 
        exit(errno);
 
53
    strcpy(afile, sc_device);
 
54
 
 
55
    if ((afd = open(afile, O_RDONLY, 0)) == -1) {
 
56
        perror(afile);
 
57
        exit(errno);
 
58
    }
 
59
 
 
60
    if (ioctl(afd, SNDCTL_DSP_SETFMT, &sndfmt) == -1) {
 
61
        perror("mu law");
 
62
        exit(errno);
 
63
    }
 
64
 
 
65
    if (ioctl(afd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
 
66
        perror("mono");
 
67
        exit(errno);
 
68
    }
 
69
 
 
70
    if (ioctl(afd, SNDCTL_DSP_SPEED, &speed) == -1) {
 
71
        perror("8000 sps");
 
72
        exit(errno);
75
73
    }
76
74
}
77
75
 
78
 
int close_audio() {
79
 
 
80
 
        close (afd);
81
 
 
82
 
return (0);
 
76
int close_audio()
 
77
{
 
78
 
 
79
    close(afd);
 
80
 
 
81
    return (0);
83
82
}
84
83
 
85
84
/* ------------ rescale bar ----------*/
86
85
 
87
 
 
88
 
int rescale (int testvalue) {
89
 
 
90
 
extern int scale_values[];
91
 
 
92
 
if (testvalue > scale_values[0]) testvalue = 19;
93
 
else if (testvalue > scale_values[1]) testvalue = 18;
94
 
else if (testvalue > scale_values[2]) testvalue = 17;
95
 
else if (testvalue > scale_values[3]) testvalue = 16;
96
 
else if (testvalue > scale_values[4]) testvalue = 15;
97
 
else if (testvalue > scale_values[5]) testvalue = 14;
98
 
else if (testvalue > scale_values[6]) testvalue = 13;
99
 
else if (testvalue > scale_values[7]) testvalue = 12;
100
 
else if (testvalue > scale_values[8]) testvalue = 11;
101
 
else if (testvalue > scale_values[9]) testvalue = 10;
102
 
else if (testvalue > scale_values[10]) testvalue = 9;
103
 
else if (testvalue > scale_values[11]) testvalue = 8;
104
 
else if (testvalue > scale_values[12]) testvalue = 7;
105
 
else if (testvalue > scale_values[13]) testvalue = 6;
106
 
else if (testvalue > scale_values[14]) testvalue = 5;
107
 
else if (testvalue > scale_values[15]) testvalue = 4;
108
 
else if (testvalue > scale_values[16]) testvalue = 3;
109
 
else if (testvalue > scale_values[17]) testvalue = 2;
110
 
else if (testvalue > scale_values[18]) testvalue = 1;
111
 
else testvalue = 0;
112
 
 
113
 
        return (testvalue);
 
86
int rescale(int testvalue)
 
87
{
 
88
 
 
89
    extern int scale_values[];
 
90
 
 
91
    if (testvalue > scale_values[0])
 
92
        testvalue = 19;
 
93
    else if (testvalue > scale_values[1])
 
94
        testvalue = 18;
 
95
    else if (testvalue > scale_values[2])
 
96
        testvalue = 17;
 
97
    else if (testvalue > scale_values[3])
 
98
        testvalue = 16;
 
99
    else if (testvalue > scale_values[4])
 
100
        testvalue = 15;
 
101
    else if (testvalue > scale_values[5])
 
102
        testvalue = 14;
 
103
    else if (testvalue > scale_values[6])
 
104
        testvalue = 13;
 
105
    else if (testvalue > scale_values[7])
 
106
        testvalue = 12;
 
107
    else if (testvalue > scale_values[8])
 
108
        testvalue = 11;
 
109
    else if (testvalue > scale_values[9])
 
110
        testvalue = 10;
 
111
    else if (testvalue > scale_values[10])
 
112
        testvalue = 9;
 
113
    else if (testvalue > scale_values[11])
 
114
        testvalue = 8;
 
115
    else if (testvalue > scale_values[12])
 
116
        testvalue = 7;
 
117
    else if (testvalue > scale_values[13])
 
118
        testvalue = 6;
 
119
    else if (testvalue > scale_values[14])
 
120
        testvalue = 5;
 
121
    else if (testvalue > scale_values[15])
 
122
        testvalue = 4;
 
123
    else if (testvalue > scale_values[16])
 
124
        testvalue = 3;
 
125
    else if (testvalue > scale_values[17])
 
126
        testvalue = 2;
 
127
    else if (testvalue > scale_values[18])
 
128
        testvalue = 1;
 
129
    else
 
130
        testvalue = 0;
 
131
 
 
132
    return (testvalue);
114
133
}
115
134
 
116
 
 
117
 
float get_audio_sample(void) {
118
 
 
119
 
    int rc=0;                                   /* Return value from subs */
120
 
        static float avg = 128.0;
121
 
        static float maxval=0;
122
 
        static float minval=0;
123
 
        static float retval = 0.0;
124
 
    unsigned char abuf[ABUFSIZE];       /* Audio data buffer */
125
 
        int i, k;
126
 
 
127
 
        for (k=0; k < 4; k++) {
128
 
           if ((rc = read(afd, abuf, ABUFSIZE)) == -1)
129
 
        {
130
 
            perror("audio read");
131
 
            exit(errno);
132
 
        }
133
 
 
134
 
                for (i=0; i < rc; i++)          // calculate average
135
 
                {
136
 
                        if ( (maxval - minval) != 0.0){
137
 
                                        if (i > 2)
138
 
                                                avg =  avg + (abuf[i] + abuf[i-1] + abuf[i-2] + abuf[i-3])/ 5;
139
 
                                        else
140
 
                                                avg =  avg + (abuf[i] + abuf[i+1] + abuf[i+2] + abuf[i+3])/ 5;
141
 
                        }
142
 
                        if (avg >= 188.0) avg = 128.0;
143
 
                        if (avg <= 60.0) avg = 128.0;
144
 
 
145
 
                }
146
 
                for (i=0; i < rc; i++)          // calculate maximum avg value
147
 
                {
148
 
                        if (abuf[i] >= avg) {
149
 
                                        if (i > 0)
150
 
                                                maxval = ((510 * maxval) + abuf[i] + abuf[i-1]) / 512;
151
 
                                        else
152
 
                                                maxval = ((510 * maxval) + abuf[i] + abuf[i+1]) / 512;
153
 
 
154
 
                                        if (maxval < avg) maxval = avg + 1;
155
 
 
156
 
 
157
 
                        }
158
 
                        else{
159
 
                                        if (i > 0)
160
 
                                                minval = ((510 * minval) + abuf[i] + abuf[i-1]) / 512 ;
161
 
                                        else
162
 
                                                minval = ((510 * minval) + abuf[i] + abuf[i+1]) / 512 ;
163
 
 
164
 
                                        if (minval >= avg) minval = avg - 1;
165
 
                        }
166
 
 
167
 
                }
168
 
                retval = (maxval - minval);
169
 
                if (retval < 0.0) retval = 0.0;
170
 
        }
171
 
        mvprintw(23, 5, "               ");
172
 
 
173
 
        mvprintw(23,5, "%4.0f", retval);
174
 
        refresh();
175
 
 
176
 
        retval = rescale (retval);
177
 
 
178
 
return (retval);
 
135
float get_audio_sample(void)
 
136
{
 
137
 
 
138
    int rc = 0;                 /* Return value from subs */
 
139
    static float avg = 128.0;
 
140
    static float maxval = 0;
 
141
    static float minval = 0;
 
142
    static float retval = 0.0;
 
143
    unsigned char abuf[ABUFSIZE];       /* Audio data buffer */
 
144
    int i, k;
 
145
 
 
146
    for (k = 0; k < 4; k++) {
 
147
        if ((rc = read(afd, abuf, ABUFSIZE)) == -1) {
 
148
            perror("audio read");
 
149
            exit(errno);
 
150
        }
 
151
 
 
152
        for (i = 0; i < rc; i++)        // calculate average
 
153
        {
 
154
            if ((maxval - minval) != 0.0) {
 
155
                if (i > 2)
 
156
                    avg =
 
157
                        avg + (abuf[i] + abuf[i - 1] + abuf[i - 2] +
 
158
                               abuf[i - 3]) / 5;
 
159
                else
 
160
                    avg =
 
161
                        avg + (abuf[i] + abuf[i + 1] + abuf[i + 2] +
 
162
                               abuf[i + 3]) / 5;
 
163
            }
 
164
            if (avg >= 188.0)
 
165
                avg = 128.0;
 
166
            if (avg <= 60.0)
 
167
                avg = 128.0;
 
168
 
 
169
        }
 
170
        for (i = 0; i < rc; i++)        // calculate maximum avg value
 
171
        {
 
172
            if (abuf[i] >= avg) {
 
173
                if (i > 0)
 
174
                    maxval =
 
175
                        ((510 * maxval) + abuf[i] + abuf[i - 1]) / 512;
 
176
                else
 
177
                    maxval =
 
178
                        ((510 * maxval) + abuf[i] + abuf[i + 1]) / 512;
 
179
 
 
180
                if (maxval < avg)
 
181
                    maxval = avg + 1;
 
182
 
 
183
            } else {
 
184
                if (i > 0)
 
185
                    minval =
 
186
                        ((510 * minval) + abuf[i] + abuf[i - 1]) / 512;
 
187
                else
 
188
                    minval =
 
189
                        ((510 * minval) + abuf[i] + abuf[i + 1]) / 512;
 
190
 
 
191
                if (minval >= avg)
 
192
                    minval = avg - 1;
 
193
            }
 
194
 
 
195
        }
 
196
        retval = (maxval - minval);
 
197
        if (retval < 0.0)
 
198
            retval = 0.0;
 
199
    }
 
200
    mvprintw(23, 5, "               ");
 
201
 
 
202
    mvprintw(23, 5, "%4.0f", retval);
 
203
    refreshp();
 
204
 
 
205
    retval = rescale(retval);
 
206
 
 
207
    return (retval);
179
208
}
180
209
 
181
210
/* ----------make bar for s meter ------------*/
182
211
 
183
 
int make_bar(int xpos, int ypos, int yheight, unsigned int value, int bar_type){
184
 
 
185
 
int i;
186
 
 
187
 
if (bar_type == S_BAR) {
 
212
int make_bar(int xpos, int ypos, int yheight, unsigned int value,
 
213
             int bar_type)
 
214
{
 
215
 
 
216
    int i;
 
217
 
 
218
    if (bar_type == S_BAR) {
188
219
        for (i = 0; i < yheight; i++)
189
 
                mvprintw(ypos - i, xpos, " ");
190
 
}
 
220
            mvprintw(ypos - i, xpos, " ");
 
221
    }
191
222
 
192
223
/* Make the bar */
193
224
 
194
 
if (bar_type == S_BAR || bar_type == PAN_BAR) {
195
 
        for (i = 0; i < value && i < 20 ; i++)
196
 
                mvprintw(ypos - i, xpos, "#");
197
 
}
198
 
else
199
 
                mvprintw(21 - value, xpos , "@");
200
 
 
201
 
refresh();
202
 
 
203
 
 
204
 
return(0);
 
225
    if (bar_type == S_BAR || bar_type == PAN_BAR) {
 
226
        for (i = 0; i < value && i < 20; i++)
 
227
            mvprintw(ypos - i, xpos, "#");
 
228
    } else
 
229
        mvprintw(21 - value, xpos, "@");
 
230
 
 
231
    refreshp();
 
232
 
 
233
    return (0);
205
234
}
206
235
 
207
236
/* ------------ draw noise bridge screen ----------*/
208
237
 
209
 
int draw_nb_screen(int xpos, int ypos, int yheight, int bar_type){
210
 
 
211
 
int i;
212
 
 
213
 
attroff(A_BOLD);
214
 
 
215
 
for (i = 0; i < 21; i++) {
 
238
int draw_nb_screen(int xpos, int ypos, int yheight, int bar_type)
 
239
{
 
240
 
 
241
    int i;
 
242
 
 
243
    attroff(A_BOLD);
 
244
 
 
245
    for (i = 0; i < 21; i++) {
216
246
        switch (i) {
217
 
                case 0 :
218
 
                case 20 :
219
 
                        mvprintw(ypos + i, xpos, "+---------+---------+---------+---------+---------+");
220
 
                        break;
221
 
                case 1 ... 4 :
222
 
                case 6 ... 9 :
223
 
                case 11 ... 14 :
224
 
                case 16 ... 19 :
225
 
                        mvprintw(ypos + i, xpos, "|    |    |    |    |    |    |    |    |    |    |");
226
 
                        break;
227
 
                case 5 :
228
 
                case 10 :
229
 
                case 15 :
 
247
        case 0:
 
248
        case 20:
 
249
            mvprintw(ypos + i, xpos,
 
250
                     "+---------+---------+---------+---------+---------+");
 
251
            break;
 
252
        case 1 ... 4:
 
253
        case 6 ... 9:
 
254
        case 11 ... 14:
 
255
        case 16 ... 19:
 
256
            mvprintw(ypos + i, xpos,
 
257
                     "|    |    |    |    |    |    |    |    |    |    |");
 
258
            break;
 
259
        case 5:
 
260
        case 10:
 
261
        case 15:
230
262
 
231
 
                        mvprintw(ypos + i, xpos, "+----+----+----+----+----+----+----+----+----+----+");
 
263
            mvprintw(ypos + i, xpos,
 
264
                     "+----+----+----+----+----+----+----+----+----+----+");
232
265
 
233
266
        }
234
 
}
235
 
 
236
 
attron(A_BOLD);
237
 
 
238
 
mvprintw(ypos + 1, 2, "%2d-", 0);       // 0
239
 
mvprintw(ypos + 3, 2, "%2d-", 3);       // 3
240
 
mvprintw(ypos + 5, 2, "%2d-", 6);       // 6
241
 
mvprintw(ypos + 10, 2, "%2d-", 10);
242
 
mvprintw(ypos + 15, 2, "%2d-", 20);     // 20
243
 
mvprintw(ypos + 20, 2, "%2d-", 40);
244
 
 
245
 
return(0);
246
 
}
247
 
 
248
 
 
 
267
    }
 
268
 
 
269
    attron(A_BOLD);
 
270
 
 
271
    mvprintw(ypos + 1, 2, "%2d-", 0);   // 0
 
272
    mvprintw(ypos + 3, 2, "%2d-", 3);   // 3
 
273
    mvprintw(ypos + 5, 2, "%2d-", 6);   // 6
 
274
    mvprintw(ypos + 10, 2, "%2d-", 10);
 
275
    mvprintw(ypos + 15, 2, "%2d-", 20); // 20
 
276
    mvprintw(ypos + 20, 2, "%2d-", 40);
 
277
 
 
278
    return (0);
 
279
}
249
280
 
250
281
/* ------------ draw scanner screen ----------*/
251
282
 
252
 
int drawscreen(int xpos, int ypos, int yheight, int bar_type){
253
 
 
254
 
int i;
255
 
 
256
 
attroff(A_BOLD);
257
 
 
258
 
for (i = 0; i < 21; i++) {
 
283
int drawscreen(int xpos, int ypos, int yheight, int bar_type)
 
284
{
 
285
 
 
286
    int i;
 
287
 
 
288
    attroff(A_BOLD);
 
289
 
 
290
    for (i = 0; i < 21; i++) {
259
291
        switch (i) {
260
 
                case 0 :
261
 
                case 20 :
262
 
                        mvprintw(ypos + i, xpos, "+---------+---------+---------+---------+---------+");
263
 
                        break;
264
 
                case 1 ... 4 :
265
 
                case 6 ... 9 :
266
 
                case 11 ... 14 :
267
 
                case 16 ... 19 :
268
 
                        mvprintw(ypos + i, xpos, "|    |    |    |    |    |    |    |    |    |    |");
269
 
                        break;
270
 
                case 5 :
271
 
                case 10 :
272
 
                case 15 :
 
292
        case 0:
 
293
        case 20:
 
294
            mvprintw(ypos + i, xpos,
 
295
                     "+---------+---------+---------+---------+---------+");
 
296
            break;
 
297
        case 1 ... 4:
 
298
        case 6 ... 9:
 
299
        case 11 ... 14:
 
300
        case 16 ... 19:
 
301
            mvprintw(ypos + i, xpos,
 
302
                     "|    |    |    |    |    |    |    |    |    |    |");
 
303
            break;
 
304
        case 5:
 
305
        case 10:
 
306
        case 15:
273
307
 
274
 
                        mvprintw(ypos + i, xpos, "+----+----+----+----+----+----+----+----+----+----+");
 
308
            mvprintw(ypos + i, xpos,
 
309
                     "+----+----+----+----+----+----+----+----+----+----+");
275
310
 
276
311
        }
277
 
}
278
 
 
279
 
attron(A_BOLD);
280
 
 
281
 
mvprintw(ypos + 1, 2, "%2d-", 20);
282
 
mvprintw(ypos + 3, 2, "%2d-", 10);
283
 
mvprintw(ypos + 5, 2, "%2d-", 9);
284
 
mvprintw(ypos + 7, 2, "%2d-", 8);
285
 
mvprintw(ypos + 9, 2, "%2d-", 7);
286
 
mvprintw(ypos + 11, 2, "%2d-", 6);
287
 
mvprintw(ypos + 13, 2, "%2d-", 5);
288
 
mvprintw(ypos + 15, 2, "%2d-", 4);
289
 
mvprintw(ypos + 17, 2, "%2d-", 3);
290
 
mvprintw(ypos + 19, 2, "%2d-", 2);
291
 
 
292
 
return(0);
 
312
    }
 
313
 
 
314
    attron(A_BOLD);
 
315
 
 
316
    mvprintw(ypos + 1, 2, "%2d-", 20);
 
317
    mvprintw(ypos + 3, 2, "%2d-", 10);
 
318
    mvprintw(ypos + 5, 2, "%2d-", 9);
 
319
    mvprintw(ypos + 7, 2, "%2d-", 8);
 
320
    mvprintw(ypos + 9, 2, "%2d-", 7);
 
321
    mvprintw(ypos + 11, 2, "%2d-", 6);
 
322
    mvprintw(ypos + 13, 2, "%2d-", 5);
 
323
    mvprintw(ypos + 15, 2, "%2d-", 4);
 
324
    mvprintw(ypos + 17, 2, "%2d-", 3);
 
325
    mvprintw(ypos + 19, 2, "%2d-", 2);
 
326
 
 
327
    return (0);
293
328
}
294
329
 
295
330
/* ------------ draw S meter screen ----------*/
296
331
 
297
 
int drawSmeter(int xpos, int ypos, int yheight, float testvalue){
298
 
 
299
 
extern int use_rxvt;
300
 
 
301
 
int i;
302
 
 
303
 
for (i = 0; i < 21; i++) {
 
332
int drawSmeter(int xpos, int ypos, int yheight, float testvalue)
 
333
{
 
334
 
 
335
    extern int use_rxvt;
 
336
 
 
337
    int i;
 
338
 
 
339
    for (i = 0; i < 21; i++) {
304
340
        switch (i) {
305
 
                case 0 :
306
 
                case 20 :
307
 
                        mvprintw(ypos + i, xpos, "+---+");
308
 
                        break;
309
 
                case 1 ... 4 :
310
 
                case 6 ... 19 :
311
 
                        mvprintw(ypos + i, xpos, "|   |");
312
 
                        break;
313
 
                case 5 :
314
 
                        if (use_rxvt == 0) attron(COLOR_PAIR(COLOR_GREEN) | A_BOLD | A_STANDOUT);
315
 
                        else  attron(COLOR_PAIR(COLOR_GREEN) | A_STANDOUT);
316
 
 
317
 
                        mvprintw(ypos + i, xpos, ">   <");
318
 
 
319
 
                        if (use_rxvt == 0) attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
320
 
                        else  attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
 
341
        case 0:
 
342
        case 20:
 
343
            mvprintw(ypos + i, xpos, "+---+");
 
344
            break;
 
345
        case 1 ... 4:
 
346
        case 6 ... 19:
 
347
            mvprintw(ypos + i, xpos, "|   |");
 
348
            break;
 
349
        case 5:
 
350
            if (use_rxvt == 0)
 
351
                attron(COLOR_PAIR(COLOR_GREEN) | A_BOLD | A_STANDOUT);
 
352
            else
 
353
                attron(COLOR_PAIR(COLOR_GREEN) | A_STANDOUT);
 
354
 
 
355
            mvprintw(ypos + i, xpos, ">   <");
 
356
 
 
357
            if (use_rxvt == 0)
 
358
                attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
 
359
            else
 
360
                attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
321
361
        }
322
 
}
323
 
 
324
 
mvprintw(ypos + 1, 3, "%2d", 20);
325
 
mvprintw(ypos + 3, 3, "%2d", 10);
326
 
mvprintw(ypos + 5, 3, "%2d", 9);
327
 
mvprintw(ypos + 7, 3, "%2d", 8);
328
 
mvprintw(ypos + 9, 3, "%2d", 7);
329
 
mvprintw(ypos + 11, 3, "%2d", 6);
330
 
mvprintw(ypos + 13, 3, "%2d", 5);
331
 
mvprintw(ypos + 15, 3, "%2d", 4);
332
 
mvprintw(ypos + 17, 3, "%2d", 3);
333
 
mvprintw(ypos + 19, 3, "%2d", 2);
334
 
 
335
 
    make_bar(7, 20, 20, (int) testvalue  , S_BAR);
336
 
 
337
 
refresh();
338
 
 
339
 
return(0);
 
362
    }
 
363
 
 
364
    mvprintw(ypos + 1, 3, "%2d", 20);
 
365
    mvprintw(ypos + 3, 3, "%2d", 10);
 
366
    mvprintw(ypos + 5, 3, "%2d", 9);
 
367
    mvprintw(ypos + 7, 3, "%2d", 8);
 
368
    mvprintw(ypos + 9, 3, "%2d", 7);
 
369
    mvprintw(ypos + 11, 3, "%2d", 6);
 
370
    mvprintw(ypos + 13, 3, "%2d", 5);
 
371
    mvprintw(ypos + 15, 3, "%2d", 4);
 
372
    mvprintw(ypos + 17, 3, "%2d", 3);
 
373
    mvprintw(ypos + 19, 3, "%2d", 2);
 
374
 
 
375
    make_bar(7, 20, 20, (int) testvalue, S_BAR);
 
376
 
 
377
    refreshp();
 
378
 
 
379
    return (0);
340
380
}
341
381
 
342
382
/* ------------------ Panoramic scan -------------------- */
343
383
 
344
 
int panscan (void) {
 
384
int panscan(void)
 
385
{
345
386
 
346
 
extern int use_rxvt;
 
387
    extern int use_rxvt;
347
388
#ifdef HAVE_LIBHAMLIB
348
 
extern freq_t outfreq;
 
389
    extern freq_t outfreq;
349
390
#else
350
 
extern int outfreq;
 
391
    extern int outfreq;
351
392
#endif
352
393
 
353
 
int j, key = 0;
354
 
float testvalue;
355
 
float FromFrequency = 0.0;
356
 
float FrequencyStep = 0.0;
357
 
float frequencies[51];
 
394
    int rc, j, key = 0;
 
395
    float testvalue;
 
396
    float FromFrequency = 0.0;
 
397
    float FrequencyStep = 0.0;
 
398
    float frequencies[51];
358
399
 
359
 
while (1) {
 
400
    while (1) {
360
401
        key = 0;
361
 
        if (use_rxvt == 0) attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
362
 
        else  attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
 
402
        if (use_rxvt == 0)
 
403
            attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
 
404
        else
 
405
            attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
363
406
 
364
407
        for (j = 0; j <= 24; j++)
365
 
                mvprintw(j,0,"                                                                                ");
 
408
            mvprintw(j, 0,
 
409
                     "                                                                                ");
366
410
 
367
411
        drawscreen(5, 1, 21, 0);
368
412
 
369
 
        mvprintw (1, 60, "- PANORAMIC SCAN -");
370
 
        mvprintw (5, 60, "Frequency: ");
371
 
        refresh();
 
413
        mvprintw(1, 60, "- PANORAMIC SCAN -");
 
414
        mvprintw(5, 60, "Frequency: ");
 
415
        refreshp();
372
416
        echo();
373
 
        scanf("%f",  &FromFrequency);
 
417
        rc = scanf("%f", &FromFrequency);
374
418
        noecho();
375
 
        mvprintw (5, 72, "%5.1f", FromFrequency);
376
 
        mvprintw (22, 1, "%5.1f", FromFrequency);
377
 
        refresh();
378
 
        mvprintw (7, 60, "Step (kHz): ");
379
 
        refresh();
380
 
        scanf("%f",  &FrequencyStep);
381
 
        mvprintw (7, 72, "%5.1f", FrequencyStep);
382
 
        refresh();
 
419
        mvprintw(5, 72, "%5.1f", FromFrequency);
 
420
        mvprintw(22, 1, "%5.1f", FromFrequency);
 
421
        refreshp();
 
422
        mvprintw(7, 60, "Step (kHz): ");
 
423
        refreshp();
 
424
        rc = scanf("%f", &FrequencyStep);
 
425
        mvprintw(7, 72, "%5.1f", FrequencyStep);
 
426
        refreshp();
383
427
 
384
 
        for (j=0; j<51; j++) {
385
 
                frequencies [j] = FromFrequency + j * FrequencyStep;
386
 
                switch (j) {
387
 
                        case 10 :
388
 
                        case 20 :
389
 
                        case 30 :
390
 
                        case 40 :
391
 
                        case 50 :
392
 
                                mvprintw(22, j+1, "%5.1f", frequencies[j]);
393
 
                                break;
394
 
                        default :
395
 
                                ;
396
 
                }
 
428
        for (j = 0; j < 51; j++) {
 
429
            frequencies[j] = FromFrequency + j * FrequencyStep;
 
430
            switch (j) {
 
431
            case 10:
 
432
            case 20:
 
433
            case 30:
 
434
            case 40:
 
435
            case 50:
 
436
                mvprintw(22, j + 1, "%5.1f", frequencies[j]);
 
437
                break;
 
438
            default:
 
439
                ;
 
440
            }
397
441
 
398
442
        }
399
 
        refresh();
400
 
 
401
 
 
402
 
        /* ------------- scan ---------------------*/
403
 
 
404
 
        for (j=0; j<5; j++)
405
 
                testvalue = get_audio_sample();
406
 
 
407
 
        for (j=0; j < 51; j++) {
408
 
 
409
 
        int i;
410
 
 
411
 
                for (i = 0; i < 100; i++){
412
 
                        if (outfreq == 0) break;
413
 
                        usleep(10000);
414
 
                }
 
443
        refreshp();
 
444
 
 
445
        /* ------------- scan --------------------- */
 
446
 
 
447
        for (j = 0; j < 5; j++)
 
448
            testvalue = get_audio_sample();
 
449
 
 
450
        for (j = 0; j < 51; j++) {
 
451
 
 
452
            int i;
 
453
 
 
454
            for (i = 0; i < 100; i++) {
 
455
                if (outfreq == 0)
 
456
                    break;
 
457
                usleep(10000);
 
458
            }
415
459
 
416
460
#ifdef HAVE_LIBHAMLIB
417
 
                outfreq = (freq_t) (frequencies[j] * 1000) ;
 
461
            outfreq = (freq_t) (frequencies[j] * 1000);
418
462
#else
419
 
                outfreq = (int) (frequencies[j] * 1000) ;
 
463
            outfreq = (int) (frequencies[j] * 1000);
420
464
#endif
421
465
 
422
 
                usleep(50 * 1000);
423
 
                testvalue = get_audio_sample();
424
 
 
425
 
                make_bar(5 + j, 20, 20, (int) testvalue , PAN_BAR);
426
 
 
427
 
                nodelay(stdscr, TRUE);
428
 
                key = getch();
429
 
                nodelay(stdscr, FALSE);
430
 
                if (key == 27 || key ==  '\n') break;
431
 
 
432
 
        } // end for
433
 
 
434
 
 
435
 
        /* -----------end scan --------------------*/
436
 
                mvprintw (23,60, "----   Key?  ----");
437
 
 
438
 
                j = getch();
439
 
                if ( j == 27) break;
440
 
} // end while
441
 
 
442
 
return (0);
 
466
            usleep(50 * 1000);
 
467
            testvalue = get_audio_sample();
 
468
 
 
469
            make_bar(5 + j, 20, 20, (int) testvalue, PAN_BAR);
 
470
 
 
471
            nodelay(stdscr, TRUE);
 
472
            key = getch();
 
473
            nodelay(stdscr, FALSE);
 
474
            if (key == 27 || key == '\n')
 
475
                break;
 
476
 
 
477
        }                       // end for
 
478
 
 
479
        /* -----------end scan -------------------- */
 
480
        mvprintw(23, 60, "----   Key?  ----");
 
481
 
 
482
        j = getch();
 
483
        if (j == 27)
 
484
            break;
 
485
    }                           // end while
 
486
 
 
487
    return (0);
443
488
}
444
489
 
445
490
/* ------------------ Noise bridge scan -------------------- */
446
491
 
447
 
int nbscan (void) {
 
492
int nbscan(void)
 
493
{
448
494
 
449
 
extern int use_rxvt;
 
495
    extern int use_rxvt;
450
496
#ifdef HAVE_LIBHAMLIB
451
 
extern freq_t outfreq;
 
497
    extern freq_t outfreq;
452
498
#else
453
 
extern int outfreq;
 
499
    extern int outfreq;
454
500
#endif
455
501
 
456
 
int j, key = 0;
457
 
float testvalue;
458
 
float FromFrequency = 0.0;
459
 
float FrequencyStep = 0.0;
460
 
float frequencies[51];
461
 
float values[51];
 
502
    int rc, j, key = 0;
 
503
    float testvalue;
 
504
    float FromFrequency = 0.0;
 
505
    float FrequencyStep = 0.0;
 
506
    float frequencies[51];
 
507
    float values[51];
462
508
 
463
 
while (1) {
 
509
    while (1) {
464
510
        key = 0;
465
 
        if (use_rxvt == 0) attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
466
 
        else  attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
467
 
 
468
 
        for (j = 0; j <= 24; j++)                                       // wipe the screen
469
 
                mvprintw(j,0,"                                                                                ");
470
 
 
471
 
        draw_nb_screen(5, 1, 21, 0);                            // draw the grid
472
 
 
473
 
        mvprintw (1, 60, "- NOISE BRIDGE -");           // get the parameters
474
 
        mvprintw (5, 60, "Frequency: ");
475
 
        refresh();
476
 
        scanf("%f",  &FromFrequency);
477
 
        mvprintw (5, 72, "%5.1f", FromFrequency);
478
 
        mvprintw (22, 1, "%5.1f", FromFrequency);
479
 
        refresh();
480
 
        mvprintw (7, 60, "Step (kHz): ");
481
 
        refresh();
482
 
        scanf("%f",  &FrequencyStep);
483
 
        mvprintw (7, 72, "%5.1f", FrequencyStep);
484
 
        refresh();
485
 
 
486
 
        for (j=0; j<51; j++) {                                          // draw the X scale
487
 
                frequencies [j] = FromFrequency + j * FrequencyStep;
488
 
                switch (j) {
489
 
                        case 10 :
490
 
                        case 20 :
491
 
                        case 30 :
492
 
                        case 40 :
493
 
                        case 50 :
494
 
                                mvprintw(22, j+1, "%5.1f", frequencies[j]);
495
 
                                break;
496
 
                        default :
497
 
                                ;
498
 
                }
 
511
        if (use_rxvt == 0)
 
512
            attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
 
513
        else
 
514
            attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
 
515
 
 
516
        for (j = 0; j <= 24; j++)       // wipe the screen
 
517
            mvprintw(j, 0,
 
518
                     "                                                                                ");
 
519
 
 
520
        draw_nb_screen(5, 1, 21, 0);    // draw the grid
 
521
 
 
522
        mvprintw(1, 60, "- NOISE BRIDGE -");    // get the parameters
 
523
        mvprintw(5, 60, "Frequency: ");
 
524
        refreshp();
 
525
        rc = scanf("%f", &FromFrequency);
 
526
        mvprintw(5, 72, "%5.1f", FromFrequency);
 
527
        mvprintw(22, 1, "%5.1f", FromFrequency);
 
528
        refreshp();
 
529
        mvprintw(7, 60, "Step (kHz): ");
 
530
        refreshp();
 
531
        rc = scanf("%f", &FrequencyStep);
 
532
        mvprintw(7, 72, "%5.1f", FrequencyStep);
 
533
        refreshp();
 
534
 
 
535
        for (j = 0; j < 51; j++) {      // draw the X scale
 
536
            frequencies[j] = FromFrequency + j * FrequencyStep;
 
537
            switch (j) {
 
538
            case 10:
 
539
            case 20:
 
540
            case 30:
 
541
            case 40:
 
542
            case 50:
 
543
                mvprintw(22, j + 1, "%5.1f", frequencies[j]);
 
544
                break;
 
545
            default:
 
546
                ;
 
547
            }
499
548
 
500
549
        }
501
 
        refresh();
502
 
 
503
 
 
504
 
        /* ------------- scan ---------------------*/
505
 
 
506
 
        for (j=0; j<5; j++)
507
 
                testvalue = get_audio_sample();
508
 
 
509
 
 
510
 
        for (j=0; j < 51; j++) {
511
 
 
512
 
        int i;
513
 
 
514
 
                for (i = 0; i < 100; i++){
515
 
                        if (outfreq == 0) break;
516
 
                        usleep(10000);
517
 
                }
 
550
        refreshp();
 
551
 
 
552
        /* ------------- scan --------------------- */
 
553
 
 
554
        for (j = 0; j < 5; j++)
 
555
            testvalue = get_audio_sample();
 
556
 
 
557
        for (j = 0; j < 51; j++) {
 
558
 
 
559
            int i;
 
560
 
 
561
            for (i = 0; i < 100; i++) {
 
562
                if (outfreq == 0)
 
563
                    break;
 
564
                usleep(10000);
 
565
            }
518
566
#ifdef HAVE_LIBHAMLIB
519
 
                outfreq = (freq_t) (frequencies[j] * 1000) ;
 
567
            outfreq = (freq_t) (frequencies[j] * 1000);
520
568
#else
521
 
                outfreq = (int) (frequencies[j] * 1000) ;
 
569
            outfreq = (int) (frequencies[j] * 1000);
522
570
#endif
523
 
                usleep(50 * 1000);
524
 
                testvalue = get_audio_sample();
525
 
                values[j] = testvalue;
526
 
                if (j > 0)
527
 
                        testvalue =  (values[j-1] + values[j]) / 2;
528
 
 
529
 
                make_bar(5 + j, 20, 20, (int) testvalue , SPOT_BAR);
530
 
 
531
 
                nodelay(stdscr, TRUE);
532
 
                key = getch();
533
 
                nodelay(stdscr, FALSE);
534
 
                if (key == 27 || key ==  '\n') break;
535
 
 
536
 
        } // end for
537
 
 
538
 
 
539
 
        /* -----------end scan --------------------*/
540
 
                mvprintw (23,60, "----   Key?  ----");
541
 
 
542
 
                j = getch();
543
 
                if ( j == 27) break;
544
 
} // end while
545
 
 
546
 
return (0);
 
571
            usleep(50 * 1000);
 
572
            testvalue = get_audio_sample();
 
573
            values[j] = testvalue;
 
574
            if (j > 0)
 
575
                testvalue = (values[j - 1] + values[j]) / 2;
 
576
 
 
577
            make_bar(5 + j, 20, 20, (int) testvalue, SPOT_BAR);
 
578
 
 
579
            nodelay(stdscr, TRUE);
 
580
            key = getch();
 
581
            nodelay(stdscr, FALSE);
 
582
            if (key == 27 || key == '\n')
 
583
                break;
 
584
 
 
585
        }                       // end for
 
586
 
 
587
        /* -----------end scan -------------------- */
 
588
        mvprintw(23, 60, "----   Key?  ----");
 
589
 
 
590
        j = getch();
 
591
        if (j == 27)
 
592
            break;
 
593
    }                           // end while
 
594
 
 
595
    return (0);
547
596
}
548
597
 
549
 
 
550
 
void scanmenu(void){
551
 
 
552
 
extern int use_rxvt;
553
 
 
554
 
int j;
555
 
 
556
 
if (use_rxvt == 0) attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
557
 
else  attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
558
 
 
559
 
for (j = 0; j <= 24; j++)
560
 
        mvprintw(j,0,"                                                                                ");
561
 
 
562
 
mvprintw (1, 20, "--- TLF SCANNER UTILITY ---");
563
 
mvprintw (6, 20, "0.: Calibrate S-meter on S9 !");
564
 
mvprintw (8, 20, "1.: Panorama scan");
565
 
mvprintw (9, 20, "2.: Noise bridge scan");
 
598
void scanmenu(void)
 
599
{
 
600
 
 
601
    extern int use_rxvt;
 
602
 
 
603
    int j;
 
604
 
 
605
    if (use_rxvt == 0)
 
606
        attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
 
607
    else
 
608
        attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
 
609
 
 
610
    for (j = 0; j <= 24; j++)
 
611
        mvprintw(j, 0,
 
612
                 "                                                                                ");
 
613
 
 
614
    mvprintw(1, 20, "--- TLF SCANNER UTILITY ---");
 
615
    mvprintw(6, 20, "0.: Calibrate S-meter on S9 !");
 
616
    mvprintw(8, 20, "1.: Panorama scan");
 
617
    mvprintw(9, 20, "2.: Noise bridge scan");
566
618
//mvprintw (10, 20, "3.: Channel scan (n.a.)");
567
619
//mvprintw (11, 20, "4.: Beacon scan (n.a.)");
568
 
mvprintw (11, 20, "ESC: Exit scan function");
 
620
    mvprintw(11, 20, "ESC: Exit scan function");
569
621
 
570
 
mvprintw(23,20," --- Press a key to continue --- ");
571
 
refresh();
 
622
    mvprintw(23, 20, " --- Press a key to continue --- ");
 
623
    refreshp();
572
624
 
573
625
}
574
626
 
575
627
/* -------------------main test routine ------- */
576
628
 
577
 
int testaudio() {
578
 
 
579
 
float testvalue;
580
 
char key = '\0';
581
 
int runnit = 1;
582
 
 
583
 
clear();
584
 
 
585
 
scanmenu();
 
629
int testaudio()
 
630
{
 
631
 
 
632
    float testvalue;
 
633
    char key = '\0';
 
634
    int runnit = 1;
 
635
 
 
636
    clear();
 
637
 
 
638
    scanmenu();
586
639
 
587
640
/* ------------initialize sound card --------*/
588
 
init_audio();
 
641
    init_audio();
589
642
 
590
 
while (runnit == 1) {
 
643
    while (runnit == 1) {
591
644
 
592
645
        testvalue = get_audio_sample();
593
646
 
599
652
 
600
653
        switch (key) {
601
654
 
602
 
                case '1' :
603
 
                        panscan();
604
 
                        scanmenu();
605
 
                        break;
606
 
                case '2' :
607
 
                        nbscan();
608
 
                        scanmenu();
609
 
                        break;
610
 
 
611
 
                case 27 :
612
 
                        runnit = 0;
613
 
        }
614
 
}
615
 
 
616
 
close_audio();
617
 
clear();
618
 
 
619
 
return (0);
620
 
}
621
 
 
622
 
void recordmenue (void) {
623
 
 
624
 
extern int use_rxvt;
625
 
 
626
 
int j;
627
 
 
628
 
if (use_rxvt == 0) attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
629
 
else  attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
630
 
 
631
 
for (j = 0; j <= 24; j++)
632
 
        mvprintw(j,0,"                                                                                ");
633
 
 
634
 
mvprintw (1, 20, "--- TLF SOUND RECORDER UTILITY ---");
635
 
mvprintw (6, 20, "F1 ... F12, S, C: Record Messages");
636
 
 
637
 
mvprintw (9, 20, "1.: Enable contest recorder");
638
 
mvprintw (10, 20, "2.: Disable contest recorder");
639
 
mvprintw (11,20, "3.: Play back file");
640
 
mvprintw (13, 20, "ESC: Exit sound recorder function");
641
 
 
642
 
refresh();
643
 
 
644
 
}
645
 
/*--------------------------------------------------------------------------------------*/
646
 
void record (void) {
647
 
 
648
 
extern char ph_message[14][80];
649
 
 
650
 
int runnit = 1, key, i=0, j = 4;
651
 
char commands[80] = "";
652
 
char playbackfile[40];
653
 
char printname[7];
654
 
DIR *sounddir;
655
 
struct dirent *soundfilename;
656
 
 
657
 
        recordmenue();
658
 
 
659
 
        while (runnit == 1) {
660
 
 
661
 
                nodelay(stdscr, TRUE);
662
 
                key = onechar();
663
 
                nodelay(stdscr, FALSE);
664
 
 
665
 
                switch (key) {
666
 
 
667
 
                        case 129 :
668
 
                                mvprintw(15,20, "recording %s", ph_message[0]);
669
 
                                mvprintw(16,20, "");
670
 
                                refresh();
671
 
                                strcpy(commands,"rec -w -r 8000 -d ");
672
 
                                strcat(commands, sc_device);
673
 
                                strcat(commands, " ");                  // (W9WI)
674
 
                                strcat(commands, ph_message[0]);
675
 
                                system (commands);
676
 
                                runnit = 0;
677
 
                                break;
678
 
                        case 130 :
679
 
                                mvprintw(15,20, "recording %s", ph_message[1]);
680
 
                                mvprintw(16,20, "");
681
 
                                refresh();
682
 
 
683
 
                                strcpy(commands,"rec -w -r 8000 -d ");
684
 
                                strcat(commands, sc_device);
685
 
                                strcat(commands, " ");                  // (W9WI)
686
 
                                strcat(commands, ph_message[1]);
687
 
                                system (commands);
688
 
                                runnit = 0;
689
 
                                break;
690
 
                        case 131 :
691
 
                                mvprintw(15,20, "recording %s", ph_message[2]);
692
 
                                mvprintw(16,20, "");
693
 
                                refresh();
694
 
                                strcpy(commands,"rec -w -r 8000 -d ");
695
 
                                strcat(commands, sc_device);
696
 
                                strcat(commands, " ");                  // (W9WI)
697
 
                                strcat(commands, ph_message[2]);
698
 
                                system (commands);
699
 
                                runnit = 0;
700
 
                                break;
701
 
                        case 132 :
702
 
                                mvprintw(15,20, "recording %s", ph_message[3]);
703
 
                                mvprintw(16,20, "");
704
 
                                refresh();
705
 
                                strcpy(commands,"rec -w -r 8000 -d ");
706
 
                                strcat(commands, sc_device);
707
 
                                strcat(commands, " ");                  // (W9WI)
708
 
                                strcat(commands, ph_message[3]);
709
 
                                system (commands);
710
 
                                runnit = 0;
711
 
                                break;
712
 
                        case 133 :
713
 
                                mvprintw(15,20, "recording %s", ph_message[4]);
714
 
                                mvprintw(16,20, "");
715
 
                                refresh();
716
 
                                strcpy(commands,"rec -w -r 8000 -d ");
717
 
                                strcat(commands, sc_device);
718
 
                                strcat(commands, " ");                          // (W9WI)
719
 
                                strcat(commands, ph_message[4]);
720
 
                                system (commands);
721
 
                                runnit = 0;
722
 
                                break;
723
 
                        case 134 :
724
 
                                mvprintw(15,20, "recording %s", ph_message[5]);
725
 
                                mvprintw(16,20, "");
726
 
                                refresh();
727
 
                                strcpy(commands,"rec -w -r 8000 -d ");
728
 
                                strcat(commands, sc_device);
729
 
                                strcat(commands, " ");                          // (W9WI)
730
 
                                strcat(commands, ph_message[5]);
731
 
                                system (commands);
732
 
                                runnit = 0;
733
 
                                break;
734
 
                        case 135 :
735
 
                                mvprintw(15,20, "recording %s", ph_message[6]);
736
 
                                mvprintw(16,20, "");
737
 
                                refresh();
738
 
                                strcpy(commands,"rec -w -r 8000 -d ");
739
 
                                strcat(commands, sc_device);
740
 
                                strcat(commands, " ");                          // (W9WI)
741
 
                                strcat(commands, ph_message[6]);
742
 
                                system (commands);
743
 
                                runnit = 0;
744
 
                                break;
745
 
                        case 136 :
746
 
                                mvprintw(15,20, "recording %s", ph_message[7]);
747
 
                                mvprintw(16,20, "");
748
 
                                refresh();
749
 
                                strcpy(commands,"rec -w -r 8000 -d ");
750
 
                                strcat(commands, sc_device);
751
 
                                strcat(commands, " ");                          // (W9WI)
752
 
                                strcat(commands, ph_message[7]);
753
 
                                system (commands);
754
 
                                runnit = 0;
755
 
                                break;
756
 
                        case 137 :
757
 
                                mvprintw(15,20, "recording %s", ph_message[8]);
758
 
                                mvprintw(16,20, "");
759
 
                                refresh();
760
 
                                strcpy(commands,"rec -w -r 8000 -d ");
761
 
                                strcat(commands, sc_device);
762
 
                                strcat(commands, " ");                          // (W9WI)
763
 
                                strcat(commands, ph_message[8]);
764
 
                                system (commands);
765
 
                                runnit = 0;
766
 
                                break;
767
 
                        case 138 :
768
 
                                mvprintw(15,20, "recording %s", ph_message[9]);
769
 
                                mvprintw(16,20, "");
770
 
                                refresh();
771
 
                                strcpy(commands,"rec -w -r 8000 -d ");
772
 
                                strcat(commands, sc_device);
773
 
                                strcat(commands, " ");                          // (W9WI)
774
 
                                strcat(commands, ph_message[9]);
775
 
                                system (commands);
776
 
                                runnit = 0;
777
 
                                break;
778
 
                        case 140 :
779
 
                                mvprintw(15,20, "recording %s", ph_message[10]);
780
 
                                mvprintw(16,20, "");
781
 
                                refresh();
782
 
                                strcpy(commands,"rec -w -r 8000 -d ");
783
 
                                strcat(commands, sc_device);
784
 
                                strcat(commands, " ");                          // (W9WI)
785
 
                                strcat(commands, ph_message[10]);
786
 
                                system (commands);
787
 
                                runnit = 0;
788
 
                                break;
789
 
                        case 141 :
790
 
                                mvprintw(15,20, "recording %s", ph_message[11]);
791
 
                                mvprintw(16,20, "");
792
 
                                refresh();
793
 
                                strcpy(commands,"rec -w -r 8000 -d ");
794
 
                                strcat(commands, sc_device);
795
 
                                strcat(commands, " ");                          // (W9WI)
796
 
                                strcat(commands, ph_message[11]);
797
 
                                system (commands);
798
 
                                runnit = 0;
799
 
                                break;
800
 
                        case 's' :
801
 
                        case 'S' :
802
 
                                mvprintw(15,20, "recording %s", ph_message[12]);
803
 
                                mvprintw(16,20, "");
804
 
                                refresh();
805
 
                                strcpy(commands,"rec -w -r 8000 -d ");
806
 
                                strcat(commands, sc_device);
807
 
                                strcat(commands, " ");                          // (W9WI)
808
 
                                strcat(commands, ph_message[12]);
809
 
                                system (commands);
810
 
                                runnit = 0;
811
 
                                break;
812
 
                        case 'c' :
813
 
                        case 'C' :
814
 
                                mvprintw(15,20, "recording %s", ph_message[13]);
815
 
                                mvprintw(16,20, "");
816
 
                                refresh();
817
 
                                strcpy(commands,"rec -w -r 8000 -d ");
818
 
                                strcat(commands, sc_device);
819
 
                                strcat(commands, " ");                          // (W9WI)
820
 
                                strcat(commands, ph_message[13]);
821
 
                                system (commands);
822
 
                                runnit = 0;
823
 
                                break;
824
 
                        case '1' :
825
 
                                system ("echo "" > ~/.VRlock");
826
 
 
827
 
                                system ("cd ~/tlf/soundlogs; ./soundlog  > /dev/null 2> /dev/null &");
828
 
 
829
 
                                mvprintw(15,20, "Contest recording enabled...");
830
 
                                refresh();
831
 
                                sleep(1);
832
 
                                runnit = 0;
833
 
                                break;
834
 
                        case '2' :
835
 
                                mvprintw(15,20, "Contest recording disabled...");
836
 
                                refresh();
837
 
                                sleep(1);
838
 
                                system ("rm ~/.VRlock");
839
 
                                system ("pkill -f soundlogs > /dev/null 2> /dev/null ");
840
 
                                runnit = 0;
841
 
                                break;
842
 
                        case '3' :
843
 
                                sounddir = opendir("$HOME/tlf/soundlogs/");             // (W9WI)
844
 
 
845
 
                                if (sounddir == NULL) break;
846
 
 
847
 
                                for (i = 4; i < 15; i++)
848
 
                                        mvprintw(i, 0, "                                                                                ");
849
 
 
850
 
                                mvprintw(4, 10, "");
851
 
 
852
 
                                for (i = 10; i <  81; i += 10) {
853
 
                                        soundfilename = readdir (sounddir);
854
 
                                        if (soundfilename== NULL)
855
 
                                                break;
856
 
                                        else {
857
 
                                                if (strstr(soundfilename->d_name, ".au") != NULL) {
858
 
                                                        if (i > 60) {
859
 
                                                                i = 10;
860
 
                                                                j++;
861
 
                                                        }
862
 
                                                        strncpy (printname, soundfilename->d_name, 6);
863
 
                                                        mvprintw(j,i , "%s", printname);
864
 
                                                        refresh();
865
 
 
866
 
                                                }else
867
 
                                                        if (i >= 10) i -= 10;
868
 
                                        }
869
 
                                }
870
 
                                closedir (sounddir);
871
 
 
872
 
                        case '4' :
873
 
 
874
 
                                mvprintw(15,20, "Play back file (ddhhmmxx): ");
875
 
                                refresh();
876
 
 
877
 
                                echo();
878
 
                                getnstr(playbackfile,  8);
879
 
                                noecho();
880
 
                                strcpy(commands, "play -d ");
881
 
                                strcat(commands, sc_device);
882
 
                                strcat(commands, " ~/tlf/soundlogs/");
883
 
                                if (strlen(playbackfile) > 6) {
884
 
                                        strncat (commands , playbackfile, 6);
885
 
                                        strcat (commands, ".au trim ");
886
 
                                        strcat (commands, playbackfile+6);
887
 
                                }else if (strlen(playbackfile) < 5) {
888
 
                                        strcat(commands, playbackfile);
889
 
                                        strcat(commands, "00.au");
890
 
                                }else {
891
 
                                        strcat(commands, playbackfile);
892
 
                                        strcat(commands, ".au");
893
 
                                }
894
 
                                mvprintw(16,20, "Use Ctrl-c to stop and return to tlf");
895
 
                                mvprintw(18,20, "");
896
 
                                refresh();
897
 
                                system (commands);
898
 
                                runnit=0;
899
 
                                break;
900
 
                        case 27 :
901
 
                                runnit = 0;
 
655
        case '1':
 
656
            panscan();
 
657
            scanmenu();
 
658
            break;
 
659
        case '2':
 
660
            nbscan();
 
661
            scanmenu();
 
662
            break;
 
663
 
 
664
        case 27:
 
665
            runnit = 0;
 
666
        }
 
667
    }
 
668
 
 
669
    close_audio();
 
670
    clear();
 
671
 
 
672
    return (0);
 
673
}
 
674
 
 
675
void recordmenue(void)
 
676
{
 
677
 
 
678
    extern int use_rxvt;
 
679
 
 
680
    int j;
 
681
 
 
682
    if (use_rxvt == 0)
 
683
        attron(COLOR_PAIR(COLOR_CYAN) | A_BOLD | A_STANDOUT);
 
684
    else
 
685
        attron(COLOR_PAIR(COLOR_CYAN) | A_STANDOUT);
 
686
 
 
687
    for (j = 0; j <= 24; j++)
 
688
        mvprintw(j, 0,
 
689
                 "                                                                                ");
 
690
 
 
691
    mvprintw(1, 20, "--- TLF SOUND RECORDER UTILITY ---");
 
692
    mvprintw(6, 20, "F1 ... F12, S, C: Record Messages");
 
693
 
 
694
    mvprintw(9, 20, "1.: Enable contest recorder");
 
695
    mvprintw(10, 20, "2.: Disable contest recorder");
 
696
    mvprintw(11, 20, "3.: Play back file");
 
697
    mvprintw(13, 20, "ESC: Exit sound recorder function");
 
698
 
 
699
    refreshp();
 
700
 
 
701
}
 
702
 
 
703
/*--------------------------------------------------------------------------*/
 
704
void do_record(int message_nr)
 
705
{
 
706
    extern char ph_message[14][80];
 
707
 
 
708
    int rc;
 
709
    char commands[80] = "";
 
710
 
 
711
    mvprintw(15, 20, "recording %s", ph_message[message_nr]);
 
712
    mvprintw(16, 20, "ESC to exit");
 
713
    mvprintw(17, 20, "");
 
714
    refreshp();
 
715
    strcpy(commands, "rec -r 8000 ");   //G4KNO
 
716
    strcat(commands, ph_message[message_nr]);
 
717
    strcat(commands, " -q &");  //G4KNO
 
718
    rc = system(commands);
 
719
    //G4KNO: Loop until <esc> keypress
 
720
    while (1) {
 
721
        if (getch() == 27) {
 
722
            //kill process (SIGINT=Ctrl-C).
 
723
            rc = system("pkill -SIGINT -n rec");
 
724
            break;
 
725
        }
 
726
    }
 
727
}
 
728
 
 
729
/*--------------------------------------------------------------------------*/
 
730
void record(void)
 
731
{
 
732
 
 
733
    extern char ph_message[14][80];
 
734
 
 
735
    int rc, runnit = 1, key, i = 0, j = 4;
 
736
    char commands[80] = "";
 
737
    char playbackfile[40];
 
738
    char printname[7];
 
739
    DIR *sounddir;
 
740
    struct dirent *soundfilename;
 
741
 
 
742
    recordmenue();
 
743
 
 
744
    while (runnit == 1) {
 
745
 
 
746
        nodelay(stdscr, TRUE);
 
747
        key = onechar();
 
748
        nodelay(stdscr, FALSE);
 
749
 
 
750
        switch (key) {
 
751
 
 
752
        case 129:
 
753
            do_record(0);
 
754
            runnit = 0;
 
755
            break;
 
756
        case 130:
 
757
            do_record(1);
 
758
            runnit = 0;
 
759
            break;
 
760
        case 131:
 
761
            do_record(2);
 
762
            runnit = 0;
 
763
            break;
 
764
        case 132:
 
765
            do_record(3);
 
766
            runnit = 0;
 
767
            break;
 
768
        case 133:
 
769
            do_record(4);
 
770
            runnit = 0;
 
771
            break;
 
772
        case 134:
 
773
            do_record(5);
 
774
            runnit = 0;
 
775
            break;
 
776
        case 135:
 
777
            do_record(6);
 
778
            runnit = 0;
 
779
            break;
 
780
        case 136:
 
781
            do_record(7);
 
782
            runnit = 0;
 
783
            break;
 
784
        case 137:
 
785
            do_record(8);
 
786
            runnit = 0;
 
787
            break;
 
788
        case 138:
 
789
            do_record(9);
 
790
            runnit = 0;
 
791
            break;
 
792
        case 140:
 
793
            do_record(10);
 
794
            runnit = 0;
 
795
            break;
 
796
        case 141:
 
797
            do_record(11);
 
798
            runnit = 0;
 
799
            break;
 
800
        case 's':
 
801
        case 'S':
 
802
            do_record(12);
 
803
            runnit = 0;
 
804
            break;
 
805
        case 'c':
 
806
        case 'C':
 
807
            do_record(13);
 
808
            runnit = 0;
 
809
            break;
 
810
        case '1':
 
811
            rc = system("echo " " > ~/.VRlock");
 
812
 
 
813
            rc = system
 
814
                ("cd ~/tlf/soundlogs; ./soundlog  > /dev/null 2> /dev/null &");
 
815
 
 
816
            mvprintw(15, 20, "Contest recording enabled...");
 
817
            refreshp();
 
818
            sleep(1);
 
819
            runnit = 0;
 
820
            break;
 
821
        case '2':
 
822
            mvprintw(15, 20, "Contest recording disabled...");
 
823
            refreshp();
 
824
            sleep(1);
 
825
            rc = system("rm ~/.VRlock");
 
826
            rc = system("pkill -f soundlogs > /dev/null 2> /dev/null ");
 
827
            runnit = 0;
 
828
            break;
 
829
        case '3':
 
830
            sounddir = opendir("$HOME/tlf/soundlogs/"); // (W9WI)
 
831
 
 
832
            if (sounddir == NULL)
 
833
                break;
 
834
 
 
835
            for (i = 4; i < 15; i++)
 
836
                mvprintw(i, 0,
 
837
                         "                                                                                ");
 
838
 
 
839
            mvprintw(4, 10, "");
 
840
 
 
841
            for (i = 10; i < 81; i += 10) {
 
842
                soundfilename = readdir(sounddir);
 
843
                if (soundfilename == NULL)
 
844
                    break;
 
845
                else {
 
846
                    if (strstr(soundfilename->d_name, ".au") != NULL) {
 
847
                        if (i > 60) {
 
848
                            i = 10;
 
849
                            j++;
 
850
                        }
 
851
                        strncpy(printname, soundfilename->d_name, 6);
 
852
                        mvprintw(j, i, "%s", printname);
 
853
                        refreshp();
 
854
 
 
855
                    } else if (i >= 10)
 
856
                        i -= 10;
902
857
                }
 
858
            }
 
859
            closedir(sounddir);
 
860
 
 
861
        case '4':
 
862
 
 
863
            mvprintw(15, 20, "Play back file (ddhhmmxx): ");
 
864
            refreshp();
 
865
 
 
866
            echo();
 
867
            getnstr(playbackfile, 8);
 
868
            noecho();
 
869
            strcpy(commands, "play -d ");
 
870
            strcat(commands, sc_device);
 
871
            strcat(commands, " ~/tlf/soundlogs/");
 
872
            if (strlen(playbackfile) > 6) {
 
873
                strncat(commands, playbackfile, 6);
 
874
                strcat(commands, ".au trim ");
 
875
                strcat(commands, playbackfile + 6);
 
876
            } else if (strlen(playbackfile) < 5) {
 
877
                strcat(commands, playbackfile);
 
878
                strcat(commands, "00.au");
 
879
            } else {
 
880
                strcat(commands, playbackfile);
 
881
                strcat(commands, ".au");
 
882
            }
 
883
            mvprintw(16, 20, "Use Ctrl-c to stop and return to tlf");
 
884
            mvprintw(18, 20, "");
 
885
            refreshp();
 
886
            rc = system(commands);
 
887
            runnit = 0;
 
888
            break;
 
889
        case 27:
 
890
            runnit = 0;
903
891
        }
 
892
    }
904
893
 
905
894
}