summaryrefslogtreecommitdiff
path: root/src/lockin.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lockin.h')
-rw-r--r--src/lockin.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/lockin.h b/src/lockin.h
new file mode 100644
index 0000000..9a6a515
--- /dev/null
+++ b/src/lockin.h
@@ -0,0 +1,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