Skip to content

Commit

Permalink
InputApplet: Level control; peak meters
Browse files Browse the repository at this point in the history
  • Loading branch information
djphazer committed Dec 11, 2024
1 parent a01c405 commit c157937
Showing 1 changed file with 57 additions and 16 deletions.
73 changes: 57 additions & 16 deletions software/src/audio_applets/InputApplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class InputApplet : public HemisphereAudioApplet {

out_conn[0].connect(mixer[0], 0, output, 0);
mixer[0].gain(1, 0.0);

peakpatch[0].connect(OC::AudioIO::InputStream(), 0, peakmeter[0], 0);
peakpatch[1].connect(OC::AudioIO::InputStream(), 1, peakmeter[1], 0);
} else {
for (int i = 0; i < Channels; ++i) {
in_conn[i].connect(OC::AudioIO::InputStream(), i, mixer[i], 0);
Expand All @@ -26,6 +29,8 @@ class InputApplet : public HemisphereAudioApplet {

out_conn[i].connect(mixer[i], 0, output, i);
mixer[i].gain(1, 0.0);

peakpatch[i].connect(OC::AudioIO::InputStream(), i, peakmeter[i], 0);
}
}
}
Expand All @@ -34,36 +39,68 @@ class InputApplet : public HemisphereAudioApplet {
const char * const txt[] = {
"Left", "Right", "Mixed"
};
gfxPrint(2, 15, txt[mono_mode]);
gfxPrint(3, 15, txt[mono_mode]);
if constexpr (Channels == STEREO) {
gfxPrint("+Right");

gfxPrint(2, 25, "Mix? ");
gfxPrint(2, 35, mixtomono ? "Mono" : "Stereo" );
gfxCursor(2, 44, 37);
gfxPrint(10, 25, "Mix? ");
gfxPrint(10, 35, mixtomono ? "Mono" : "Stereo" );
if (cursor == CHANNEL_MODE) gfxCursor(10, 43, 37);

if (peakmeter[1].available()) {
int peaklvl = peakmeter[1].read() * 64;
gfxInvert(61, 64 - peaklvl, 3, peaklvl);
}
} else {
gfxCursor(2, 24, 31);
if (cursor == CHANNEL_MODE) gfxCursor(3, 23, 31);
}
gfxPrint(2, 45, "Lvl:");
gfxPrint(level); gfxPrint("%");
if (cursor == IN_LEVEL) gfxCursor(26, 53, 26);

if (peakmeter[0].available()) {
int peaklvl = peakmeter[0].read() * 64;
gfxInvert(0, 64 - peaklvl, 3, peaklvl);
}
}
uint64_t OnDataRequest() override {
return 0;
}
void OnDataReceive(uint64_t data) override {}
void OnEncoderMove(int direction) override {
if (!EditMode()) return;
if (!EditMode()) {
MoveCursor(cursor, direction, MAX_CURSOR);
return;
}
switch (cursor) {
case IN_LEVEL:
level = constrain(level + direction, 0, 200);
break;
case CHANNEL_MODE:
if (Channels == MONO) {
if (cursor == CHANNEL_MODE) {
mono_mode = constrain(mono_mode + direction, 0, MODE_COUNT-1);
}
} else {
mixtomono = !mixtomono;
}
break;
}

// update mix levels on any param change
if (Channels == MONO) {
mono_mode = constrain(mono_mode + direction, 0, MODE_COUNT-1);
if (mono_mode == MIXED) {
mixer[0].gain(0, 0.9);
mixer[0].gain(1, 0.9);
mixer[0].gain(0, level * 0.01f);
mixer[0].gain(1, level * 0.01f);
} else {
mixer[0].gain(mono_mode, 1.0);
mixer[0].gain(mono_mode, level * 0.01f);
mixer[0].gain(1 - mono_mode, 0.0);
}
} else {
mixtomono = !mixtomono;
mixer[0].gain(1, mixtomono? 1.0 : 0.0);
mixer[1].gain(1, mixtomono? 1.0 : 0.0);
mixer[0].gain(0, level * 0.01f);
mixer[0].gain(1, mixtomono? level * 0.01f : 0.0);
mixer[1].gain(0, level * 0.01f);
mixer[1].gain(1, mixtomono? level * 0.01f : 0.0);
}
}

Expand All @@ -85,18 +122,22 @@ class InputApplet : public HemisphereAudioApplet {
AudioConnection out_conn[Channels];
AudioPassthrough<Channels> output;

AudioAnalyzePeak peakmeter[Channels];
AudioConnection peakpatch[Channels];

int mono_mode = LEFT;
bool mixtomono = 0;
int level = 90;

enum SideMode {
LEFT, RIGHT,
MIXED,
MODE_COUNT
};
enum {
CHAN_SEL,
MIX_TOGGLE,
MAX_CURSOR = MIX_TOGGLE
CHANNEL_MODE,
IN_LEVEL,
MAX_CURSOR = IN_LEVEL
};
int cursor;

Expand Down

0 comments on commit c157937

Please sign in to comment.