forked from jj1bdx/WWV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voice.c
109 lines (92 loc) · 2.96 KB
/
voice.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* WWV simulator
* Copyright (C) 2022 Anthony96922
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include "audio/time_nums.h"
#include "audio/time_ann.h"
void build_time_announcement(int hour, int minute, int h, int len, short *voice) {
int samples = 0;
int number_offset = 0;
int number_len = 0;
int time_ann_offset = 0;
short *out_buffer;
short *nums;
int *nums_sizes;
short *time_ann;
int *time_ann_sizes;
if (h) {
nums = wwvh_nums;
nums_sizes = wwvh_nums_sizes;
time_ann = wwvh_time_ann;
time_ann_sizes = wwvh_time_ann_sizes;
} else {
nums = wwv_nums;
nums_sizes = wwv_nums_sizes;
time_ann = wwv_time_ann;
time_ann_sizes = wwv_time_ann_sizes;
}
out_buffer = malloc(SAMPLE_RATE * 60 * 2 * sizeof(*voice)); // doubled just in case
/* clear out buffer */
memset(out_buffer, 0, SAMPLE_RATE * 60 * 2 * sizeof(*voice));
// at the tone
memcpy(out_buffer, time_ann, time_ann_sizes[0]*sizeof(*voice));
time_ann_offset += time_ann_sizes[0];
samples += time_ann_sizes[0];
samples += 100*25;
// # of hours
for (int i = 0; i < 24; i++) {
if (i == hour) {
number_len = nums_sizes[i];
memcpy(out_buffer+samples, nums+number_offset,
number_len*sizeof(*voice));
break;
}
number_offset += nums_sizes[i]; // continue stepping through the data
}
samples += number_len;
// hours
memcpy(out_buffer+samples, time_ann+time_ann_offset, time_ann_sizes[1]*sizeof(*voice));
time_ann_offset += time_ann_sizes[1];
samples += time_ann_sizes[1];
/* add pause (WWV only) */
if (!h) samples += SAMPLES_IN_1_MS * 150;
// # of minutes
number_offset = 0;
for (int i = 0; i < 60; i++) {
if (i == minute) {
number_len = nums_sizes[i];
memcpy(out_buffer+samples, nums+number_offset,
number_len*sizeof(*voice));
break;
}
number_offset += nums_sizes[i]; // continue stepping through the data
}
samples += number_len;
// minutes
memcpy(out_buffer+samples, time_ann+time_ann_offset, time_ann_sizes[2]*sizeof(*voice));
time_ann_offset += time_ann_sizes[2];
samples += time_ann_sizes[2];
// add pause (WWV only)
if (!h) samples += SAMPLES_IN_1_MS * 325;
// coordinated universal time
memcpy(out_buffer+samples, time_ann+time_ann_offset, time_ann_sizes[3]*sizeof(*voice));
samples += time_ann_sizes[3];
if (samples > len) samples = len;
memcpy(voice, out_buffer, samples*sizeof(*voice));
free(out_buffer);
}