6 #define AudioOutput AudioOutputMozzi
11 AudioOutputMozzi updateAudio();
16 uint16_t control_rate = CONTROL_RATE;
17 int input_range_from = 0;
18 int input_range_to = 1023;
19 int16_t output_volume = 10;
40 void setInput(Stream& in) { p_input = ∈ }
60 control_counter_max = info.
sample_rate / cfg.control_rate;
61 if (control_counter_max <= 0) {
62 control_counter_max = 1;
64 control_counter = control_counter_max;
69 void end() { active =
false; }
73 cfg.output_volume = vol;
79 if (!active)
return 0;
80 int samples = len /
sizeof(int16_t);
82 int16_t* data16 = (int16_t*)data;
84 for (
int j = 0; j < frames; j++) {
85 int16_t sample = nextSample();
86 for (
int ch = 0; ch < cfg.
channels; ch++) {
87 data16[idx++] = sample;
90 return idx *
sizeof(int16_t);
94 size_t write(
const uint8_t* data,
size_t len) {
95 if (!active)
return 0;
96 if (buffer.
size() == 0) {
97 buffer.resize(len * 2);
107 if (p_input !=
nullptr) {
108 p_input->readBytes((uint8_t*)&result,
sizeof(int16_t) * cfg.
channels);
113 int sample = avg(result);
115 if (sample < input_min) input_min = sample;
116 if (sample > input_max) input_max = sample;
117 int sample1 =
map(sample, input_min, input_max, cfg.input_range_from,
124 int control_counter_max;
127 Stream* p_input =
nullptr;
129 int input_min = 32767;
130 int input_max = -32768;
132 int16_t avg(int16_t* values) {
134 for (
int ch = 0; ch < cfg.
channels; ch++) {
140 int16_t nextSample() {
142 if (--control_counter < 0) {
143 control_counter = control_counter_max;
144 LOGD(
"updateControl");
149 auto result = updateAudio() * cfg.output_volume;
151 if (result > 32767) result = 32767;
152 if (result < -32768) result = -32768;