summaryrefslogtreecommitdiff
path: root/Core/Inc
diff options
context:
space:
mode:
authorozpv <39195175+ozpv@users.noreply.github.com>2026-08-29 23:04:49 -0500
committerozpv <39195175+ozpv@users.noreply.github.com>2026-08-29 23:04:49 -0500
commitbdd8c21fcfff8041ea94a972903ce42e58c2a5c2 (patch)
treee85828cc8d209decf9a367f1853356a79397ea3b /Core/Inc
parentd000890eafbc6cc715fa6e7da2db61db05a6f3e4 (diff)
add retainHEADmain
Diffstat (limited to 'Core/Inc')
-rwxr-xr-xCore/Inc/Effects/retain.h34
-rwxr-xr-xCore/Inc/Effects/ringmod.h9
-rwxr-xr-xCore/Inc/cs4272.h21
3 files changed, 58 insertions, 6 deletions
diff --git a/Core/Inc/Effects/retain.h b/Core/Inc/Effects/retain.h
new file mode 100755
index 0000000..4700493
--- /dev/null
+++ b/Core/Inc/Effects/retain.h
@@ -0,0 +1,34 @@
+/*
+ * retain.h
+ *
+ * Created on: Aug 23, 2026
+ * Author: ozpv
+ */
+
+#ifndef INC_EFFECTS_RETAIN_H_
+#define INC_EFFECTS_RETAIN_H_
+
+#include <stddef.h>
+#include <stdint.h>
+#include "cs4272.h"
+
+/* must be a power of two
+ higher values give better frequency resolution
+ and must be paired with a higher BUFFER_SIZE */
+#define WINDOW_SIZE 4096
+/* change based on necessary overlap */
+#define HOP_SIZE (WINDOW_SIZE / 4)
+#define OVERLAP_SIZE (WINDOW_SIZE - HOP_SIZE)
+#define NUM_OVERLAPS (WINDOW_SIZE / HOP_SIZE)
+#define COMPLEX_BIN_COUNT (WINDOW_SIZE / 2 - 1)
+
+void retain_init(void);
+void retain(
+ const int32_t *samples_in,
+ int32_t *samples_out,
+ const size_t range_min,
+ const size_t range_max,
+ const enum Channel channel
+);
+
+#endif /* INC_EFFECTS_RETAIN_H_ */
diff --git a/Core/Inc/Effects/ringmod.h b/Core/Inc/Effects/ringmod.h
index 516ca6c..766fad4 100755
--- a/Core/Inc/Effects/ringmod.h
+++ b/Core/Inc/Effects/ringmod.h
@@ -20,6 +20,13 @@ typedef struct RingModParams {
bool square_lfo;
} RingModParams;
-void ringmod(float *samples, const size_t range_min, const size_t range_max, const struct RingModParams *params);
+void ringmod(
+ const struct RingModParams *params,
+ const int32_t *samples_in,
+ int32_t *samples_out,
+ const size_t range_min,
+ const size_t range_max,
+ const enum Channel channel
+);
#endif /* INC_EFFECTS_RINGMOD_H_ */
diff --git a/Core/Inc/cs4272.h b/Core/Inc/cs4272.h
index 423b7c0..4e22263 100755
--- a/Core/Inc/cs4272.h
+++ b/Core/Inc/cs4272.h
@@ -26,16 +26,27 @@
#define CS4272_I2C_ADDR (0b0010000 << 1)
#define SAMPLE_RATE 48000
-#define BUFFER_SIZE 512
+#define BUFFER_SIZE 1024
-extern volatile int32_t rx_buffer[BUFFER_SIZE];
-extern volatile int32_t tx_buffer[BUFFER_SIZE];
-extern volatile float samples[BUFFER_SIZE];
+typedef enum Channel {
+ LEFT = 0,
+ RIGHT = 1,
+ MONO = 0,
+} Channel;
+
+extern int32_t rx_buffer[BUFFER_SIZE];
+extern int32_t tx_buffer[BUFFER_SIZE];
extern const uint8_t CS4272_CONFIG[7];
uint8_t CS4272_Init(void);
-#define INT24_MAX 0x7FFFFF
+static inline __attribute__((always_inline)) float int24_t_to_f32(const int32_t in) {
+ return ((float)(in << 8)) / ((float)INT32_MAX);
+}
+
+static inline __attribute__((always_inline)) int32_t f32_to_int24_t(const float in) {
+ return ((int32_t)(in * ((float)INT32_MAX))) >> 8;
+}
#endif /* INC_CS4272_H_ */