-
Notifications
You must be signed in to change notification settings - Fork 2
/
cw.c
92 lines (71 loc) · 2.46 KB
/
cw.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
#include <stdio.h>
#include <math.h>
#include "cw.h"
#include "ozy.h"
void init_cw() {
int i;
cwinternal=1;
cwkeysreversed = 0; // 0=disabled 1=enabled
cwkeyerspeed = 12; // 1-60 WPM
cwkeyermode = KEYER_STRAIGHT;
cwkeyerweight = 30; //0-100
cwkeyerspacing = 0; // 0=on 1=off
cwinternal = 1; // 0=external, 1=internal
cwsidetonevolume = 127; // 0-127
cwpttdelay = 20; // 0-255ms
cwhangtime = 10; // ms
cwsidetonefrequency = 400; // Hz
double deltaf = 600.0/(double)sampleRate*2*M_PI;
//double deltaf = M_PI / 40.0; // (2 PI f / 48k) gives an 600 Hz note at 48 ksps
for (i=0;i<240;++i) {
cwSin[i] = (short)((double)(pow(2, 15) -1) * sin(deltaf * (double)i));
cwCos[i] = (short)((double)(pow(2, 15) -1) * cos(deltaf * (double)i));
}
cwIndex=0;
}
double sineWave(float* buf, int samples, double phase, double freq) {
double phase_step = 2*M_PI*freq/sampleRate;
int i;
for(i=0; i<samples; i++ ) {
buf[i] = (float)sin(phase);
phase += phase_step;
}
return phase;
}
/*
double sineWave(float* buf, int samples, double phase, double freq) {
double phase_step = 2*M_PI*freq/sampleRate;
double cosval = cos(phase);
double sinval = sin(phase);
double cosdelta = cos(phase_step);
double sindelta = sin(phase_step);
double tmpval;
int i;
for(i=0; i<samples; i++ ) {
tmpval = cosval*cosdelta - sinval*sindelta;
sinval = cosval*sindelta + sinval*cosdelta;
cosval = tmpval;
buf[i] = (float)(sinval);
//fprintf(stderr,"%d=%f\n",i,buf[i]);
phase += phase_step;
}
return phase;
}
*/
double cosineWave(float* buf, int samples, double phase, double freq) {
double phase_step = freq/sampleRate*2*M_PI;
double cosval = cos(phase);
double sinval = sin(phase);
double cosdelta = cos(phase_step);
double sindelta = sin(phase_step);
double tmpval;
int i;
for(i=0; i<samples; i++ ) {
tmpval = cosval*cosdelta - sinval*sindelta;
sinval = cosval*sindelta + sinval*cosdelta;
cosval = tmpval;
buf[i] = (float)(cosval);
phase += phase_step;
}
return phase;
}