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
|
#ifndef LOCKIN_H
#define LOCKIN_H
#include <limits.h> /* for INT_MAX */
#include <valarray>
#include <cmath>
#include <string>
#include "alsa_pcm.h"
// used when converting between syslog and fprintf:
#define NL "\n"
const double two16(1<<16);
const double two32(two16*two16);
const int bPB(8); // bits per byte
void exeunt(int signum);
std::string invent_driverfile(const std::string justcard);
std::string invent_ctlfile(const std::string justcard);
typedef int32_t datum; // all internal calculations are 32bit
const double pi(M_PI);
const double kT(1.38e-23 * (273.15 + 20));
const double twopi = 2 * pi;
// reference level is saturation minus 15 dB
const double full_swing(INT_MAX);
// sine wave RMS is sqrt(2) less than peak:
const double full_swing_2(full_swing/sqrt(2.0));
// some non-constant global variables,
// for inter-thread communication:
extern std::string progname;
extern int verbosity;
extern timespec prog_start_time;
extern int xrun_verbosity; // be verbose about underrun and overrun
//
// Note: more globals are found in gui.h
inline double operator-(const timespec a, const timespec b){
return (a.tv_sec-b.tv_sec) + (a.tv_nsec - b.tv_nsec)*1e-9;
}
class Keeper{
public:
const alsa_pcm* pcm;
const int fpp; // frames per period
std::valarray<datum> buf;
int finbuf; // frames in buffer at the moment
int nchan;
Keeper(const alsa_pcm*, const int fsize);
};
snd_pcm_sframes_t snd_pcm_writei(Keeper& kk, const datum* buffer,
snd_pcm_uframes_t nframes);
class snark {
public:
snark(); // constructor
std::string card_device; // principal input, e.g. "0,0"
std::string wcheck_fname; // place to write raw data (checkfile)
int nframe;
int onepass; // exit after one pass
int desired_rate;
int channel_mask;
double kout; // output voltage scale, assuming sine-wave
// ... which has RMS 3dB below full_swing
double zref; // reference resistor
double reffreq;
double refival;
double refamp;
std::string mixer_ctlfile;
// not commandline options, but derived therefrom:
int wcheck_fd;
std::string justcard; // the "card" part of that, before the comman
double sps; // entropy (bits per sample)
double snooze; // time to snooze between actions if not
// actually writing to output fifo,
// e.g. during calibration.
//// functions
void usage(const int err);
void cmdline(int argc, char** argv);
void open_aux_io();
int read_stuff(alsa_pcm*, datum*);
void printx(
const int colored,
const char* name,
const double foo_1,
const double foo_2,
double plogp,
const alsa_pcm* pcm
);
};
#endif
|