-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwavgen.h
executable file
·143 lines (122 loc) · 5.28 KB
/
wavgen.h
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
** wavgen.h
**
** Main application header file.
*/
#ifndef wavgen_h
#define wavgen_h
#include <ctype.h>
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> // for isatty
#include <stdbool.h>
static const char version_str[] = "0.0.5";
/*
** Define some upper limits, not all of which are strongly enforced.
*/
#define MAX_SAMPLE_RATE_HZ (192000U) // 192kHz.
#define MAX_DURATION_MS (60U * 60U * 1000U) // 60 minutes maximum FILE duration.
#define MAX_SAMPLES_PER_CHNL (MAX_DURATION_MS * MAX_SAMPLE_RATE_HZ) // 60 minutes at 192kHz for FILE o/p.
#define MAX_CHANNELS (8U) // 8 channels maximum.
#define MAX_LEVEL_32BIT (0x7FFFFFFF)
/*
** Typedefs and enums.
*/
typedef enum {
WAVEFORM_TYPE_BURST,
WAVEFORM_TYPE_COUNTER,
WAVEFORM_TYPE_SAW,
WAVEFORM_TYPE_SILENCE,
WAVEFORM_TYPE_SINE,
WAVEFORM_TYPE_SQUARE,
WAVEFORM_TYPE_STEPS,
WAVEFORM_TYPE_PINK,
WAVEFORM_TYPE_WHITE,
NUM_WAVEFORM_TYPES
} WAVEFORM_TYPE;
enum BYTES_PER_SAMPLE {
BYTES_NONE = 0,
BYTES_8BIT = 1,
BYTES_16BIT = 2,
BYTES_24BIT = 3,
BYTES_32BIT = 4
};
/* Mixed pointer to a sample/buffer that can hold either a 32-bit int or a float sample */
typedef union {
int32_t i;
float f;
} SAMPLE;
/*
** General parameters that apply to all (or at least most) waveforms.
** These represent the command-line options "b:c:d:s:f:l:a:p:w:m:"
*/
struct COMMON_USER_PARAMS {
bool save_as_float; // -b 0
uint8_t num_channels; // -c 1:8
uint8_t bits_per_sample; // -b 32|24|16
uint8_t bytes_per_sample; // =4 =4 =2
uint32_t frequency_hz; // -f (of the main waveform)
uint32_t sample_rate; // -r 48000|44100 etc,
uint32_t duration_ms; // -d (or calculated from -s)
uint32_t num_samples; // -s (or calculated from -d)
float peak_level_dbfs; // -l
float align_level_dbfs; // -a
WAVEFORM_TYPE wf_type; // -t
const char *filename; // The final parameter (no prefix).
};
/*
** Extra options that only apply to some waveforms.
*/
struct ADDITIONAL_USER_PARAMS {
uint16_t power_fraction; // -w (e.g. '8' for 1/8th power)
uint32_t num_cycles; // -n (for burst/impulse waveforms)
uint32_t period_ms; // -p (for burst/impulse waveforms)
bool markers_on; // -m
bool markers_in_msb; // -m tb|msb (not bb|lsb)
bool uncorrelated; // -u (for pink noise)
};
/*
** Fixed parameters that aren't DIRECTLY set by the user, or are internal only.
*/
struct FIXED_PARAMS {
double gain; // Gain value calculated from user params (align, level, power).
bool verbose; // Output information to the console.
bool piping; // True if piping the "wavfile" to another application.
SAMPLE sample_value; // Holds the value of the current sample being generated.
uint32_t sample_number; // Holds the offset of the current sample (i.e. the sample number).
uint16_t current_chnl; // Holds the channel number of the current sample being generated.
};
/*
** Function declarations.
*/
/* From help.c */
void help(void);
void waveform_type_help(WAVEFORM_TYPE type);
void help_type_unknown(void);
void help_version(void);
/* From log.c */
void log_info(struct FIXED_PARAMS *fixed, const char *format, ...);
void log_extra(struct FIXED_PARAMS *fixed, const char *format, ...);
/* From opts.c */
void parse_opts(int argc, char *argv[], struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user, struct ADDITIONAL_USER_PARAMS *extra);
double gain_from_params(struct FIXED_PARAMS *fixed, float align_dbfs, float peak_dbfs, uint16_t power_fraction);
/* From wf_xxx.c - these waveforms can have channel-markers overlaid.*/
void generate_saw(struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user_params);
void generate_steps(struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user_params);
void generate_silence(struct FIXED_PARAMS *fixed);
void generate_counter(struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user_params, struct ADDITIONAL_USER_PARAMS *extra_params);
/* From wf_xxx.c - these waveforms cannot have markers, but their level can be specified by power fraction.*/
void generate_square(struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user_params);
void generate_sine(struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user_params);
void generate_burst(struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user_params, struct ADDITIONAL_USER_PARAMS *extra_params);
void generate_white(struct FIXED_PARAMS *fixed, struct ADDITIONAL_USER_PARAMS *extra_params);
void generate_pink(struct FIXED_PARAMS *fixed, struct ADDITIONAL_USER_PARAMS *extra_params);
/* From wf_markers.c */
bool check_markers(struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user, struct ADDITIONAL_USER_PARAMS *extra);
bool add_markers(struct FIXED_PARAMS *fixed, bool markers_in_msb);
/* From wf_output.c */
bool finalise_data(struct FIXED_PARAMS *fixed, struct COMMON_USER_PARAMS *user, struct ADDITIONAL_USER_PARAMS *extra_params, FILE *wavfile);
#endif